using System; namespace Newtonsoft.Json { /// /// Instructs the to always serialize the member with the specified name. /// [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)] public sealed class JsonPropertyAttribute : Attribute { // yuck. can't set nullable properties on an attribute in C# // have to use this approach to get an unset default state internal NullValueHandling? _nullValueHandling; internal DefaultValueHandling? _defaultValueHandling; internal ReferenceLoopHandling? _referenceLoopHandling; internal ObjectCreationHandling? _objectCreationHandling; internal TypeNameHandling? _typeNameHandling; internal bool? _isReference; /// /// Gets or sets the null value handling used when serializing this property. /// /// The null value handling. public NullValueHandling NullValueHandling { get { return _nullValueHandling ?? default(NullValueHandling); } set { _nullValueHandling = value; } } /// /// Gets or sets the default value handling used when serializing this property. /// /// The default value handling. public DefaultValueHandling DefaultValueHandling { get { return _defaultValueHandling ?? default(DefaultValueHandling); } set { _defaultValueHandling = value; } } /// /// Gets or sets the reference loop handling used when serializing this property. /// /// The reference loop handling. public ReferenceLoopHandling ReferenceLoopHandling { get { return _referenceLoopHandling ?? default(ReferenceLoopHandling); } set { _referenceLoopHandling = value; } } /// /// Gets or sets the object creation handling used when deserializing this property. /// /// The object creation handling. public ObjectCreationHandling ObjectCreationHandling { get { return _objectCreationHandling ?? default(ObjectCreationHandling); } set { _objectCreationHandling = value; } } /// /// Gets or sets the type name handling used when serializing this property. /// /// The type name handling. public TypeNameHandling TypeNameHandling { get { return _typeNameHandling ?? default(TypeNameHandling); } set { _typeNameHandling = value; } } /// /// Gets or sets whether this property's value is serialized as a reference. /// /// Whether this property's value is serialized as a reference. public bool IsReference { get { return _isReference ?? default(bool); } set { _isReference = value; } } /// /// Gets or sets the name of the property. /// /// The name of the property. public string PropertyName { get; set; } /// /// Gets or sets a value indicating whether this property is required. /// /// /// A value indicating whether this property is required. /// public Required Required { get; set; } /// /// Initializes a new instance of the class. /// public JsonPropertyAttribute() { } /// /// Initializes a new instance of the class with the specified name. /// /// Name of the property. public JsonPropertyAttribute(string propertyName) { PropertyName = propertyName; } } }