AutoMapper for .Net 允许您从一种类型映射到另一种类型。它最基本的功能是通过复制类型 A 中存在于类型 B 中的属性值(具有匹配的名称和类型),从另一种类型的类中创建一种类型的类。
例子:
public class ClassA {
public string StringProp { get; set; }
public int IntProp { get;set; }
}
public class ClassB {
public string StringProp { get; set; }
public int SomeIntProp { get; set; }
}
ClassA classAInstance = new ClassA { StringProp = "Test", IntProp = 5 };
ClassB classBInstance = Mapper.Map<ClassA, ClassB>(classAInstance);
// This creates a new instance of ClassB and sets its StringProp property to "Test".
// It does not set the property on ClassB called "SomeIntProp" because there is no
// property on ClassA called "SomeIntProp"
Objective-C 有类似的东西吗?