Exemplo n.º 1
0
        public CachedType(Type type, EmitReflector reflectorProvider)
        {
            foreach (PropertyInfo property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (!property.CanRead || !property.CanWrite)
                    continue;

                ConvertTypeHandler handler;
                if (property.PropertyType == typeof(string))
                    handler = ToString;
                else if (property.PropertyType == typeof(DateTime))
                    handler = ToDate;
                else if (property.PropertyType.IsEnum)
                    handler = ToEnum;
                else if (property.PropertyType == typeof(bool))
                    handler = ToBoolean;
                else
                    handler = ConvertValue;

                _properties.Add(property.Name, new CachedProperty
                                                   {
                                                       Convert = handler,
                                                       MemberInfo = property,
                                                       MemberType = property.PropertyType
                                                   });
            }
            _type = type;
            _reflectorProvider = reflectorProvider;
        }
Exemplo n.º 2
0
        public CachedType(Type type, EmitReflector reflectorProvider)
        {
            foreach (PropertyInfo property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (!property.CanRead || !property.CanWrite)
                {
                    continue;
                }

                ConvertTypeHandler handler;
                if (property.PropertyType == typeof(string))
                {
                    handler = ToString;
                }
                else if (property.PropertyType == typeof(DateTime))
                {
                    handler = ToDate;
                }
                else if (property.PropertyType.IsEnum)
                {
                    handler = ToEnum;
                }
                else if (property.PropertyType == typeof(bool))
                {
                    handler = ToBoolean;
                }
                else
                {
                    handler = ConvertValue;
                }

                _properties.Add(property.Name, new CachedProperty
                {
                    Convert    = handler,
                    MemberInfo = property,
                    MemberType = property.PropertyType
                });
            }
            _type = type;
            _reflectorProvider = reflectorProvider;
        }