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); }
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 override bool CanMap(IEnumerable <TSource> source) { return(elementMapper.CanMap(source.First())); }