本文整理汇总了C#中AutoMapper.TypeMap类的典型用法代码示例。如果您正苦于以下问题:C# TypeMap类的具体用法?C# TypeMap怎么用?C# TypeMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeMap类属于AutoMapper命名空间,在下文中一共展示了TypeMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateTypeMap
public TypeMap CreateTypeMap(Type sourceType, Type destinationType, ProfileMap options, MemberList memberList)
{
var sourceTypeInfo = options.CreateTypeDetails(sourceType);
var destTypeInfo = options.CreateTypeDetails(destinationType);
var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo, memberList, options);
foreach (var destProperty in destTypeInfo.PublicWriteAccessors)
{
var resolvers = new LinkedList<MemberInfo>();
if (MapDestinationPropertyToSource(options, sourceTypeInfo, destProperty.DeclaringType, destProperty.GetMemberType(), destProperty.Name, resolvers))
{
typeMap.AddPropertyMap(destProperty, resolvers);
}
}
if (!destinationType.IsAbstract() && destinationType.IsClass())
{
foreach (var destCtor in destTypeInfo.Constructors.OrderByDescending(ci => ci.GetParameters().Length))
{
if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options))
{
break;
}
}
}
return typeMap;
}
示例2: MapDestinationCtorToSource
private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeDetails sourceTypeInfo, IProfileConfiguration options)
{
var parameters = new List<ConstructorParameterMap>();
var ctorParameters = destCtor.GetParameters();
if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled)
return false;
foreach (var parameter in ctorParameters)
{
var resolvers = new LinkedList<IValueResolver>();
var canResolve = MapDestinationPropertyToSource(options, sourceTypeInfo, parameter.GetType(), parameter.Name, resolvers);
if(!canResolve && parameter.HasDefaultValue)
{
canResolve = true;
}
var param = new ConstructorParameterMap(parameter, resolvers.ToArray(), canResolve);
parameters.Add(param);
}
typeMap.AddConstructorMap(destCtor, parameters);
return true;
}
示例3: CreateTypeMap
public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IProfileConfiguration options, MemberList memberList)
{
var sourceTypeInfo = GetTypeInfo(sourceType, options);
var destTypeInfo = GetTypeInfo(destinationType, options);
var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo, memberList, options.ProfileName);
foreach (var destProperty in destTypeInfo.PublicWriteAccessors)
{
var resolvers = new LinkedList<IValueResolver>();
if (MapDestinationPropertyToSource(options, sourceTypeInfo, destProperty.GetMemberType(), destProperty.Name, resolvers))
{
var destPropertyAccessor = destProperty.ToMemberAccessor();
typeMap.AddPropertyMap(destPropertyAccessor, resolvers);
}
}
if (!destinationType.IsAbstract() && destinationType.IsClass())
{
foreach (var destCtor in destTypeInfo.Constructors.OrderByDescending(ci => ci.GetParameters().Length))
{
if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options))
{
break;
}
}
}
return typeMap;
}
示例4: CreateTypeMap
public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options)
{
var sourceTypeInfo = GetTypeInfo(sourceType);
var destTypeInfo = GetTypeInfo(destinationType);
var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo);
foreach (var destProperty in destTypeInfo.GetPublicWriteAccessors())
{
var members = new LinkedList<MemberInfo>();
if (MapDestinationPropertyToSource(members, sourceTypeInfo, destProperty.Name, options))
{
var resolvers = members.Select(mi => mi.ToMemberGetter());
var destPropertyAccessor = destProperty.ToMemberAccessor();
#if !SILVERLIGHT
typeMap.AddPropertyMap(destPropertyAccessor, resolvers);
#else
typeMap.AddPropertyMap(destPropertyAccessor, resolvers.Cast<IValueResolver>());
#endif
}
}
if (!destinationType.IsAbstract && destinationType.IsClass)
{
foreach (var destCtor in destTypeInfo.GetConstructors().OrderByDescending(ci => ci.GetParameters().Length))
{
if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options))
{
break;
}
}
}
return typeMap;
}
示例5: MapDestinationCtorToSource
private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeDetails sourceTypeInfo, ProfileMap options)
{
var ctorParameters = destCtor.GetParameters();
if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled)
return false;
var ctorMap = new ConstructorMap(destCtor, typeMap);
foreach (var parameter in ctorParameters)
{
var resolvers = new LinkedList<MemberInfo>();
var canResolve = MapDestinationPropertyToSource(options, sourceTypeInfo, destCtor.DeclaringType, parameter.GetType(), parameter.Name, resolvers);
if(!canResolve && parameter.HasDefaultValue)
{
canResolve = true;
}
ctorMap.AddParameter(parameter, resolvers.ToArray(), canResolve);
}
typeMap.ConstructorMap = ctorMap;
return true;
}
示例6: AutoMapperConfigurationException
public AutoMapperConfigurationException(TypeMap typeMap, string[] unmappedPropertyNames)
: base(string.Format(
"The following {3} properties on {0} are not mapped: \n\t{2}\nAdd a custom mapping expression, ignore, or rename the property on {1}.",
typeMap.DestinationType.FullName, typeMap.SourceType.FullName, string.Join("\n\t", unmappedPropertyNames),
unmappedPropertyNames.Length))
{
}
示例7: CreateTypeMap
public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options,
MemberList memberList)
{
var sourceTypeInfo = GetTypeInfo(sourceType, options);
var destTypeInfo = GetTypeInfo(destinationType, options.ShouldMapProperty, options.ShouldMapField, new MethodInfo[0]);
var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo, memberList);
foreach (var destProperty in destTypeInfo.PublicWriteAccessors)
{
var members = new LinkedList<MemberInfo>();
if (MapDestinationPropertyToSource(members, sourceTypeInfo, destProperty.Name, options))
{
var resolvers = members.Select(mi => mi.ToMemberGetter());
var destPropertyAccessor = destProperty.ToMemberAccessor();
typeMap.AddPropertyMap(destPropertyAccessor, resolvers.Cast<IValueResolver>());
}
}
if (!destinationType.IsAbstract() && destinationType.IsClass())
{
foreach (var destCtor in destTypeInfo.Constructors.OrderByDescending(ci => ci.GetParameters().Length))
{
if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options))
{
break;
}
}
}
return typeMap;
}
示例8: MapDestinationCtorToSource
private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeInfo sourceTypeInfo,
IMappingOptions options)
{
var parameters = new List<ConstructorParameterMap>();
var ctorParameters = destCtor.GetParameters();
if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled)
return false;
foreach (var parameter in ctorParameters)
{
var members = new LinkedList<MemberInfo>();
if (!MapDestinationPropertyToSource(members, sourceTypeInfo, parameter.Name, options))
return false;
var resolvers = members.Select(mi => mi.ToMemberGetter());
var param = new ConstructorParameterMap(parameter, resolvers.ToArray());
parameters.Add(param);
}
typeMap.AddConstructorMap(destCtor, parameters);
return true;
}
示例9: DryRunTypeMap
private void DryRunTypeMap(ICollection<TypeMap> typeMapsChecked, TypePair types, TypeMap typeMap, ResolutionContext context)
{
if (typeMap != null)
{
typeMapsChecked.Add(typeMap);
if(typeMap.CustomMapper != null || typeMap.TypeConverterType != null)
{
return;
}
CheckPropertyMaps(typeMapsChecked, typeMap, context);
}
else
{
var mapperToUse = _config.GetMappers().FirstOrDefault(mapper => mapper.IsMatch(types));
if (mapperToUse == null && types.SourceType.IsNullableType())
{
var nullableTypes = new TypePair(Nullable.GetUnderlyingType(types.SourceType),
types.DestinationType);
mapperToUse = _config.GetMappers().FirstOrDefault(mapper => mapper.IsMatch(nullableTypes));
}
if (mapperToUse == null)
{
throw new AutoMapperConfigurationException(types);
}
if (mapperToUse is ArrayMapper || mapperToUse is EnumerableMapper || mapperToUse is CollectionMapper)
{
CheckElementMaps(typeMapsChecked, types, context);
}
}
}
示例10: X
public static IEnumerable<MapVisual> X(TypeMap map)
{
foreach (var propertyMap in map.GetPropertyMaps())
{
yield return new MapVisual
{
SourceSystem = extractSystem(propertyMap.SourceMember),
SourceValue = getValue(propertyMap.SourceMember),
TargetSystem = extractSystem(propertyMap.DestinationProperty),
TargetValue = propertyMap.DestinationProperty.Name
};
}
}
示例11: CreateTypeMap
public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options)
{
var sourceTypeInfo = GetTypeInfo(sourceType);
var destTypeInfo = GetTypeInfo(destinationType);
var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo);
foreach (var destProperty in destTypeInfo.GetPublicWriteAccessors())
{
var members = new LinkedList<MemberInfo>();
if (MapDestinationPropertyToSource(members, sourceTypeInfo, destProperty.Name, options))
{
var resolvers = members.Select(mi => mi.ToMemberGetter()).Cast<IValueResolver>();
var destPropertyAccessor = destProperty.ToMemberAccessor();
typeMap.AddPropertyMap(destPropertyAccessor, resolvers);
}
}
return typeMap;
}
示例12: AutoMapperMappingException
public AutoMapperMappingException(string message, Exception innerException, TypePair types, TypeMap typeMap, PropertyMap propertyMap)
: this(message, innerException, types, typeMap)
{
PropertyMap = propertyMap;
}
示例13: TypeMapConfigErrors
public TypeMapConfigErrors(TypeMap typeMap, string[] unmappedPropertyNames)
{
TypeMap = typeMap;
UnmappedPropertyNames = unmappedPropertyNames;
}
示例14: InheritTypes
public void InheritTypes(TypeMap inheritedTypeMap)
{
foreach (var includedDerivedType in inheritedTypeMap._includedDerivedTypes
.Where(includedDerivedType => !_includedDerivedTypes.Contains(includedDerivedType)))
{
_includedDerivedTypes.Add(includedDerivedType);
}
}
示例15: RegisterTypeMap
public void RegisterTypeMap(TypeMap typeMap) => _typeMaps[typeMap.Types] = typeMap;