本文整理汇总了C#中TypePair类的典型用法代码示例。如果您正苦于以下问题:C# TypePair类的具体用法?C# TypePair怎么用?C# TypePair使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypePair类属于命名空间,在下文中一共展示了TypePair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsMatch
public bool IsMatch(TypePair context)
{
return IsPrimitiveArrayType(context.DestinationType) &&
IsPrimitiveArrayType(context.SourceType) &&
(TypeHelper.GetElementType(context.DestinationType)
.Equals(TypeHelper.GetElementType(context.SourceType)));
}
示例2: GetTargetName
private string GetTargetName(
Option<BindingConfig> bindingConfig,
TypePair typePair,
MemberInfo sourceMember,
Dictionary<string, string> targetBindings)
{
Option<string> targetName;
List<BindAttribute> binds = sourceMember.GetAttributes<BindAttribute>();
BindAttribute bind = binds.FirstOrDefault(x => x.TargetType.IsNull());
if (bind.IsNull())
{
bind = binds.FirstOrDefault(x => typePair.Target.IsAssignableFrom(x.TargetType));
}
if (bind.IsNotNull())
{
targetName = new Option<string>(bind.MemberName);
}
else
{
targetName = bindingConfig.Map(x => x.GetBindField(sourceMember.Name));
if (targetName.HasNoValue)
{
string targetMemberName;
if (targetBindings.TryGetValue(sourceMember.Name, out targetMemberName))
{
targetName = new Option<string>(targetMemberName);
}
else
{
targetName = new Option<string>(sourceMember.Name);
}
}
}
return targetName.Value;
}
示例3: CreateMapperCacheItem
private MapperCacheItem CreateMapperCacheItem(TypePair typePair)
{
MapperBuilder mapperBuilder = GetMapperBuilder(typePair);
Mapper mapper = mapperBuilder.Build(typePair);
MapperCacheItem mapperCacheItem = _mapperCache.Add(typePair, mapper);
return mapperCacheItem;
}
示例4: DryRunTypeMap
private void DryRunTypeMap(ICollection<TypeMap> typeMapsChecked, ResolutionContext context)
{
var typeMap = context.TypeMap;
if (typeMap != null)
{
typeMapsChecked.Add(typeMap);
CheckPropertyMaps(typeMapsChecked, context);
}
else
{
var mapperToUse = _config.GetMappers().FirstOrDefault(mapper => mapper.IsMatch(context.Types));
if (mapperToUse == null && context.SourceType.IsNullableType())
{
var nullableTypes = new TypePair(Nullable.GetUnderlyingType(context.SourceType),
context.DestinationType);
mapperToUse = _config.GetMappers().FirstOrDefault(mapper => mapper.IsMatch(nullableTypes));
}
if (mapperToUse == null)
{
throw new AutoMapperConfigurationException(context);
}
if (mapperToUse is ArrayMapper || mapperToUse is EnumerableMapper || mapperToUse is CollectionMapper)
{
CheckElementMaps(typeMapsChecked, context);
}
}
}
示例5: IsMatch
public bool IsMatch(TypePair context)
{
// destination type must be IEnumerable interface or a class implementing at least IList
return ((context.DestinationType.IsInterface() && context.DestinationType.IsEnumerableType()) ||
context.DestinationType.IsListType())
&& context.SourceType.IsEnumerableType();
}
示例6: EnumToEnumMapping
private static bool EnumToEnumMapping(TypePair context)
{
// Enum to enum mapping
var sourceEnumType = TypeHelper.GetEnumerationType(context.SourceType);
var destEnumType = TypeHelper.GetEnumerationType(context.DestinationType);
return sourceEnumType != null && destEnumType != null;
}
示例7: 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);
}
}
}
示例8: ConvertEnum
private static Option<Func<object, object>> ConvertEnum(TypePair pair)
{
Func<object, object> result;
if (pair.IsEnumTypes)
{
result = x => Convert.ChangeType(x, pair.Source);
return result.ToOption();
}
if (pair.Target.IsEnum)
{
if (pair.Source.IsEnum == false)
{
if (pair.Source == typeof(string))
{
result = x => Enum.Parse(pair.Target, x.ToString());
}
}
result = x => Enum.ToObject(pair.Target, Convert.ChangeType(x, Enum.GetUnderlyingType(pair.Target)));
return result.ToOption();
}
if (pair.Source.IsEnum)
{
result = x => Convert.ChangeType(x, pair.Target);
return result.ToOption();
}
return Option<Func<object, object>>.Empty;
}
示例9: CreateMapperCacheItem
private MapperCacheItem CreateMapperCacheItem(TypePair parentTypePair, MappingMember mappingMember)
{
MapperBuilder mapperBuilder = _config.GetMapperBuilder(parentTypePair, mappingMember);
Mapper mapper = mapperBuilder.Build(parentTypePair, mappingMember);
MapperCacheItem mapperCacheItem = _mapperCache.Add(mappingMember.TypePair, mapper);
return mapperCacheItem;
}
示例10: Build
public MemberEmitterDescription Build(TypePair parentTypePair, List<MappingMember> members)
{
var emitter = new EmitComposite();
members.ForEach(x => emitter.Add(Build(parentTypePair, x)));
var result = new MemberEmitterDescription(emitter, _mapperCache);
result.AddMapper(_mapperCache);
return result;
}
示例11: TypeMap
public TypeMap(TypeDetails sourceType, TypeDetails destinationType, MemberList memberList, ProfileMap profile)
{
SourceTypeDetails = sourceType;
DestinationTypeDetails = destinationType;
Types = new TypePair(sourceType.Type, destinationType.Type);
Profile = profile;
ConfiguredMemberList = memberList;
}
示例12: TypeMap
public TypeMap(TypeDetails sourceType, TypeDetails destinationType, MemberList memberList)
{
_sourceType = sourceType;
_destinationType = destinationType;
Types = new TypePair(sourceType.Type, destinationType.Type);
Profile = ConfigurationStore.DefaultProfileName;
ConfiguredMemberList = memberList;
}
示例13: GetMapperBuilder
public MapperBuilder GetMapperBuilder(TypePair parentTypePair, MappingMember mappingMember)
{
if (_customTypeMapperBuilder.IsSupported(parentTypePair, mappingMember))
{
return _customTypeMapperBuilder;
}
return GetTypeMapperBuilder(mappingMember.TypePair);
}
示例14: IsSupported
public bool IsSupported(TypePair parentTypePair, MappingMember mappingMember)
{
Option<BindingConfig> bindingConfig = _config.GetBindingConfig(parentTypePair);
if (bindingConfig.HasNoValue)
{
return false;
}
return bindingConfig.Value.HasCustomTypeConverter(mappingMember.Target.Name);
}
示例15: IsMatch
public bool IsMatch(TypePair context)
{
if (!(context.SourceType.IsEnumerableType() && context.DestinationType.IsGenericType()))
return false;
var genericType = context.DestinationType.GetGenericTypeDefinition();
return genericType == typeof (ReadOnlyCollection<>);
}