Ejemplo n.º 1
0
        protected FieldBase(FieldInfo fi)
        {
            mFieldInfo     = fi;
            mFieldType     = mFieldInfo.FieldType;
            mIsStringField = mFieldType == strType;

            var attribs = fi.GetCustomAttributes(typeof(FieldConverterAttribute), true);

            if (attribs.Length > 0)
            {
                var conv = (FieldConverterAttribute)attribs[0];
                mConvertProvider = conv.Converter;
                conv.ValidateTypes(mFieldInfo);
            }
            else
            {
                mConvertProvider = ConvertHelpers.GetDefaultConverter(fi.Name, mFieldType);
            }

            if (mConvertProvider != null)
            {
                mConvertProvider.mDestinationType = fi.FieldType;
            }

            attribs = fi.GetCustomAttributes(typeof(FieldNullValueAttribute), true);

            if (attribs.Length > 0)
            {
                mNullValue = ((FieldNullValueAttribute)attribs[0]).NullValue;
//				mNullValueOnWrite = ((FieldNullValueAttribute) attribs[0]).NullValueOnWrite;

                if (mNullValue != null)
                {
                    if (!mFieldType.IsAssignableFrom(mNullValue.GetType()))
                    {
                        throw new BadUsageException("The NullValue is of type: " + mNullValue.GetType().Name +
                                                    " that is not asignable to the field " + mFieldInfo.Name + " of type: " +
                                                    mFieldType.Name);
                    }
                }
            }


#if NET_2_0
            mIsNullableType = mFieldType.IsValueType &&
                              mFieldType.IsGenericType &&
                              mFieldType.GetGenericTypeDefinition() == typeof(Nullable <>);
#endif
        }