public FieldInfoItem(FieldInfo field, bool allowNullEquivalentValue, String propertyName) { ParamChecker.AssertParamNotNull(field, "field"); ParamChecker.AssertParamNotNull(propertyName, "propertyName"); this.allowNullEquivalentValue = allowNullEquivalentValue; this.field = field; DeclaringType = field.DeclaringType; #if SILVERLIGHT if (!field.IsPublic) { throw new Exception("Field '" + field + "' not public. This is not valid in Silverlight. One possibility is to set the field public or define public setter/getter."); } #endif this.propertyName = propertyName; Type fieldType = field.FieldType; ElementType = TypeInfoItemUtil.GetElementTypeUsingReflection(fieldType, null); if (fieldType.IsValueType || fieldType.IsPrimitive) { NullEquivalentValue = NullEquivalentValueUtil.GetNullEquivalentValue(fieldType); } Object[] attributes = field.GetCustomAttributes(typeof(XmlElementAttribute), false); if (attributes != null && attributes.Length > 0) { XMLName = ((XmlElementAttribute)attributes[0]).ElementName; } if (XMLName == null || XMLName.Length == 0) { XMLName = Name; } xmlIgnore = false; #if !SILVERLIGHT attributes = field.GetCustomAttributes(typeof(NonSerializedAttribute), false); if (attributes != null && attributes.Length > 0) { xmlIgnore = true; } #endif attributes = field.GetCustomAttributes(typeof(IgnoreDataMemberAttribute), false); if (attributes != null && attributes.Length > 0) { xmlIgnore = true; } attributes = field.GetCustomAttributes(typeof(XmlIgnoreAttribute), false); if (attributes != null && attributes.Length > 0) { xmlIgnore = true; } }
public PropertyInfoItem(IPropertyInfo property, bool allowNullEquivalentValue) { this.property = (IPropertyInfoIntern)property; this.AllowNullEquivalentValue = allowNullEquivalentValue; Type propertyType = property.PropertyType; DeclaringType = property.DeclaringType; ElementType = TypeInfoItemUtil.GetElementTypeUsingReflection(propertyType, null); if (propertyType.IsValueType || propertyType.IsPrimitive) { NullEquivalentValue = NullEquivalentValueUtil.GetNullEquivalentValue(propertyType); } XmlElementAttribute annotation = property.GetAnnotation <XmlElementAttribute>(); if (annotation != null) { XMLName = annotation.ElementName; } if (XMLName == null || XMLName.Length == 0) { XMLName = Name; } xmlIgnore = false; #if !SILVERLIGHT if (property.GetAnnotation <NonSerializedAttribute>() != null) { xmlIgnore = true; } #endif if (property.GetAnnotation <IgnoreDataMemberAttribute>() != null) { xmlIgnore = true; } if (property.GetAnnotation <XmlIgnoreAttribute>() != null) { xmlIgnore = true; } if (!CanRead || !CanWrite) { xmlIgnore = true; } }