コード例 #1
0
 public BuilderMemberInfo(IPropertyMappingInfo mappingMember)
 {
     Attributes = mappingMember.Attributes;
     Type       = mappingMember.Type;
     Name       = mappingMember.Name;
     MemberType = MemberType.Property;
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 protected override MethodBase GetInitMethod(IPropertyMappingInfo propInfo)
 {
     return(TypeHelpers.TryGetConstructor(propInfo.Type));
 }
コード例 #7
0
 public bool IsMemberSuitable(IPropertyMappingInfo mappingMember)
 {
     return(false);
 }
コード例 #8
0
 public ISourceInfo ResolveSourceValue(IPropertyMappingInfo mappingMember, object source)
 {
     return(null);
 }
コード例 #9
0
        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;
        }
コード例 #10
0
 public bool IsMemberSuitable(IPropertyMappingInfo mappingMember)
 {
     return(IsMemberSuitable(new BuilderMemberInfo(mappingMember)));
 }
コード例 #11
0
 public bool IsMemberSuitable(IPropertyMappingInfo propertyInfo)
 {
     return(propertyInjections.ContainsKey(BuilderUtils.GetKey(propertyInfo)));
 }
コード例 #12
0
        public bool IsMemberSuitable(IPropertyMappingInfo propInfo)
        {
            var propInfoKey = BuilderUtils.GetKey(propInfo);

            return(PropertyInjectionResolvers.ContainsKey(propInfoKey));
        }
コード例 #13
0
        protected override ISourceInfo GetMappingData(ISourceMappingResolver sourceMappingResolver, IPropertyMappingInfo propertyInfo)
        {
            var sourceValue = sourceMappingResolver.ResolveSourceValue(propertyInfo, Context.Source);

            return(sourceMappingResolver.ResolveSourceValue(propertyInfo, Context.Source));
        }
コード例 #14
0
ファイル: TypeMappingInfo.cs プロジェクト: stadub/Net.Utils
 public TypeMappingInfo(IPropertyMappingInfo <TClass> mappingInfo, IPropertyRegistrationInfo <TClass> registrationInfo)
 {
     this.mappingInfo      = mappingInfo;
     this.registrationInfo = registrationInfo;
 }
コード例 #15
0
 public bool MapPropery(ITypeMapper mapper, IPropertyMappingInfo propInfo, object sourceValue, IList <Attribute> metadata = null)
 {
     return(metadata.Any(attribute => attribute is NonSerializableAttribute));
 }
コード例 #16
0
 public MappingMemberInfo(IPropertyMappingInfo mappingMember, object source)
     : base(mappingMember)
 {
     SourceInstance = source;
 }
コード例 #17
0
 public static KeyValuePair <string, string> GetKey(IPropertyMappingInfo propInfo)
 {
     return(new KeyValuePair <string, string>(propInfo.Name, propInfo.Type.FullName));
 }
コード例 #18
0
 public ISourceInfo ResolveSourceValue(IPropertyMappingInfo mappingMember, object source)
 {
     return(ResolveSourceValue(new MappingMemberInfo(mappingMember, source)));
 }