public BuilderMemberInfo(IPropertyMappingInfo mappingMember) { Attributes = mappingMember.Attributes; Type = mappingMember.Type; Name = mappingMember.Name; MemberType = MemberType.Property; }
public bool MapPropery(ITypeMapper mapper, IPropertyMappingInfo propInfo, object sourceValue, IList <Attribute> metadata = null) { if (!mapper.CanMap(sourceValue, propInfo.Type)) { return(false); } IOperationResult mappingResult; if (mapper is ITypeInfoMapper) { mappingResult = ((ITypeInfoMapper)mapper).Map(new SourceInfo(sourceValue) { Attributes = metadata }, propInfo.Type); } else { mappingResult = mapper.Map(sourceValue, propInfo.Type); } if (mappingResult.Success) { propInfo.SetValue(mappingResult.Value); return(true); } return(false); }
protected virtual MethodBase GetInitMethod(IPropertyMappingInfo propInfo) { var destType = propInfo.SourceInstance.GetType(); var initalizer = propInfo.Attributes.FirstOrDefault(x => x is UseInitalizerAttribute) as UseInitalizerAttribute; if (initalizer == null) { return(null); } return(destType.GetMethod(initalizer.Name)); }
public ISourceInfo ResolveSourceValue(IPropertyMappingInfo propertyInfo, object source) { var key = BuilderUtils.GetKey(propertyInfo); object value; if (propertyInjections.TryGetValue(key, out value)) { return(SourceInfo.Create(value)); } return(null); }
public ISourceInfo ResolveSourceValue(IPropertyMappingInfo propInfo, object source) { var propInfoKey = BuilderUtils.GetKey(propInfo); KeyValuePair <string, Type> valueType; if (PropertyInjectionResolvers.TryGetValue(propInfoKey, out valueType)) { object value; if (locator.TryResolve(valueType.Value, valueType.Key, out value)) { return(SourceInfo.Create(value)); } } return(null); }
protected override MethodBase GetInitMethod(IPropertyMappingInfo propInfo) { return(TypeHelpers.TryGetConstructor(propInfo.Type)); }
public bool IsMemberSuitable(IPropertyMappingInfo mappingMember) { return(false); }
public ISourceInfo ResolveSourceValue(IPropertyMappingInfo mappingMember, object source) { return(null); }
public bool MapPropery(ITypeMapper mapper, IPropertyMappingInfo propInfo, object sourceValue, IList <Attribute> metadata = null) { if (!mapper.CanMap(sourceValue, propInfo.Type)) { return(false); } Exception exception; MethodBase initalizerMethod = null; try { initalizerMethod = GetInitMethod(propInfo); } catch (AmbiguousMatchException ex) { exception = ex; } catch (ArgumentNullException ex) { exception = ex; } if (initalizerMethod == null) { return(false); } try { var parameters = initalizerMethod.GetParameters(); if (parameters.Length != 1) { return(false); } //throw new ArgumentException("Only initalizers with single argument are supported."); var paramType = parameters[0].ParameterType; if (!mapper.CanMap(sourceValue, paramType)) { return(false); } IOperationResult mappingResult; if (mapper is ITypeInfoMapper) { mappingResult = ((ITypeInfoMapper)mapper).Map(new SourceInfo(sourceValue) { Attributes = metadata }, paramType); } else { mappingResult = mapper.Map(sourceValue, paramType); } if (mappingResult.Success) { var invokationInfo = new InitMethodInfo { InitalizerMethod = initalizerMethod, PropInfo = propInfo, Instance = propInfo.SourceInstance, MappingArgs = new[] { mappingResult.Value } }; return(InvokeInitMethod(invokationInfo)); } return(false); } catch (TargetException ex) { exception = ex; } catch (ArgumentException ex) { exception = ex; } catch (TargetInvocationException ex) { exception = ex; } catch (TargetParameterCountException ex) { exception = ex; } catch (MethodAccessException ex) { exception = ex; } catch (InvalidOperationException ex) { exception = ex; } catch (NotSupportedException ex) { exception = ex; } throw exception; }
public bool IsMemberSuitable(IPropertyMappingInfo mappingMember) { return(IsMemberSuitable(new BuilderMemberInfo(mappingMember))); }
public bool IsMemberSuitable(IPropertyMappingInfo propertyInfo) { return(propertyInjections.ContainsKey(BuilderUtils.GetKey(propertyInfo))); }
public bool IsMemberSuitable(IPropertyMappingInfo propInfo) { var propInfoKey = BuilderUtils.GetKey(propInfo); return(PropertyInjectionResolvers.ContainsKey(propInfoKey)); }
protected override ISourceInfo GetMappingData(ISourceMappingResolver sourceMappingResolver, IPropertyMappingInfo propertyInfo) { var sourceValue = sourceMappingResolver.ResolveSourceValue(propertyInfo, Context.Source); return(sourceMappingResolver.ResolveSourceValue(propertyInfo, Context.Source)); }
public TypeMappingInfo(IPropertyMappingInfo <TClass> mappingInfo, IPropertyRegistrationInfo <TClass> registrationInfo) { this.mappingInfo = mappingInfo; this.registrationInfo = registrationInfo; }
public bool MapPropery(ITypeMapper mapper, IPropertyMappingInfo propInfo, object sourceValue, IList <Attribute> metadata = null) { return(metadata.Any(attribute => attribute is NonSerializableAttribute)); }
public MappingMemberInfo(IPropertyMappingInfo mappingMember, object source) : base(mappingMember) { SourceInstance = source; }
public static KeyValuePair <string, string> GetKey(IPropertyMappingInfo propInfo) { return(new KeyValuePair <string, string>(propInfo.Name, propInfo.Type.FullName)); }
public ISourceInfo ResolveSourceValue(IPropertyMappingInfo mappingMember, object source) { return(ResolveSourceValue(new MappingMemberInfo(mappingMember, source))); }