<Compile Include="$(BclSourcesRoot)\System\Reflection\Associates.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\ConstructorInfo.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\CustomAttribute.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Reflection\CustomAttributeExtensions.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\Emit\AQNBuilder.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\Emit\AssemblyBuilder.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\Emit\AssemblyBuilderData.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\CallingConventions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ConstructorInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\CorElementType.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\CustomAttributeExtensions.cs" Condition="'$(TargetsCoreRT)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\CustomAttributeFormatException.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\CustomAttributeNamedArgument.cs" Condition="'$(TargetsCoreRT)' != 'true'" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\CustomAttributeTypedArgument.cs" Condition="'$(TargetsCoreRT)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\DefaultMemberAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\AssemblyBuilderAccess.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\EventToken.cs" />
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Reflection
+{
+ public readonly partial struct CustomAttributeNamedArgument
+ {
+ public static bool operator ==(CustomAttributeNamedArgument left, CustomAttributeNamedArgument right) => left.Equals(right);
+ public static bool operator !=(CustomAttributeNamedArgument left, CustomAttributeNamedArgument right) => !left.Equals(right);
+
+ private readonly MemberInfo m_memberInfo;
+ private readonly CustomAttributeTypedArgument m_value;
+
+ public CustomAttributeNamedArgument(MemberInfo memberInfo, object? value)
+ {
+ if (memberInfo == null)
+ throw new ArgumentNullException(nameof(memberInfo));
+
+ Type type;
+ if (memberInfo is FieldInfo field)
+ {
+ type = field.FieldType;
+ }
+ else if (memberInfo is PropertyInfo property)
+ {
+ type = property.PropertyType;
+ }
+ else
+ {
+ throw new ArgumentException(SR.Argument_InvalidMemberForNamedArgument);
+ }
+
+ m_memberInfo = memberInfo;
+ m_value = new CustomAttributeTypedArgument(type, value);
+ }
+
+ public CustomAttributeNamedArgument(MemberInfo memberInfo, CustomAttributeTypedArgument typedArgument)
+ {
+ if (memberInfo == null)
+ throw new ArgumentNullException(nameof(memberInfo));
+
+ m_memberInfo = memberInfo;
+ m_value = typedArgument;
+ }
+
+ public override string ToString()
+ {
+ if (m_memberInfo == null)
+ return base.ToString();
+
+ return string.Format("{0} = {1}", MemberInfo.Name, TypedValue.ToString(ArgumentType != typeof(object)));
+ }
+
+ public override int GetHashCode()
+ {
+ return base.GetHashCode();
+ }
+
+ public override bool Equals(object? obj)
+ {
+ return obj == (object)this;
+ }
+
+ internal Type ArgumentType
+ {
+ get
+ {
+ return m_memberInfo is FieldInfo ?
+ ((FieldInfo)m_memberInfo).FieldType :
+ ((PropertyInfo)m_memberInfo).PropertyType;
+ }
+ }
+
+ public MemberInfo MemberInfo => m_memberInfo;
+ public CustomAttributeTypedArgument TypedValue => m_value;
+ public string MemberName => MemberInfo.Name;
+ public bool IsField => MemberInfo is FieldInfo;
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Collections.Generic;
+
+namespace System.Reflection
+{
+ public readonly partial struct CustomAttributeTypedArgument
+ {
+ public static bool operator ==(CustomAttributeTypedArgument left, CustomAttributeTypedArgument right) => left.Equals(right);
+
+ public static bool operator !=(CustomAttributeTypedArgument left, CustomAttributeTypedArgument right) => !left.Equals(right);
+
+ private readonly object? m_value;
+ private readonly Type m_argumentType;
+
+ public CustomAttributeTypedArgument(Type argumentType, object? value)
+ {
+ // value can be null.
+ if (argumentType == null)
+ throw new ArgumentNullException(nameof(argumentType));
+
+ m_value = (value is null) ? null : CanonicalizeValue(value);
+ m_argumentType = argumentType;
+ }
+
+ public CustomAttributeTypedArgument(object value)
+ {
+ // value cannot be null.
+ if (value == null)
+ throw new ArgumentNullException(nameof(value));
+
+ m_value = CanonicalizeValue(value);
+ m_argumentType = value.GetType();
+ }
+
+
+ public override string ToString() => ToString(false);
+
+ internal string ToString(bool typed)
+ {
+ if (m_argumentType == null)
+ return base.ToString();
+
+ if (ArgumentType.IsEnum)
+ return string.Format(typed ? "{0}" : "({1}){0}", Value, ArgumentType.FullName);
+
+ else if (Value == null)
+ return string.Format(typed ? "null" : "({0})null", ArgumentType.Name);
+
+ else if (ArgumentType == typeof(string))
+ return string.Format("\"{0}\"", Value);
+
+ else if (ArgumentType == typeof(char))
+ return string.Format("'{0}'", Value);
+
+ else if (ArgumentType == typeof(Type))
+ return string.Format("typeof({0})", ((Type)Value!).FullName);
+
+ else if (ArgumentType.IsArray)
+ {
+ IList<CustomAttributeTypedArgument> array = (IList<CustomAttributeTypedArgument>)Value!;
+
+ Type elementType = ArgumentType.GetElementType()!;
+ string result = string.Format(@"new {0}[{1}] {{ ", elementType.IsEnum ? elementType.FullName : elementType.Name, array.Count);
+
+ for (int i = 0; i < array.Count; i++)
+ {
+ result += string.Format(i == 0 ? "{0}" : ", {0}", array[i].ToString(elementType != typeof(object)));
+ }
+
+ result += " }";
+
+ return result;
+ }
+
+ return string.Format(typed ? "{0}" : "({1}){0}", Value, ArgumentType.Name);
+ }
+
+ public override int GetHashCode() => base.GetHashCode();
+ public override bool Equals(object? obj) => obj == (object)this;
+
+ public Type ArgumentType => m_argumentType;
+ public object? Value => m_value;
+ }
+}
#endregion
}
- public readonly struct CustomAttributeNamedArgument
+ public readonly partial struct CustomAttributeTypedArgument
{
- public static bool operator ==(CustomAttributeNamedArgument left, CustomAttributeNamedArgument right) => left.Equals(right);
- public static bool operator !=(CustomAttributeNamedArgument left, CustomAttributeNamedArgument right) => !left.Equals(right);
-
- private readonly MemberInfo m_memberInfo;
- private readonly CustomAttributeTypedArgument m_value;
-
- #region Constructor
- public CustomAttributeNamedArgument(MemberInfo memberInfo, object? value)
- {
- if (memberInfo == null)
- throw new ArgumentNullException(nameof(memberInfo));
-
- Type type;
- if (memberInfo is FieldInfo field)
- {
- type = field.FieldType;
- }
- else if (memberInfo is PropertyInfo property)
- {
- type = property.PropertyType;
- }
- else
- {
- throw new ArgumentException(SR.Argument_InvalidMemberForNamedArgument);
- }
-
- m_memberInfo = memberInfo;
- m_value = new CustomAttributeTypedArgument(type, value);
- }
-
- public CustomAttributeNamedArgument(MemberInfo memberInfo, CustomAttributeTypedArgument typedArgument)
- {
- if (memberInfo == null)
- throw new ArgumentNullException(nameof(memberInfo));
-
- m_memberInfo = memberInfo;
- m_value = typedArgument;
- }
- #endregion
-
- #region Object Override
- public override string ToString()
- {
- if (m_memberInfo == null)
- return base.ToString();
-
- return string.Format("{0} = {1}", MemberInfo.Name, TypedValue.ToString(ArgumentType != typeof(object)));
- }
- public override int GetHashCode()
- {
- return base.GetHashCode();
- }
- public override bool Equals(object? obj)
- {
- return obj == (object)this;
- }
- #endregion
-
- #region Internal Members
- internal Type ArgumentType
- {
- get
- {
- return m_memberInfo is FieldInfo ?
- ((FieldInfo)m_memberInfo).FieldType :
- ((PropertyInfo)m_memberInfo).PropertyType;
- }
- }
- #endregion
-
- public MemberInfo MemberInfo => m_memberInfo;
- public CustomAttributeTypedArgument TypedValue => m_value;
- public string MemberName => MemberInfo.Name;
- public bool IsField => MemberInfo is FieldInfo;
- }
-
- public readonly struct CustomAttributeTypedArgument
- {
- public static bool operator ==(CustomAttributeTypedArgument left, CustomAttributeTypedArgument right) => left.Equals(right);
- public static bool operator !=(CustomAttributeTypedArgument left, CustomAttributeTypedArgument right) => !left.Equals(right);
-
#region Private Static Methods
private static Type CustomAttributeEncodingToType(CustomAttributeEncoding encodedType)
{
}
#endregion
- private readonly object? m_value;
- private readonly Type m_argumentType;
-
- #region Constructor
- public CustomAttributeTypedArgument(Type argumentType, object? value)
- {
- // value can be null.
- if (argumentType == null)
- throw new ArgumentNullException(nameof(argumentType));
-
- m_value = (value is null) ? null : CanonicalizeValue(value);
- m_argumentType = argumentType;
- }
-
- public CustomAttributeTypedArgument(object value)
- {
- // value cannot be null.
- if (value == null)
- throw new ArgumentNullException(nameof(value));
-
- m_value = CanonicalizeValue(value);
- m_argumentType = value.GetType();
- }
-
private static object CanonicalizeValue(object value)
{
Debug.Assert(value != null);
m_value = EncodedValueToRawValue(encodedArg.PrimitiveValue, encodedType);
}
}
- #endregion
-
- public override string ToString() => ToString(false);
-
- internal string ToString(bool typed)
- {
- if (m_argumentType == null)
- return base.ToString();
-
- if (ArgumentType.IsEnum)
- return string.Format(typed ? "{0}" : "({1}){0}", Value, ArgumentType.FullName);
-
- else if (Value == null)
- return string.Format(typed ? "null" : "({0})null", ArgumentType.Name);
-
- else if (ArgumentType == typeof(string))
- return string.Format("\"{0}\"", Value);
-
- else if (ArgumentType == typeof(char))
- return string.Format("'{0}'", Value);
-
- else if (ArgumentType == typeof(Type))
- return string.Format("typeof({0})", ((Type)Value!).FullName);
-
- else if (ArgumentType.IsArray)
- {
- IList<CustomAttributeTypedArgument> array = (IList<CustomAttributeTypedArgument>)Value!;
-
- Type elementType = ArgumentType.GetElementType()!;
- string result = string.Format(@"new {0}[{1}] {{ ", elementType.IsEnum ? elementType.FullName : elementType.Name, array.Count);
-
- for (int i = 0; i < array.Count; i++)
- {
- result += string.Format(i == 0 ? "{0}" : ", {0}", array[i].ToString(elementType != typeof(object)));
- }
-
- result += " }";
-
- return result;
- }
-
- return string.Format(typed ? "{0}" : "({1}){0}", Value, ArgumentType.Name);
- }
-
- public override int GetHashCode() => base.GetHashCode();
- public override bool Equals(object? obj) => obj == (object)this;
-
- public Type ArgumentType => m_argumentType;
- public object? Value => m_value;
}
[StructLayout(LayoutKind.Auto)]