blob: 6fd95eef833f71b26ac941e4a87ee8129e1854b6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
//-----------------------------------------------------------------------
// <copyright file="MessagePartAttribute.cs" company="Outercurve Foundation">
// Copyright (c) Outercurve Foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Messaging {
using System;
using System.Diagnostics;
using System.Net.Security;
using System.Reflection;
/// <summary>
/// Applied to fields and properties that form a key/value in a protocol message.
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = true, AllowMultiple = true)]
[DebuggerDisplay("MessagePartAttribute {Name}")]
public sealed class MessagePartAttribute : Attribute {
/// <summary>
/// The overridden name to use as the serialized name for the property.
/// </summary>
private string name;
/// <summary>
/// Initializes a new instance of the <see cref="MessagePartAttribute"/> class.
/// </summary>
public MessagePartAttribute() {
this.AllowEmpty = true;
this.MinVersionValue = new Version(0, 0);
this.MaxVersionValue = new Version(int.MaxValue, 0);
}
/// <summary>
/// Initializes a new instance of the <see cref="MessagePartAttribute"/> class.
/// </summary>
/// <param name="name">
/// 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.
/// </param>
public MessagePartAttribute(string name)
: this() {
this.Name = name;
}
/// <summary>
/// Gets the name of the serialized form of this member in the message.
/// </summary>
public string Name {
get { return this.name; }
private set { this.name = string.IsNullOrEmpty(value) ? null : value; }
}
/// <summary>
/// Gets or sets the level of protection required by this member in the serialized message.
/// </summary>
/// <remarks>
/// Message part protection must be provided and verified by the channel binding element(s)
/// that provide security.
/// </remarks>
public ProtectionLevel RequiredProtection { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this member is a required part of the serialized message.
/// </summary>
public bool IsRequired { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the string value is allowed to be empty in the serialized message.
/// </summary>
/// <value>Default is true.</value>
public bool AllowEmpty { get; set; }
/// <summary>
/// Gets or sets an IMessagePartEncoder custom encoder to use
/// to translate the applied member to and from a string.
/// </summary>
public Type Encoder { get; set; }
/// <summary>
/// Gets or sets the minimum version of the protocol this attribute applies to
/// and overrides any attributes with lower values for this property.
/// </summary>
/// <value>Defaults to 0.0.</value>
public string MinVersion {
get { return this.MinVersionValue.ToString(); }
set { this.MinVersionValue = new Version(value); }
}
/// <summary>
/// Gets or sets the maximum version of the protocol this attribute applies to.
/// </summary>
/// <value>Defaults to int.MaxValue for the major version number.</value>
/// <remarks>
/// Specifying <see cref="MinVersion"/> 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.
/// </remarks>
public string MaxVersion {
get { return this.MaxVersionValue.ToString(); }
set { this.MaxVersionValue = new Version(value); }
}
/// <summary>
/// Gets or sets the minimum version of the protocol this attribute applies to
/// and overrides any attributes with lower values for this property.
/// </summary>
/// <value>Defaults to 0.0.</value>
internal Version MinVersionValue { get; set; }
/// <summary>
/// Gets or sets the maximum version of the protocol this attribute applies to.
/// </summary>
/// <value>Defaults to int.MaxValue for the major version number.</value>
/// <remarks>
/// Specifying <see cref="MinVersion"/> 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.
/// </remarks>
internal Version MaxVersionValue { get; set; }
}
}
|