//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Messaging {
using System;
using System.Diagnostics;
using System.Net.Security;
using System.Reflection;
///
/// Applied to fields and properties that form a key/value in a protocol message.
///
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = true, AllowMultiple = true)]
[DebuggerDisplay("MessagePartAttribute {Name}")]
public sealed class MessagePartAttribute : Attribute {
///
/// The overridden name to use as the serialized name for the property.
///
private string name;
///
/// Initializes a new instance of the class.
///
public MessagePartAttribute() {
this.AllowEmpty = true;
this.MinVersionValue = new Version(0, 0);
this.MaxVersionValue = new Version(int.MaxValue, 0);
}
///
/// Initializes a new instance of the class.
///
///
/// A special name to give the value of this member in the serialized message.
/// When null or empty, the name of the member will be used in the serialized message.
///
public MessagePartAttribute(string name)
: this() {
this.Name = name;
}
///
/// Gets the name of the serialized form of this member in the message.
///
public string Name {
get { return this.name; }
private set { this.name = string.IsNullOrEmpty(value) ? null : value; }
}
///
/// Gets or sets the level of protection required by this member in the serialized message.
///
///
/// Message part protection must be provided and verified by the channel binding element(s)
/// that provide security.
///
public ProtectionLevel RequiredProtection { get; set; }
///
/// Gets or sets a value indicating whether this member is a required part of the serialized message.
///
public bool IsRequired { get; set; }
///
/// Gets or sets a value indicating whether the string value is allowed to be empty in the serialized message.
///
/// Default is true.
public bool AllowEmpty { get; set; }
///
/// Gets or sets an IMessagePartEncoder custom encoder to use
/// to translate the applied member to and from a string.
///
public Type Encoder { get; set; }
///
/// Gets or sets the minimum version of the protocol this attribute applies to
/// and overrides any attributes with lower values for this property.
///
/// Defaults to 0.0.
public string MinVersion {
get { return this.MinVersionValue.ToString(); }
set { this.MinVersionValue = new Version(value); }
}
///
/// Gets or sets the maximum version of the protocol this attribute applies to.
///
/// Defaults to int.MaxValue for the major version number.
///
/// Specifying on another attribute on the same member
/// automatically turns this attribute off. This property should only be set when
/// a property is totally dropped from a newer version of the protocol.
///
public string MaxVersion {
get { return this.MaxVersionValue.ToString(); }
set { this.MaxVersionValue = new Version(value); }
}
///
/// Gets or sets a value indicating whether the value contained by this property contains
/// sensitive information that should generally not be logged.
///
///
/// true if this instance is security sensitive; otherwise, false.
///
public bool IsSecuritySensitive { get; set; }
///
/// Gets or sets the minimum version of the protocol this attribute applies to
/// and overrides any attributes with lower values for this property.
///
/// Defaults to 0.0.
internal Version MinVersionValue { get; set; }
///
/// Gets or sets the maximum version of the protocol this attribute applies to.
///
/// Defaults to int.MaxValue for the major version number.
///
/// Specifying on another attribute on the same member
/// automatically turns this attribute off. This property should only be set when
/// a property is totally dropped from a newer version of the protocol.
///
internal Version MaxVersionValue { get; set; }
}
}