本文整理汇总了C#中AutoMapper.ResolutionContext类的典型用法代码示例。如果您正苦于以下问题:C# ResolutionContext类的具体用法?C# ResolutionContext怎么用?C# ResolutionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResolutionContext类属于AutoMapper命名空间,在下文中一共展示了ResolutionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AutoMapperMappingException
public AutoMapperMappingException(ResolutionContext context, Exception inner, PropertyMap propertyMap)
: base(null, inner)
{
Context = context;
Types = context.Types;
PropertyMap = propertyMap;
}
示例2: ResolveValue
public object ResolveValue(ResolutionContext context)
{
var ctorArgs = new List<object>();
foreach (var map in CtorParams)
{
var result = map.ResolveValue(context);
var sourceType = result.Type;
var destinationType = map.Parameter.ParameterType;
var typeMap = context.ConfigurationProvider.ResolveTypeMap(result, destinationType);
Type targetSourceType = typeMap != null ? typeMap.SourceType : sourceType;
var newContext = context.CreateTypeContext(typeMap, result.Value, null, targetSourceType,
destinationType);
if (typeMap == null && map.Parameter.IsOptional)
{
object value = map.Parameter.DefaultValue;
ctorArgs.Add(value);
}
else
{
var value = context.Engine.Map(newContext);
ctorArgs.Add(value);
}
}
return _runtimeCtor.Value(ctorArgs.ToArray());
}
示例3: CreateObject
public object CreateObject(ResolutionContext context)
{
var typeMap = context.TypeMap;
var destinationType = context.DestinationType;
if (typeMap != null)
if (typeMap.DestinationCtor != null)
return typeMap.DestinationCtor(context);
else if (typeMap.ConstructDestinationUsingServiceLocator)
return context.Options.ServiceCtor(destinationType);
else if (typeMap.ConstructorMap != null && typeMap.ConstructorMap.CtorParams.All(p => p.CanResolve))
return typeMap.ConstructorMap.ResolveValue(context);
if (context.DestinationValue != null)
return context.DestinationValue;
if (destinationType.IsInterface())
#if PORTABLE
throw new PlatformNotSupportedException("Mapping to interfaces through proxies not supported.");
#else
destinationType = new ProxyGenerator().GetProxyType(destinationType);
#endif
return !ConfigurationProvider.AllowNullDestinationValues
? ObjectCreator.CreateNonNullValue(destinationType)
: ObjectCreator.CreateObject(destinationType);
}
示例4: FormatValue
public string FormatValue(ResolutionContext context)
{
var timespan = (TimeSpan) context.SourceValue;
var list = new List<string>(3);
int days = timespan.Days;
int hours = timespan.Hours;
int minutes = timespan.Minutes;
if (days > 1)
list.Add(string.Format("{0} days", days));
else if (days == 1)
list.Add(string.Format("{0} day", days));
if (hours > 1)
list.Add(string.Format("{0} hours", hours));
else if (hours == 1)
list.Add(string.Format("{0} hour", hours));
if (minutes > 1)
list.Add(string.Format("{0} minutes", minutes));
else if (minutes == 1)
list.Add(string.Format("{0} minute", minutes));
return string.Join(", ", list.ToArray());
}
示例5: CheckPropertyMapSkipList
private static bool CheckPropertyMapSkipList(ResolutionContext context, Type formatterType)
{
if (context.PropertyMap == null)
return true;
return !context.PropertyMap.FormattersToSkipContains(formatterType);
}
示例6: ResolutionResult
private ResolutionResult(object value, ResolutionContext context, Type memberType)
{
Value = value;
Context = context;
Type = ResolveType(value, memberType);
MemberType = memberType;
}
示例7: ResolutionResult
private ResolutionResult(object value, ResolutionContext context, Type memberType)
{
_value = value;
_context = context;
_type = ResolveType(value, memberType);
_memberType = memberType;
}
示例8: 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);
}
}
}
示例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: MapAbstractModel
protected object MapAbstractModel(ResolutionContext context)
{
var assemblyQualifiedName = context.DestinationType.AssemblyQualifiedName;
var baseFullName = context.DestinationType.FullName;
var childtype = ((AbstractForm)context.SourceValue).BindingType;
var destinationType = Type.GetType(assemblyQualifiedName.Replace(baseFullName, baseFullName + childtype));
return Mapper.Map(context.SourceValue, context.SourceType, destinationType);
}
示例11: ResolveValue
/// <summary>
/// Resolves the value.
/// </summary>
/// <param name="context">The context.</param>
/// <returns></returns>
public object ResolveValue(ResolutionContext context)
{
var ctorArgs = CtorParams
.Select(p => p.ResolveValue(context))
.Select(result => result.Value)
.ToArray();
return _runtimeCtor(ctorArgs);
}
示例12: ReturnsTrueWhenBothSourceAndDestinationTypesAreNameValueCollection
public void ReturnsTrueWhenBothSourceAndDestinationTypesAreNameValueCollection()
{
var rc = new ResolutionContext(null, null, null, typeof(NameValueCollection), typeof(NameValueCollection), null);
var nvcm = new NameValueCollectionMapper();
var result = nvcm.IsMatch(rc);
result.ShouldBeTrue();
}
示例13: ReturnsIsFalseWhenSourceTypeIsNotNameValueCollection
public void ReturnsIsFalseWhenSourceTypeIsNotNameValueCollection()
{
var rc = new ResolutionContext(null, null, null, typeof(Object), typeof(NameValueCollection), null);
var nvcm = new NameValueCollectionMapper();
var result = nvcm.IsMatch(rc);
result.ShouldBeFalse();
}
示例14: IsMatch
/// <summary>
/// Determines whether the specified context is match.
/// </summary>
/// <param name="context">The context.</param>
/// <returns><c>true</c> if the specified context is match; otherwise, <c>false</c>.</returns>
public bool IsMatch( ResolutionContext context )
{
if (Mapper.GetAllTypeMaps().Count(m => m.SourceType == context.SourceType && m.DestinationType == context.DestinationType) == 0)
{
return true;
}
return false;
}
示例15: ResolutionResult
private ResolutionResult(object value, ResolutionContext context)
{
if (context == null) throw new ArgumentNullException("context");
_value = value;
_context = context;
_type = ResolveType(value, typeof(object));
_memberType = _type;
}