mscorlib(4.0.0.0) API with additions
CustomAttributeNamedArgument.cs
3 
4 namespace System.Reflection
5 {
8  [ComVisible(true)]
9  [__DynamicallyInvokable]
11  {
12  private MemberInfo m_memberInfo;
13 
14  private CustomAttributeTypedArgument m_value;
15 
16  internal Type ArgumentType
17  {
18  get
19  {
20  if (!(m_memberInfo is FieldInfo))
21  {
22  return ((PropertyInfo)m_memberInfo).PropertyType;
23  }
24  return ((FieldInfo)m_memberInfo).FieldType;
25  }
26  }
27 
30  public MemberInfo MemberInfo => m_memberInfo;
31 
34  [__DynamicallyInvokable]
36  {
37  [__DynamicallyInvokable]
38  get
39  {
40  return m_value;
41  }
42  }
43 
46  [__DynamicallyInvokable]
47  public string MemberName
48  {
49  [__DynamicallyInvokable]
50  get
51  {
52  return MemberInfo.Name;
53  }
54  }
55 
59  [__DynamicallyInvokable]
60  public bool IsField
61  {
62  [__DynamicallyInvokable]
63  get
64  {
65  return MemberInfo is FieldInfo;
66  }
67  }
68 
75  {
76  return left.Equals(right);
77  }
78 
85  {
86  return !left.Equals(right);
87  }
88 
96  public CustomAttributeNamedArgument(MemberInfo memberInfo, object value)
97  {
98  if (memberInfo == null)
99  {
100  throw new ArgumentNullException("memberInfo");
101  }
102  Type type = null;
103  FieldInfo fieldInfo = memberInfo as FieldInfo;
104  PropertyInfo propertyInfo = memberInfo as PropertyInfo;
105  if (fieldInfo != null)
106  {
107  type = fieldInfo.FieldType;
108  }
109  else
110  {
111  if (!(propertyInfo != null))
112  {
113  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidMemberForNamedArgument"));
114  }
115  type = propertyInfo.PropertyType;
116  }
117  m_memberInfo = memberInfo;
118  m_value = new CustomAttributeTypedArgument(type, value);
119  }
120 
127  {
128  if (memberInfo == null)
129  {
130  throw new ArgumentNullException("memberInfo");
131  }
132  m_memberInfo = memberInfo;
133  m_value = typedArgument;
134  }
135 
138  public override string ToString()
139  {
140  if (m_memberInfo == null)
141  {
142  return ((ValueType)this).ToString();
143  }
144  return string.Format(CultureInfo.CurrentCulture, "{0} = {1}", MemberInfo.Name, TypedValue.ToString(ArgumentType != typeof(object)));
145  }
146 
149  public override int GetHashCode()
150  {
151  return ((ValueType)this).GetHashCode();
152  }
153 
158  public override bool Equals(object obj)
159  {
160  return obj == (object)this;
161  }
162  }
163 }
Obtains information about the attributes of a member and provides access to member metadata.
Definition: MemberInfo.cs:14
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
abstract Type FieldType
Gets the type of this field object.
Definition: FieldInfo.cs:34
Represents a named argument of a custom attribute in the reflection-only context.
CustomAttributeNamedArgument(MemberInfo memberInfo, CustomAttributeTypedArgument typedArgument)
Initializes a new instance of the T:System.Reflection.CustomAttributeNamedArgument class,...
Discovers the attributes of a field and provides access to field metadata.
Definition: FieldInfo.cs:15
Definition: __Canon.cs:3
bool IsField
Gets a value that indicates whether the named argument is a field.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
static bool operator==(CustomAttributeNamedArgument left, CustomAttributeNamedArgument right)
Tests whether two T:System.Reflection.CustomAttributeNamedArgument structures are equivalent.
static bool operator !=(CustomAttributeNamedArgument left, CustomAttributeNamedArgument right)
Tests whether two T:System.Reflection.CustomAttributeNamedArgument structures are different.
Represents an argument of a custom attribute in the reflection-only context, or an element of an arra...
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
abstract string Name
Gets the name of the current member.
Definition: MemberInfo.cs:27
abstract Type PropertyType
Gets the type of this property.
Definition: PropertyInfo.cs:25
Discovers the attributes of a property and provides access to property metadata.
Definition: PropertyInfo.cs:15
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
Definition: CultureInfo.cs:120
The exception that is thrown when one of the arguments provided to a method is not valid.
override string ToString()
Returns a string consisting of the argument name, the equal sign, and a string representation of the ...
override int GetHashCode()
Returns the hash code for this instance.
CustomAttributeTypedArgument TypedValue
Gets a T:System.Reflection.CustomAttributeTypedArgument structure that can be used to obtain the type...
Specifies that the class can be serialized.
CustomAttributeNamedArgument(MemberInfo memberInfo, object value)
Initializes a new instance of the T:System.Reflection.CustomAttributeNamedArgument class,...
override bool Equals(object obj)
Returns a value that indicates whether this instance is equal to a specified object.
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
override string ToString()
Returns a string that consists of the argument name, the equal sign, and a string representation of t...
Provides the base class for value types.
Definition: ValueType.cs:12
string MemberName
Gets the name of the attribute member that would be used to set the named argument.