public PropertyDescriptor(FieldInfo fldInfo)
        {
            _fieldInfo = fldInfo;

            if (fldInfo != null)
            {
                _propertyName = fldInfo.Name.ToUpper();

                _mappedDBName = _propertyName; // By default the mapped Db name and property name are same

                _type = fldInfo.FieldType;

                _isClass = !IsBaseType(_type);

                if (_type.IsEnum)
                {
                    _enumTypeDescriptor = EnumDescriptorFactory.CreateEnumDescriptor(_type) as EnumDescriptor;
                }
                object[] attrList = fldInfo.GetCustomAttributes(true);

                if (attrList != null && attrList.Length > 0)
                {
                    foreach (object attrib in attrList)
                    {
                        Type attribType = attrib.GetType();
                        if (attribType == typeof(MapFieldAttribute))
                        {
                            if (((MapFieldAttribute)attrib).SourceName != null)
                            {
                                _mappedDBName = ((MapFieldAttribute)attrib).SourceName.ToUpper();
                            }
                        }
                        else if (attribType == typeof(MapDefaultValueAttribute))
                        {
                            _defaultValue = ((MapDefaultValueAttribute)attrib).DefaultValue;
                        }
                        else if (attribType == typeof(MapNullValueAttribute))
                        {
                            _defaultValue = ((MapNullValueAttribute)attrib).TypeValue;
                            _nullValue    = _defaultValue;
                        }
                        if (attribType == typeof(MapIgnoreAttribute))
                        {
                            _isIgnore = true;
                        }
                    }
                }

                if (_nullValue == null)
                {
                    _nullValue = SetDefatulValue(_type);
                }

                if (_defaultValue == null)
                {
                    _defaultValue = SetDefatulValue(_type);
                }
            }
        }
Beispiel #2
0
        public static object ToEnum(object sourceValue, Type type)
        {
            EnumDescriptor enumTypeDescriptor = EnumDescriptorFactory.CreateEnumDescriptor(type) as EnumDescriptor;

            return((Enum)enumTypeDescriptor.MapFrom(sourceValue));
        }
Beispiel #3
0
        public static object FromEnum(Enum enumValue)
        {
            EnumDescriptor enumTypeDescriptor = EnumDescriptorFactory.CreateEnumDescriptor(enumValue.GetType()) as EnumDescriptor;

            return(enumTypeDescriptor.MapTo(enumValue));
        }