//internal bool mNullValueOnWrite = false; #endregion #region " Constructor " protected FieldBase(FieldInfo fi) { mFieldInfo = fi; mFieldType = mFieldInfo.FieldType; object[] attribs = fi.GetCustomAttributes(typeof(FieldConverterAttribute), true); if (attribs.Length > 0) { mConvertProvider = ((FieldConverterAttribute)attribs[0]).Converter; } else { mConvertProvider = ConvertHelpers.GetDefaultConverter(fi.Name, mFieldType); } 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); } } } }
internal FieldBase(FieldInfo fi) { mFieldInfo = fi; mFieldType = mFieldInfo.FieldType; if (mFieldType.IsArray) { mFieldTypeInternal = mFieldType.GetElementType(); } else { mFieldTypeInternal = mFieldType; } mIsStringField = mFieldTypeInternal == strType; object[] attribs = fi.GetCustomAttributes(typeof(FieldConverterAttribute), true); if (attribs.Length > 0) { FieldConverterAttribute conv = (FieldConverterAttribute)attribs[0]; mConvertProvider = conv.Converter; conv.ValidateTypes(mFieldInfo); } else { mConvertProvider = ConvertHelpers.GetDefaultConverter(fi.Name, mFieldType); } if (mConvertProvider != null) { mConvertProvider.mDestinationType = mFieldTypeInternal; } attribs = fi.GetCustomAttributes(typeof(FieldNullValueAttribute), true); if (attribs.Length > 0) { mNullValue = ((FieldNullValueAttribute)attribs[0]).NullValue; // mNullValueOnWrite = ((FieldNullValueAttribute) attribs[0]).NullValueOnWrite; if (mNullValue != null) { if (!mFieldTypeInternal.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: " + mFieldTypeInternal.Name); } } } #if NET_2_0 mIsNullableType = mFieldTypeInternal.IsValueType && mFieldTypeInternal.IsGenericType && mFieldTypeInternal.GetGenericTypeDefinition() == typeof(Nullable <>); #endif }
/// <summary> /// Create a field base from a fieldinfo object /// Verify the settings against the actual field to ensure it will work. /// </summary> /// <param name="fi">Field Info Object</param> internal FieldBase(FieldInfo fi) : this() { FieldInfo = fi; FieldType = FieldInfo.FieldType; if (FieldType.IsArray) { FieldTypeInternal = FieldType.GetElementType(); } else { FieldTypeInternal = FieldType; } IsStringField = FieldTypeInternal == typeof(string); object[] attribs = fi.GetCustomAttributes(typeof(FieldConverterAttribute), true); if (attribs.Length > 0) { var conv = (FieldConverterAttribute)attribs[0]; this.Converter = conv.Converter; conv.ValidateTypes(FieldInfo); } else { this.Converter = ConvertHelpers.GetDefaultConverter(fi.Name, FieldType); } if (this.Converter != null) { this.Converter.mDestinationType = FieldTypeInternal; } attribs = fi.GetCustomAttributes(typeof(FieldNullValueAttribute), true); if (attribs.Length > 0) { NullValue = ((FieldNullValueAttribute)attribs[0]).NullValue; // mNullValueOnWrite = ((FieldNullValueAttribute) attribs[0]).NullValueOnWrite; if (NullValue != null) { if (!FieldTypeInternal.IsAssignableFrom(NullValue.GetType())) { throw new BadUsageException("The NullValue is of type: " + NullValue.GetType().Name + " that is not asignable to the field " + FieldInfo.Name + " of type: " + FieldTypeInternal.Name); } } } IsNullableType = FieldTypeInternal.IsValueType && FieldTypeInternal.IsGenericType && FieldTypeInternal.GetGenericTypeDefinition() == typeof(Nullable <>); }
/// <summary> /// Create a field base from a fieldinfo object /// Verify the settings against the actual field to ensure it will work. /// </summary> /// <param name="fi">Field Info Object</param> internal FieldBase(FieldInfo fi) { IsNullableType = false; TrimMode = TrimMode.None; FieldOrder = null; InNewLine = false; NextIsOptional = false; IsOptional = false; TrimChars = null; NullValue = null; TrailingArray = false; IsLast = false; IsFirst = false; IsArray = false; CharsToDiscard = 0; FieldInfo = fi; FieldType = FieldInfo.FieldType; NullFieldOnError = false; if (FieldType.IsArray) { FieldTypeInternal = FieldType.GetElementType(); } else { FieldTypeInternal = FieldType; } IsStringField = FieldTypeInternal == typeof(string); object[] attribs = fi.GetCustomAttributes(typeof(FieldConverterAttribute), true); if (attribs.Length > 0) { var conv = (FieldConverterAttribute)attribs[0]; this.Converter = conv.Converter; conv.ValidateTypes(FieldInfo); } else { this.Converter = ConvertHelpers.GetDefaultConverter(fi.Name, FieldType); } if (this.Converter != null) { this.Converter.mDestinationType = FieldTypeInternal; } attribs = fi.GetCustomAttributes(typeof(FieldNullValueAttribute), true); if (attribs.Length > 0) { NullValue = ((FieldNullValueAttribute)attribs[0]).NullValue; // mNullValueOnWrite = ((FieldNullValueAttribute) attribs[0]).NullValueOnWrite; if (NullValue != null) { if (!FieldTypeInternal.IsAssignableFrom(NullValue.GetType())) { throw new BadUsageException("The NullValue is of type: " + NullValue.GetType().Name + " that is not asignable to the field " + FieldInfo.Name + " of type: " + FieldTypeInternal.Name); } } } IsNullableType = FieldTypeInternal.IsValueType && FieldTypeInternal.IsGenericType && FieldTypeInternal.GetGenericTypeDefinition() == typeof(Nullable <>); }
/// <summary> /// Create a field base from a fieldinfo object /// Verify the settings against the actual field to ensure it will work. /// </summary> /// <param name="fi">Field Info Object</param> /// <param name="defaultCultureName">Default culture name used for each properties if no converter is specified otherwise. If null, the default decimal separator (".") will be used.</param> internal FieldBase(FieldInfo fi, string defaultCultureName = null) : this() { FieldInfo = fi; FieldType = FieldInfo.FieldType; MemberInfo attibuteTarget = fi; FieldFriendlyName = AutoPropertyName(fi); if (string.IsNullOrEmpty(FieldFriendlyName) == false) { var prop = fi.DeclaringType.GetProperty(FieldFriendlyName); if (prop == null) { FieldFriendlyName = null; } else { attibuteTarget = prop; } } if (FieldType.IsArray) { FieldTypeInternal = FieldType.GetElementType(); } else { FieldTypeInternal = FieldType; } IsStringField = FieldTypeInternal == typeof(string); object[] attribs = attibuteTarget.GetCustomAttributes(typeof(FieldConverterAttribute), true); if (attribs.Length > 0) { var conv = (FieldConverterAttribute)attribs[0]; Converter = conv.Converter; conv.ValidateTypes(FieldInfo); } else { Converter = ConvertHelpers.GetDefaultConverter(FieldFriendlyName ?? fi.Name, FieldType, defaultCultureName: defaultCultureName); } if (Converter != null) { Converter.mDestinationType = FieldTypeInternal; } attribs = attibuteTarget.GetCustomAttributes(typeof(FieldNullValueAttribute), true); if (attribs.Length > 0) { NullValue = ((FieldNullValueAttribute)attribs[0]).NullValue; if (NullValue != null) { if (!FieldTypeInternal.IsAssignableFrom(NullValue.GetType())) { throw new BadUsageException("The NullValue is of type: " + NullValue.GetType().Name + " that is not asignable to the field " + FieldInfo.Name + " of type: " + FieldTypeInternal.Name); } } } IsNullableType = FieldTypeInternal.IsValueType && FieldTypeInternal.IsGenericType && FieldTypeInternal.GetGenericTypeDefinition() == typeof(Nullable <>); }