private void SetPropertySettingsFromAttributes(JsonProperty property, ICustomAttributeProvider attributeProvider, string name, Type declaringType, MemberSerialization memberSerialization, out bool allowNonPublicAccess, out bool hasExplicitAttribute) { hasExplicitAttribute = false; DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(declaringType); DataMemberAttribute dataMemberAttribute; if (dataContractAttribute != null && attributeProvider is MemberInfo) { dataMemberAttribute = JsonTypeReflector.GetDataMemberAttribute((MemberInfo)attributeProvider); } else { dataMemberAttribute = null; } JsonPropertyAttribute propertyAttribute = JsonTypeReflector.GetAttribute <JsonPropertyAttribute>(attributeProvider); if (propertyAttribute != null) { hasExplicitAttribute = true; } bool hasIgnoreAttribute = (JsonTypeReflector.GetAttribute <JsonIgnoreAttribute>(attributeProvider) != null); string mappedName; if (propertyAttribute != null && propertyAttribute.PropertyName != null) { mappedName = propertyAttribute.PropertyName; } else if (dataMemberAttribute != null && dataMemberAttribute.Name != null) { mappedName = dataMemberAttribute.Name; } else { mappedName = name; } property.PropertyName = ResolvePropertyName(mappedName); property.UnderlyingName = name; if (propertyAttribute != null) { property.Required = propertyAttribute.Required; property.Order = propertyAttribute._order; } else if (dataMemberAttribute != null) { property.Required = (dataMemberAttribute.IsRequired) ? Required.AllowNull : Required.Default; property.Order = (dataMemberAttribute.Order != -1) ? (int?)dataMemberAttribute.Order : null; } else { property.Required = Required.Default; } property.Ignored = (hasIgnoreAttribute || (memberSerialization == MemberSerialization.OptIn && propertyAttribute == null && dataMemberAttribute == null )); // resolve converter for property // the class type might have a converter but the property converter takes presidence property.Converter = JsonTypeReflector.GetJsonConverter(attributeProvider, property.PropertyType); property.MemberConverter = JsonTypeReflector.GetJsonConverter(attributeProvider, property.PropertyType); DefaultValueAttribute defaultValueAttribute = JsonTypeReflector.GetAttribute <DefaultValueAttribute>(attributeProvider); property.DefaultValue = (defaultValueAttribute != null) ? defaultValueAttribute.Value : null; property.NullValueHandling = (propertyAttribute != null) ? propertyAttribute._nullValueHandling : null; property.DefaultValueHandling = (propertyAttribute != null) ? propertyAttribute._defaultValueHandling : null; property.ReferenceLoopHandling = (propertyAttribute != null) ? propertyAttribute._referenceLoopHandling : null; property.ObjectCreationHandling = (propertyAttribute != null) ? propertyAttribute._objectCreationHandling : null; property.TypeNameHandling = (propertyAttribute != null) ? propertyAttribute._typeNameHandling : null; property.IsReference = (propertyAttribute != null) ? propertyAttribute._isReference : null; allowNonPublicAccess = false; if ((DefaultMembersSearchFlags & BindingFlags.NonPublic) == BindingFlags.NonPublic) { allowNonPublicAccess = true; } if (propertyAttribute != null) { allowNonPublicAccess = true; } if (dataMemberAttribute != null) { allowNonPublicAccess = true; hasExplicitAttribute = true; } }
private void SetPropertySettingsFromAttributes(JsonProperty property, ICustomAttributeProvider attributeProvider, string name, Type declaringType, MemberSerialization memberSerialization, out bool allowNonPublicAccess, out bool hasExplicitAttribute) { hasExplicitAttribute = false; #if !PocketPC && !NET20 DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(declaringType); MemberInfo memberInfo = null; #if !(NETFX_CORE || PORTABLE) memberInfo = attributeProvider as MemberInfo; #else memberInfo = attributeProvider.UnderlyingObject as MemberInfo; #endif DataMemberAttribute dataMemberAttribute; if (dataContractAttribute != null && memberInfo != null) { dataMemberAttribute = JsonTypeReflector.GetDataMemberAttribute((MemberInfo)memberInfo); } else { dataMemberAttribute = null; } #endif JsonPropertyAttribute propertyAttribute = JsonTypeReflector.GetAttribute <JsonPropertyAttribute>(attributeProvider); if (propertyAttribute != null) { hasExplicitAttribute = true; } string mappedName; if (propertyAttribute != null && propertyAttribute.PropertyName != null) { mappedName = propertyAttribute.PropertyName; } #if !PocketPC && !NET20 else if (dataMemberAttribute != null && dataMemberAttribute.Name != null) { mappedName = dataMemberAttribute.Name; } #endif else { mappedName = name; } property.PropertyName = ResolvePropertyName(mappedName); property.UnderlyingName = name; if (propertyAttribute != null) { property._required = propertyAttribute._required; property.Order = propertyAttribute._order; } #if !PocketPC && !NET20 else if (dataMemberAttribute != null) { property._required = (dataMemberAttribute.IsRequired) ? Required.AllowNull : Required.Default; property.Order = (dataMemberAttribute.Order != -1) ? (int?)dataMemberAttribute.Order : null; } #endif bool hasJsonIgnoreAttribute = JsonTypeReflector.GetAttribute <JsonIgnoreAttribute>(attributeProvider) != null #if !(SILVERLIGHT || NETFX_CORE || PORTABLE) || JsonTypeReflector.GetAttribute <NonSerializedAttribute>(attributeProvider) != null #endif ; if (memberSerialization != MemberSerialization.OptIn) { // ignored if it has JsonIgnore or NonSerialized attributes property.Ignored = hasJsonIgnoreAttribute; } else { // ignored if it has JsonIgnore/NonSerialized or does not have DataMember or JsonProperty attributes property.Ignored = hasJsonIgnoreAttribute || (propertyAttribute == null #if !PocketPC && !NET20 && dataMemberAttribute == null #endif ); } // resolve converter for property // the class type might have a converter but the property converter takes presidence property.Converter = JsonTypeReflector.GetJsonConverter(attributeProvider, property.PropertyType); property.MemberConverter = JsonTypeReflector.GetJsonConverter(attributeProvider, property.PropertyType); DefaultValueAttribute defaultValueAttribute = JsonTypeReflector.GetAttribute <DefaultValueAttribute>(attributeProvider); property.DefaultValue = (defaultValueAttribute != null) ? defaultValueAttribute.Value : null; property.NullValueHandling = (propertyAttribute != null) ? propertyAttribute._nullValueHandling : null; property.DefaultValueHandling = (propertyAttribute != null) ? propertyAttribute._defaultValueHandling : null; property.ReferenceLoopHandling = (propertyAttribute != null) ? propertyAttribute._referenceLoopHandling : null; property.ObjectCreationHandling = (propertyAttribute != null) ? propertyAttribute._objectCreationHandling : null; property.TypeNameHandling = (propertyAttribute != null) ? propertyAttribute._typeNameHandling : null; property.IsReference = (propertyAttribute != null) ? propertyAttribute._isReference : null; property.ItemIsReference = (propertyAttribute != null) ? propertyAttribute._itemIsReference : null; property.ItemConverter = (propertyAttribute != null && propertyAttribute.ItemConverterType != null) ? JsonConverterAttribute.CreateJsonConverterInstance(propertyAttribute.ItemConverterType) : null; property.ItemReferenceLoopHandling = (propertyAttribute != null) ? propertyAttribute._itemReferenceLoopHandling : null; property.ItemTypeNameHandling = (propertyAttribute != null) ? propertyAttribute._itemTypeNameHandling : null; allowNonPublicAccess = false; if ((DefaultMembersSearchFlags & BindingFlags.NonPublic) == BindingFlags.NonPublic) { allowNonPublicAccess = true; } if (propertyAttribute != null) { allowNonPublicAccess = true; } if (memberSerialization == MemberSerialization.Fields) { allowNonPublicAccess = true; } #if !PocketPC && !NET20 if (dataMemberAttribute != null) { allowNonPublicAccess = true; hasExplicitAttribute = true; } #endif }
private void SetPropertySettingsFromAttributes(JsonProperty property, object attributeProvider, string name, Type declaringType, MemberSerialization memberSerialization, out bool allowNonPublicAccess) { DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(declaringType); MemberInfo memberInfo = attributeProvider as MemberInfo; DataMemberAttribute dataMemberAttribute; if (dataContractAttribute != null && memberInfo != null) { dataMemberAttribute = JsonTypeReflector.GetDataMemberAttribute(memberInfo); } else { dataMemberAttribute = null; } JsonPropertyAttribute attribute = JsonTypeReflector.GetAttribute <JsonPropertyAttribute>(attributeProvider); if (attribute != null) { property.HasMemberAttribute = true; } string propertyName; if (attribute != null && attribute.PropertyName != null) { propertyName = attribute.PropertyName; } else if (dataMemberAttribute != null && dataMemberAttribute.Name != null) { propertyName = dataMemberAttribute.Name; } else { propertyName = name; } property.PropertyName = this.ResolvePropertyName(propertyName); property.UnderlyingName = name; bool flag = false; if (attribute != null) { property._required = attribute._required; property.Order = attribute._order; property.DefaultValueHandling = attribute._defaultValueHandling; flag = true; } else if (dataMemberAttribute != null) { property._required = new Required?(dataMemberAttribute.IsRequired ? Required.AllowNull : Required.Default); property.Order = ((dataMemberAttribute.Order != -1) ? new int?(dataMemberAttribute.Order) : null); property.DefaultValueHandling = ((!dataMemberAttribute.EmitDefaultValue) ? new DefaultValueHandling?(DefaultValueHandling.Ignore) : null); flag = true; } bool flag2 = JsonTypeReflector.GetAttribute <JsonIgnoreAttribute>(attributeProvider) != null || JsonTypeReflector.GetAttribute <JsonExtensionDataAttribute>(attributeProvider) != null || JsonTypeReflector.GetAttribute <NonSerializedAttribute>(attributeProvider) != null; if (memberSerialization != MemberSerialization.OptIn) { bool flag3 = JsonTypeReflector.GetAttribute <IgnoreDataMemberAttribute>(attributeProvider) != null; property.Ignored = (flag2 || flag3); } else { property.Ignored = (flag2 || !flag); } property.Converter = JsonTypeReflector.GetJsonConverter(attributeProvider, property.PropertyType); property.MemberConverter = JsonTypeReflector.GetJsonConverter(attributeProvider, property.PropertyType); DefaultValueAttribute attribute2 = JsonTypeReflector.GetAttribute <DefaultValueAttribute>(attributeProvider); if (attribute2 != null) { property.DefaultValue = attribute2.Value; } property.NullValueHandling = ((attribute != null) ? attribute._nullValueHandling : null); property.ReferenceLoopHandling = ((attribute != null) ? attribute._referenceLoopHandling : null); property.ObjectCreationHandling = ((attribute != null) ? attribute._objectCreationHandling : null); property.TypeNameHandling = ((attribute != null) ? attribute._typeNameHandling : null); property.IsReference = ((attribute != null) ? attribute._isReference : null); property.ItemIsReference = ((attribute != null) ? attribute._itemIsReference : null); property.ItemConverter = ((attribute != null && attribute.ItemConverterType != null) ? JsonConverterAttribute.CreateJsonConverterInstance(attribute.ItemConverterType) : null); property.ItemReferenceLoopHandling = ((attribute != null) ? attribute._itemReferenceLoopHandling : null); property.ItemTypeNameHandling = ((attribute != null) ? attribute._itemTypeNameHandling : null); allowNonPublicAccess = false; if ((this.DefaultMembersSearchFlags & BindingFlags.NonPublic) == BindingFlags.NonPublic) { allowNonPublicAccess = true; } if (attribute != null) { allowNonPublicAccess = true; } if (memberSerialization == MemberSerialization.Fields) { allowNonPublicAccess = true; } if (dataMemberAttribute != null) { allowNonPublicAccess = true; property.HasMemberAttribute = true; } }
private void SetPropertySettingsFromAttributes(JsonProperty property, ICustomAttributeProvider attributeProvider, string name, Type declaringType, MemberSerialization memberSerialization, out bool allowNonPublicAccess, out bool hasExplicitAttribute) { hasExplicitAttribute = false; DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(declaringType); DataMemberAttribute dataMemberAttribute; if (dataContractAttribute != null && attributeProvider is MemberInfo) { dataMemberAttribute = JsonTypeReflector.GetDataMemberAttribute((MemberInfo)attributeProvider); } else { dataMemberAttribute = null; } JsonPropertyAttribute attribute = JsonTypeReflector.GetAttribute <JsonPropertyAttribute>(attributeProvider); if (attribute != null) { hasExplicitAttribute = true; } bool flag = JsonTypeReflector.GetAttribute <JsonIgnoreAttribute>(attributeProvider) != null; string propertyName; if (attribute != null && attribute.PropertyName != null) { propertyName = attribute.PropertyName; } else if (dataMemberAttribute != null && dataMemberAttribute.Name != null) { propertyName = dataMemberAttribute.Name; } else { propertyName = name; } property.PropertyName = this.ResolvePropertyName(propertyName); property.UnderlyingName = name; if (attribute != null) { property.Required = attribute.Required; property.Order = attribute._order; } else if (dataMemberAttribute != null) { property.Required = ((!dataMemberAttribute.IsRequired) ? Required.Default : Required.AllowNull); property.Order = ((dataMemberAttribute.Order == -1) ? null : new int?(dataMemberAttribute.Order)); } else { property.Required = Required.Default; } property.Ignored = (flag || (memberSerialization == MemberSerialization.OptIn && attribute == null && dataMemberAttribute == null)); property.Converter = JsonTypeReflector.GetJsonConverter(attributeProvider, property.PropertyType); property.MemberConverter = JsonTypeReflector.GetJsonConverter(attributeProvider, property.PropertyType); DefaultValueAttribute attribute2 = JsonTypeReflector.GetAttribute <DefaultValueAttribute>(attributeProvider); property.DefaultValue = ((attribute2 == null) ? null : attribute2.Value); property.NullValueHandling = ((attribute == null) ? null : attribute._nullValueHandling); property.DefaultValueHandling = ((attribute == null) ? null : attribute._defaultValueHandling); property.ReferenceLoopHandling = ((attribute == null) ? null : attribute._referenceLoopHandling); property.ObjectCreationHandling = ((attribute == null) ? null : attribute._objectCreationHandling); property.TypeNameHandling = ((attribute == null) ? null : attribute._typeNameHandling); property.IsReference = ((attribute == null) ? null : attribute._isReference); allowNonPublicAccess = false; if ((this.DefaultMembersSearchFlags & BindingFlags.NonPublic) == BindingFlags.NonPublic) { allowNonPublicAccess = true; } if (attribute != null) { allowNonPublicAccess = true; } if (dataMemberAttribute != null) { allowNonPublicAccess = true; hasExplicitAttribute = true; } }
private void SetPropertySettingsFromAttributes(JsonProperty property, ICustomAttributeProvider attributeProvider, string name, Type declaringType, MemberSerialization memberSerialization, out bool allowNonPublicAccess, out bool hasExplicitAttribute) { DataMemberAttribute dataMemberAttribute; string propertyName; bool flag; NullValueHandling? nullable; DefaultValueHandling? nullable1; ReferenceLoopHandling? nullable2; ObjectCreationHandling?nullable3; TypeNameHandling? nullable4; bool? nullable5; int?nullable6; hasExplicitAttribute = false; if (JsonTypeReflector.GetDataContractAttribute(declaringType) == null || !(attributeProvider is MemberInfo)) { dataMemberAttribute = null; } else { dataMemberAttribute = JsonTypeReflector.GetDataMemberAttribute((MemberInfo)attributeProvider); } JsonPropertyAttribute attribute = JsonTypeReflector.GetAttribute <JsonPropertyAttribute>(attributeProvider); if (attribute != null) { hasExplicitAttribute = true; } bool attribute1 = JsonTypeReflector.GetAttribute <JsonIgnoreAttribute>(attributeProvider) != null; if (attribute == null || attribute.PropertyName == null) { propertyName = (dataMemberAttribute == null || dataMemberAttribute.Name == null ? name : dataMemberAttribute.Name); } else { propertyName = attribute.PropertyName; } property.PropertyName = this.ResolvePropertyName(propertyName); property.UnderlyingName = name; if (attribute != null) { property.Required = attribute.Required; property.Order = attribute._order; } else if (dataMemberAttribute == null) { property.Required = Required.Default; } else { property.Required = (!dataMemberAttribute.IsRequired ? Required.Default : Required.AllowNull); JsonProperty jsonProperty = property; if (dataMemberAttribute.Order == -1) { nullable6 = null; } else { nullable6 = new int?(dataMemberAttribute.Order); } jsonProperty.Order = nullable6; } JsonProperty jsonProperty1 = property; if (attribute1) { flag = true; } else { flag = (memberSerialization != MemberSerialization.OptIn || attribute != null ? false : dataMemberAttribute == null); } jsonProperty1.Ignored = flag; property.Converter = JsonTypeReflector.GetJsonConverter(attributeProvider, property.PropertyType); property.MemberConverter = JsonTypeReflector.GetJsonConverter(attributeProvider, property.PropertyType); DefaultValueAttribute defaultValueAttribute = JsonTypeReflector.GetAttribute <DefaultValueAttribute>(attributeProvider); property.DefaultValue = (defaultValueAttribute == null ? null : defaultValueAttribute.Value); JsonProperty jsonProperty2 = property; if (attribute == null) { nullable = null; } else { nullable = attribute._nullValueHandling; } jsonProperty2.NullValueHandling = nullable; JsonProperty jsonProperty3 = property; if (attribute == null) { nullable1 = null; } else { nullable1 = attribute._defaultValueHandling; } jsonProperty3.DefaultValueHandling = nullable1; JsonProperty jsonProperty4 = property; if (attribute == null) { nullable2 = null; } else { nullable2 = attribute._referenceLoopHandling; } jsonProperty4.ReferenceLoopHandling = nullable2; JsonProperty jsonProperty5 = property; if (attribute == null) { nullable3 = null; } else { nullable3 = attribute._objectCreationHandling; } jsonProperty5.ObjectCreationHandling = nullable3; JsonProperty jsonProperty6 = property; if (attribute == null) { nullable4 = null; } else { nullable4 = attribute._typeNameHandling; } jsonProperty6.TypeNameHandling = nullable4; JsonProperty jsonProperty7 = property; if (attribute == null) { nullable5 = null; } else { nullable5 = attribute._isReference; } jsonProperty7.IsReference = nullable5; allowNonPublicAccess = false; if ((this.DefaultMembersSearchFlags & BindingFlags.NonPublic) == BindingFlags.NonPublic) { allowNonPublicAccess = true; } if (attribute != null) { allowNonPublicAccess = true; } if (dataMemberAttribute != null) { allowNonPublicAccess = true; hasExplicitAttribute = true; } }