public object Map(ResolutionContext context, IMappingEngineRunner mapper) { bool toEnum = false; Type enumSourceType = TypeHelper.GetEnumerationType(context.SourceType); Type enumDestinationType = TypeHelper.GetEnumerationType(context.DestinationType); if (EnumToStringMapping(context, ref toEnum)) { if (context.SourceValue == null) { return(mapper.CreateObject(context)); } if (toEnum) { var stringValue = context.SourceValue.ToString(); if (string.IsNullOrEmpty(stringValue)) { return(mapper.CreateObject(context)); } return(Enum.Parse(enumDestinationType, stringValue, true)); } return(Enum.GetName(enumSourceType, context.SourceValue)); } if (EnumToEnumMapping(context)) { if (context.SourceValue == null) { return(mapper.CreateObject(context)); } if (!Enum.IsDefined(enumSourceType, context.SourceValue)) { return(Enum.ToObject(enumDestinationType, context.SourceValue)); } #if !SILVERLIGHT if (!Enum.GetNames(enumDestinationType).Contains(context.SourceValue.ToString())) { Type underlyingSourceType = Enum.GetUnderlyingType(enumSourceType); var underlyingSourceValue = Convert.ChangeType(context.SourceValue, underlyingSourceType); return(Enum.ToObject(context.DestinationType, underlyingSourceValue)); } #endif return(Enum.Parse(enumDestinationType, Enum.GetName(enumSourceType, context.SourceValue), true)); } if (EnumToUnderlyingTypeMapping(context, ref toEnum)) { if (toEnum) { return(Enum.Parse(enumDestinationType, context.SourceValue.ToString(), true)); } return(Convert.ChangeType(context.SourceValue, context.DestinationType, null)); } return(null); }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { bool toEnum = false; Type enumSourceType = TypeHelper.GetEnumerationType(context.SourceType); Type enumDestinationType = TypeHelper.GetEnumerationType(context.DestinationType); if (EnumToStringMapping(context, ref toEnum)) { if (context.SourceValue == null) { return mapper.CreateObject(context); } if (toEnum) { var stringValue = context.SourceValue.ToString(); if (string.IsNullOrEmpty(stringValue)) { return mapper.CreateObject(context); } return Enum.Parse(enumDestinationType, stringValue, true); } return Enum.GetName(enumSourceType, context.SourceValue); } if (EnumToEnumMapping(context)) { if (context.SourceValue == null) { return mapper.CreateObject(context); } if (!Enum.IsDefined(enumSourceType, context.SourceValue)) { return Enum.ToObject(enumDestinationType, context.SourceValue); } #if !SILVERLIGHT && !__ANDROID__ if (!Enum.GetNames(enumDestinationType).Contains(context.SourceValue.ToString())) { Type underlyingSourceType = Enum.GetUnderlyingType(enumSourceType); var underlyingSourceValue = Convert.ChangeType(context.SourceValue, underlyingSourceType); return Enum.ToObject(context.DestinationType, underlyingSourceValue); } #endif return Enum.Parse(enumDestinationType, Enum.GetName(enumSourceType, context.SourceValue), true); } if (EnumToUnderlyingTypeMapping(context, ref toEnum)) { if (toEnum) { return Enum.Parse(enumDestinationType, context.SourceValue.ToString(), true); } return Convert.ChangeType(context.SourceValue, context.DestinationType, null); } return null; }
protected override object GetMappedObject(ResolutionContext context, IMappingEngineRunner mapper) { var result = mapper.CreateObject(context); context.SetResolvedDestinationValue(result); return(result); }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { if (context.SourceValue == null) { return mapper.CreateObject(context); } Func<object> converter = GetConverter(context); return converter != null ? converter() : null; }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { if (context.SourceValue == null && !mapper.ShouldMapSourceCollectionAsNull(context)) { return mapper.CreateObject(context); } return context.SourceValue; }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { if (context.SourceValue == null && !mapper.ShouldMapSourceCollectionAsNull(context)) { return(mapper.CreateObject(context)); } return(context.SourceValue); }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { if (context.SourceValue == null) { return mapper.CreateObject(context); } return context.SourceValue; }
private object CreateDestinationObject(ResolutionContext context, Type destinationElementType, int count, IMappingEngineRunner mapper) { var destinationType = context.DestinationType; if (!destinationType.IsInterface && !destinationType.IsArray) { return(mapper.CreateObject(context)); } return(CreateDestinationObjectBase(destinationElementType, count)); }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { if (context.SourceValue == null) { return mapper.CreateObject(context); } TypeConverter typeConverter = GetTypeConverter(context); return typeConverter.ConvertTo(context.SourceValue, context.DestinationType); }
protected override object GetMappedObject(ResolutionContext context, IMappingEngineRunner mapper) { var result = mapper.CreateObject(context); if (result == null) { throw new InvalidOperationException("Cannot create destination object. " + context); } return(result); }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { if (context.SourceValue == null) { return(mapper.CreateObject(context)); } Func <object> converter = GetConverter(context); return(converter != null?converter() : null); }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { if (context.SourceValue == null) { return(mapper.CreateObject(context)); } TypeConverter typeConverter = GetTypeConverter(context); return(typeConverter.ConvertTo(context.SourceValue, context.DestinationType)); }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { var enumDestType = TypeHelper.GetEnumerationType(context.DestinationType); if (context.SourceValue == null) { return(mapper.CreateObject(context)); } return(Enum.Parse(enumDestType, context.SourceValue.ToString(), true)); }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { var enumDestType = TypeHelper.GetEnumerationType(context.DestinationType); if (context.SourceValue == null) { return mapper.CreateObject(context); } return Enum.Parse(enumDestType, context.SourceValue.ToString(), true); }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { if (context == null) throw new ArgumentNullException("context"); if (mapper == null) throw new ArgumentNullException("mapper"); if (context.SourceValue == null && !mapper.ShouldMapSourceValueAsNull(context)) { return mapper.CreateObject(context); } return context.SourceValue; }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { Type enumDestType = TypeHelper.GetEnumerationType(context.DestinationType); if (context.SourceValue == null) { return mapper.CreateObject(context); } Type enumSourceType = TypeHelper.GetEnumerationType(context.SourceType); return Enum.Parse(enumDestType, Enum.GetName(enumSourceType, context.SourceValue)); }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { if (context == null) throw new ArgumentNullException("context"); if (mapper == null) throw new ArgumentNullException("mapper"); if (context.SourceValue == null) { return mapper.CreateObject(context); } TypeConverter typeConverter = GetTypeConverter(context); return typeConverter.ConvertTo(context.SourceValue, context.DestinationType); }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { var dictionary = (StringDictionary)context.SourceValue; object destination = mapper.CreateObject(context); var destTypeDetails = new TypeDetails(context.DestinationType, _ => true, _ => true); var members = from name in dictionary.Keys join member in destTypeDetails.PublicWriteAccessors on name equals member.Name select member; foreach(var member in members) { object value = ReflectionHelper.Map(member, dictionary[member.Name]); member.SetMemberValue(destination, value); } return destination; }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { if (context == null) throw new ArgumentNullException("context"); if (mapper == null) throw new ArgumentNullException("mapper"); bool toEnum = false; Type enumSourceType = TypeHelper.GetEnumerationType(context.SourceType); Type enumDestinationType = TypeHelper.GetEnumerationType(context.DestinationType); if (EnumToStringMapping(context, ref toEnum)) { if (toEnum) { return Enum.Parse(enumDestinationType, context.SourceValue.ToString(), true); } return Enum.GetName(enumSourceType, context.SourceValue); } if (EnumToEnumMapping(context)) { if (context.SourceValue == null) { return mapper.CreateObject(context); } if (!Enum.IsDefined(enumSourceType, context.SourceValue)) { return Enum.ToObject(enumDestinationType, context.SourceValue); } #if !SILVERLIGHT if (!Enum.GetNames(enumDestinationType).Contains(context.SourceValue.ToString())) { Type underlyingSourceType = Enum.GetUnderlyingType(enumSourceType); var underlyingSourceValue = Convert.ChangeType(context.SourceValue, underlyingSourceType); return Enum.ToObject(context.DestinationType, underlyingSourceValue); } #endif return Enum.Parse(enumDestinationType, Enum.GetName(enumSourceType, context.SourceValue), true); } if (EnumToUnderlyingTypeMapping(context, ref toEnum)) { if (toEnum) { return Enum.Parse(enumDestinationType, context.SourceValue.ToString(), true); } return Convert.ChangeType(context.SourceValue, context.DestinationType, null); } return null; }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { var dictionary = (StringDictionary)context.SourceValue; object destination = mapper.CreateObject(context); var destTypeDetails = new TypeDetails(context.DestinationType, _ => true, _ => true); var members = from name in dictionary.Keys join member in destTypeDetails.PublicWriteAccessors on name equals member.Name select member; foreach (var member in members) { object value = ReflectionHelper.Map(member, dictionary[member.Name]); member.SetMemberValue(destination, value); } return(destination); }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { if (context == null) throw new ArgumentNullException("context"); if (mapper == null) throw new ArgumentNullException("mapper"); Type enumDestType = TypeHelper.GetEnumerationType(context.DestinationType); if (context.SourceValue == null) { return mapper.CreateObject(context); } return Enum.Parse(enumDestType, context.SourceValue.ToString(), true); }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { // If source is int, create an identifiable for the destination. // Otherwise, get the Id of the identifiable. if (typeof(int) == context.SourceType) { var identifiable = (IIdentifiable)mapper.CreateObject(context); identifiable.Id = (int)context.SourceValue; return(identifiable); } else { return(((IIdentifiable)context.SourceValue).Id); } }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { var source = context.SourceValue; var destination = mapper.CreateObject(context); foreach (var member in MembersToMap(source, destination)) { object sourceMemberValue; try { sourceMemberValue = GetSourceMember(member, source); } catch (RuntimeBinderException) { continue; } var destinationMemberValue = ReflectionHelper.Map(member, sourceMemberValue); SetDestinationMember(member, destination, destinationMemberValue); } return destination; }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { var source = context.SourceValue; var destination = mapper.CreateObject(context); foreach (var member in MembersToMap(source, destination)) { object sourceMemberValue; try { sourceMemberValue = GetSourceMember(member, source); } catch (RuntimeBinderException) { continue; } var destinationMemberValue = ReflectionHelper.Map(member, sourceMemberValue); SetDestinationMember(member, destination, destinationMemberValue); } return(destination); }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { bool toEnum = false; Type enumSourceType = TypeHelper.GetEnumerationType(context.SourceType); if (EnumToStringMapping(context, ref toEnum)) { if (toEnum) { return Enum.Parse(context.DestinationType, context.SourceValue.ToString(), true); } return Enum.GetName(enumSourceType, context.SourceValue); } if (EnumToEnumMapping(context)) { Type enumDestType = TypeHelper.GetEnumerationType(context.DestinationType); if (context.SourceValue == null) { return mapper.CreateObject(context); } if (!Enum.IsDefined(enumSourceType, context.SourceValue)) { return Enum.ToObject(context.DestinationType, context.SourceValue); } return Enum.Parse(enumDestType, Enum.GetName(enumSourceType, context.SourceValue), true); } if (EnumToUnderlyingTypeMapping(context, ref toEnum)) { if (toEnum) { return Enum.Parse(context.DestinationType, context.SourceValue.ToString(), true); } return Convert.ChangeType(context.SourceValue, context.DestinationType, null); } return null; }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { return(context.SourceValue ?? mapper.CreateObject(context)); }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { bool toEnum = false; Type enumSourceType = TypeHelper.GetEnumerationType(context.SourceType); Type enumDestinationType = TypeHelper.GetEnumerationType(context.DestinationType); if (EnumToStringMapping(context, ref toEnum)) { if (context.SourceValue == null) { return mapper.CreateObject(context); } if (toEnum) { var stringValue = context.SourceValue.ToString(); if (string.IsNullOrEmpty(stringValue)) { return mapper.CreateObject(context); } return Enum.Parse(enumDestinationType, stringValue, true); } return Enum.GetName(enumSourceType, context.SourceValue); } if (EnumToEnumMapping(context)) { if (context.SourceValue == null) { if (mapper.ShouldMapSourceValueAsNull(context) && context.DestinationType.IsNullableType()) return null; return mapper.CreateObject(context); } if (!Enum.IsDefined(enumSourceType, context.SourceValue)) { return Enum.ToObject(enumDestinationType, context.SourceValue); } if (FeatureDetector.IsEnumGetNamesSupported) { var enumValueMapper = EnumNameValueMapperFactory.Create(); if (enumValueMapper.IsMatch(enumDestinationType, context.SourceValue.ToString())) { return enumValueMapper.Convert(enumSourceType, enumDestinationType, context); } } return Enum.Parse(enumDestinationType, Enum.GetName(enumSourceType, context.SourceValue), true); } if (EnumToUnderlyingTypeMapping(context, ref toEnum)) { if (toEnum && context.SourceValue != null) { return Enum.Parse(enumDestinationType, context.SourceValue.ToString(), true); } if (EnumToNullableTypeMapping(context)) { return ConvertEnumToNullableType(context); } return Convert.ChangeType(context.SourceValue, context.DestinationType, null); } return null; }
public object Map(ResolutionContext context, IMappingEngineRunner mapper) { bool toEnum = false; Type enumSourceType = TypeHelper.GetEnumerationType(context.SourceType); Type enumDestinationType = TypeHelper.GetEnumerationType(context.DestinationType); if (EnumToStringMapping(context, ref toEnum)) { if (context.SourceValue == null) { return(mapper.CreateObject(context)); } if (toEnum) { var stringValue = context.SourceValue.ToString(); if (string.IsNullOrEmpty(stringValue)) { return(mapper.CreateObject(context)); } return(Enum.Parse(enumDestinationType, stringValue, true)); } return(Enum.GetName(enumSourceType, context.SourceValue)); } if (EnumToEnumMapping(context)) { if (context.SourceValue == null) { if (mapper.ShouldMapSourceValueAsNull(context) && context.DestinationType.IsNullableType()) { return(null); } return(mapper.CreateObject(context)); } if (!Enum.IsDefined(enumSourceType, context.SourceValue)) { return(Enum.ToObject(enumDestinationType, context.SourceValue)); } if (FeatureDetector.IsEnumGetNamesSupported) { var enumValueMapper = EnumNameValueMapperFactory.Create(); if (enumValueMapper.IsMatch(enumDestinationType, context.SourceValue.ToString())) { return(enumValueMapper.Convert(enumSourceType, enumDestinationType, context)); } } return(Enum.Parse(enumDestinationType, Enum.GetName(enumSourceType, context.SourceValue), true)); } if (EnumToUnderlyingTypeMapping(context, ref toEnum)) { if (toEnum) { return(Enum.Parse(enumDestinationType, context.SourceValue.ToString(), true)); } if (EnumToNullableTypeMapping(context)) { return(ConvertEnumToNullableType(context)); } return(Convert.ChangeType(context.SourceValue, context.DestinationType, null)); } return(null); }
protected override object GetMappedObject(ResolutionContext context, IMappingEngineRunner mapper) { var result = mapper.CreateObject(context); if(result == null) { throw new InvalidOperationException("Cannot create destination object. " + context); } return result; }
protected override object GetMappedObject(ResolutionContext context, IMappingEngineRunner mapper) { var result = mapper.CreateObject(context); context.SetResolvedDestinationValue(result); return result; }
protected override object GetMappedObject(ResolutionContext context, IMappingEngineRunner mapper) { return mapper.CreateObject(context); }
protected override object GetMappedObject(ResolutionContext context, IMappingEngineRunner mapper) { return(mapper.CreateObject(context)); }