summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Reflection/CustomAttribute.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/src/System/Reflection/CustomAttribute.cs')
-rw-r--r--src/mscorlib/src/System/Reflection/CustomAttribute.cs166
1 files changed, 82 insertions, 84 deletions
diff --git a/src/mscorlib/src/System/Reflection/CustomAttribute.cs b/src/mscorlib/src/System/Reflection/CustomAttribute.cs
index b71c7bbff3..96eb45f3e4 100644
--- a/src/mscorlib/src/System/Reflection/CustomAttribute.cs
+++ b/src/mscorlib/src/System/Reflection/CustomAttribute.cs
@@ -18,7 +18,7 @@ using System.Runtime.ConstrainedExecution;
using System.Runtime.Versioning;
using System.Diagnostics.Contracts;
-namespace System.Reflection
+namespace System.Reflection
{
[Serializable]
public class CustomAttributeData
@@ -268,7 +268,7 @@ namespace System.Reflection
if (type.IsValueType)
return CustomAttributeEncoding.Undefined;
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidKindOfTypeForCA"), nameof(type));
+ throw new ArgumentException(SR.Argument_InvalidKindOfTypeForCA, nameof(type));
}
private static CustomAttributeType InitCustomAttributeType(RuntimeType parameterType)
{
@@ -300,8 +300,8 @@ namespace System.Reflection
customAttributes[i] = new CustomAttributeData(module, records[i]);
return Array.AsReadOnly(customAttributes);
- }
- #endregion
+ }
+ #endregion
#region Internal Static Members
internal unsafe static CustomAttributeRecord[] GetCustomAttributeRecords(RuntimeModule module, int targetToken)
@@ -361,7 +361,7 @@ namespace System.Reflection
m_scope = scope;
m_ctor = (RuntimeConstructorInfo)RuntimeType.GetMethodBase(scope, caRecord.tkCtor);
- ParameterInfo[] parameters = m_ctor.GetParametersNoCopy();
+ ParameterInfo[] parameters = m_ctor.GetParametersNoCopy();
m_ctorParams = new CustomAttributeCtorParameter[parameters.Length];
for (int i = 0; i < parameters.Length; i++)
m_ctorParams[i] = new CustomAttributeCtorParameter(InitCustomAttributeType((RuntimeType)parameters[i].ParameterType));
@@ -417,8 +417,7 @@ namespace System.Reflection
new CustomAttributeNamedArgument(type.GetField("CallingConvention"), dllImport.CallingConvention),
new CustomAttributeNamedArgument(type.GetField("BestFitMapping"), dllImport.BestFitMapping),
new CustomAttributeNamedArgument(type.GetField("ThrowOnUnmappableChar"), dllImport.ThrowOnUnmappableChar)
-
- });
+});
}
private void Init(FieldOffsetAttribute fieldOffset)
{
@@ -491,11 +490,11 @@ namespace System.Reflection
public override string ToString()
{
string ctorArgs = "";
- for (int i = 0; i < ConstructorArguments.Count; i ++)
+ for (int i = 0; i < ConstructorArguments.Count; i++)
ctorArgs += String.Format(CultureInfo.CurrentCulture, i == 0 ? "{0}" : ", {0}", ConstructorArguments[i]);
string namedArgs = "";
- for (int i = 0; i < NamedArguments.Count; i ++)
+ for (int i = 0; i < NamedArguments.Count; i++)
namedArgs += String.Format(CultureInfo.CurrentCulture, i == 0 && ctorArgs.Length == 0 ? "{0}" : ", {0}", NamedArguments[i]);
return String.Format(CultureInfo.CurrentCulture, "[{0}({1}{2})]", Constructor.DeclaringType.FullName, ctorArgs, namedArgs);
@@ -514,7 +513,7 @@ namespace System.Reflection
public Type AttributeType { get { return Constructor.DeclaringType; } }
public virtual ConstructorInfo Constructor { get { return m_ctor; } }
-
+
public virtual IList<CustomAttributeTypedArgument> ConstructorArguments
{
get
@@ -605,7 +604,7 @@ namespace System.Reflection
else if (property != null)
type = property.PropertyType;
else
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidMemberForNamedArgument"));
+ throw new ArgumentException(SR.Argument_InvalidMemberForNamedArgument);
m_memberInfo = memberInfo;
m_value = new CustomAttributeTypedArgument(type, value);
@@ -627,7 +626,7 @@ namespace System.Reflection
if (m_memberInfo == null)
return base.ToString();
- return String.Format(CultureInfo.CurrentCulture, "{0} = {1}", MemberInfo.Name, TypedValue.ToString(ArgumentType != typeof(object)));
+ return String.Format(CultureInfo.CurrentCulture, "{0} = {1}", MemberInfo.Name, TypedValue.ToString(ArgumentType != typeof(object)));
}
public override int GetHashCode()
{
@@ -640,14 +639,14 @@ namespace System.Reflection
#endregion
#region Internal Members
- internal Type ArgumentType
- {
- get
- {
- return m_memberInfo is FieldInfo ?
- ((FieldInfo)m_memberInfo).FieldType :
- ((PropertyInfo)m_memberInfo).PropertyType;
- }
+ internal Type ArgumentType
+ {
+ get
+ {
+ return m_memberInfo is FieldInfo ?
+ ((FieldInfo)m_memberInfo).FieldType :
+ ((PropertyInfo)m_memberInfo).PropertyType;
+ }
}
#endregion
@@ -730,8 +729,8 @@ namespace System.Reflection
case (CustomAttributeEncoding.Object):
return typeof(object);
- default :
- throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)encodedType), nameof(encodedType));
+ default:
+ throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, (int)encodedType), nameof(encodedType));
}
}
@@ -776,7 +775,7 @@ namespace System.Reflection
unsafe { return *(double*)&val; }
default:
- throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)val), nameof(val));
+ throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, (int)val), nameof(val));
}
}
private static RuntimeType ResolveType(RuntimeModule scope, string typeName)
@@ -785,7 +784,7 @@ namespace System.Reflection
if (type == null)
throw new InvalidOperationException(
- String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Arg_CATypeResolutionFailed"), typeName));
+ String.Format(CultureInfo.CurrentUICulture, SR.Arg_CATypeResolutionFailed, typeName));
return type;
}
@@ -848,17 +847,17 @@ namespace System.Reflection
else if (encodedType == CustomAttributeEncoding.Type)
{
m_argumentType = typeof(Type);
-
+
m_value = null;
if (encodedArg.StringValue != null)
m_value = ResolveType(scope, encodedArg.StringValue);
}
else if (encodedType == CustomAttributeEncoding.Array)
- {
+ {
encodedType = encodedArg.CustomAttributeType.EncodedArrayType;
Type elementType;
-
+
if (encodedType == CustomAttributeEncoding.Enum)
{
elementType = ResolveType(scope, encodedArg.CustomAttributeType.EnumName);
@@ -869,10 +868,10 @@ namespace System.Reflection
}
m_argumentType = elementType.MakeArrayType();
-
+
if (encodedArg.ArrayValue == null)
{
- m_value = null;
+ m_value = null;
}
else
{
@@ -949,12 +948,12 @@ namespace System.Reflection
return m_argumentType;
}
}
- public object Value
- {
- get
+ public object Value
+ {
+ get
{
return m_value;
- }
+ }
}
#endregion
}
@@ -994,17 +993,17 @@ namespace System.Reflection
[Serializable]
[StructLayout(LayoutKind.Auto)]
internal struct CustomAttributeEncodedArgument
- {
+ {
#region Parser
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void ParseAttributeArguments(
- IntPtr pCa,
- int cCa,
+ IntPtr pCa,
+ int cCa,
ref CustomAttributeCtorParameter[] CustomAttributeCtorParameters,
ref CustomAttributeNamedParameter[] CustomAttributeTypedArgument,
RuntimeAssembly assembly);
- internal static void ParseAttributeArguments(ConstArray attributeBlob,
+ internal static void ParseAttributeArguments(ConstArray attributeBlob,
ref CustomAttributeCtorParameter[] customAttributeCtorParameters,
ref CustomAttributeNamedParameter[] customAttributeNamedParameters,
RuntimeModule customAttributeModule)
@@ -1045,7 +1044,7 @@ namespace System.Reflection
public string StringValue { get { return m_stringValue; } }
#endregion
}
-
+
[Serializable]
[StructLayout(LayoutKind.Auto)]
internal struct CustomAttributeNamedParameter
@@ -1077,7 +1076,7 @@ namespace System.Reflection
public CustomAttributeEncodedArgument EncodedArgument { get { return m_encodedArgument; } }
#endregion
}
-
+
[Serializable]
[StructLayout(LayoutKind.Auto)]
internal struct CustomAttributeCtorParameter
@@ -1110,18 +1109,18 @@ namespace System.Reflection
private CustomAttributeEncoding m_encodedType; // ...array
private CustomAttributeEncoding m_encodedEnumType; // ...enum
private CustomAttributeEncoding m_encodedArrayType; // ...enum type
- private CustomAttributeEncoding m_padding;
+ private CustomAttributeEncoding m_padding;
#endregion
#region Constructor
- public CustomAttributeType(CustomAttributeEncoding encodedType, CustomAttributeEncoding encodedArrayType,
+ public CustomAttributeType(CustomAttributeEncoding encodedType, CustomAttributeEncoding encodedArrayType,
CustomAttributeEncoding encodedEnumType, string enumName)
{
m_encodedType = encodedType;
m_encodedArrayType = encodedArrayType;
m_encodedEnumType = encodedEnumType;
m_enumName = enumName;
- m_padding = m_encodedType;
+ m_padding = m_encodedType;
}
#endregion
@@ -1145,7 +1144,7 @@ namespace System.Reflection
{
Contract.Requires(type != null);
- if (type.GetElementType() != null)
+ if (type.GetElementType() != null)
return false;
if (PseudoCustomAttribute.IsDefined(type, caType))
@@ -1252,7 +1251,7 @@ namespace System.Reflection
return IsCustomAttributeDefined(parameter.GetRuntimeModule(), parameter.MetadataToken, caType);
}
- internal static bool IsDefined(RuntimeAssembly assembly, RuntimeType caType)
+ internal static bool IsDefined(RuntimeAssembly assembly, RuntimeType caType)
{
Contract.Requires(assembly != null);
Contract.Requires(caType != null);
@@ -1279,8 +1278,8 @@ namespace System.Reflection
Contract.Requires(type != null);
Contract.Requires(caType != null);
- if (type.GetElementType() != null)
- return (caType.IsValueType) ? EmptyArray<Object>.Value : CreateAttributeArrayHelper(caType, 0);
+ if (type.GetElementType() != null)
+ return (caType.IsValueType) ? Array.Empty<Object>() : CreateAttributeArrayHelper(caType, 0);
if (type.IsGenericType && !type.IsGenericTypeDefinition)
type = type.GetGenericTypeDefinition() as RuntimeType;
@@ -1323,7 +1322,7 @@ namespace System.Reflection
private static bool AllowCriticalCustomAttributes(RuntimeType type)
{
- if (type.IsGenericParameter)
+ if (type.IsGenericParameter)
{
// Generic parameters don't have transparency state, so look at the
// declaring method/type. One of declaringMethod or declaringType
@@ -1331,7 +1330,7 @@ namespace System.Reflection
MethodBase declaringMethod = type.DeclaringMethod;
if (declaringMethod != null)
{
- return AllowCriticalCustomAttributes(declaringMethod);
+ return AllowCriticalCustomAttributes(declaringMethod);
}
else
{
@@ -1394,9 +1393,9 @@ namespace System.Reflection
bool useObjectArray = (caType == null || caType.IsValueType || caType.ContainsGenericParameters);
Type arrayType = useObjectArray ? typeof(object) : caType;
- while (pcaCount > 0)
+ while (pcaCount > 0)
result.Add(pca[--pcaCount]);
-
+
while (method != null)
{
object[] attributes = GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, 0, caType, mustBeInheritable, result, !AllowCriticalCustomAttributes(method));
@@ -1478,12 +1477,12 @@ namespace System.Reflection
int pcaCount = 0;
Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(parameter, caType, out pcaCount);
- object[] attributes = GetCustomAttributes(parameter.GetRuntimeModule(), parameter.MetadataToken, pcaCount, caType, !AllowCriticalCustomAttributes(parameter));
+ object[] attributes = GetCustomAttributes(parameter.GetRuntimeModule(), parameter.MetadataToken, pcaCount, caType, !AllowCriticalCustomAttributes(parameter));
if (pcaCount > 0) Array.Copy(pca, 0, attributes, attributes.Length - pcaCount, pcaCount);
return attributes;
}
- internal static Object[] GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
+ internal static Object[] GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
{
Contract.Requires(assembly != null);
Contract.Requires(caType != null);
@@ -1497,7 +1496,7 @@ namespace System.Reflection
return attributes;
}
- internal static Object[] GetCustomAttributes(RuntimeModule module, RuntimeType caType)
+ internal static Object[] GetCustomAttributes(RuntimeModule module, RuntimeType caType)
{
Contract.Requires(module != null);
Contract.Requires(caType != null);
@@ -1525,7 +1524,7 @@ namespace System.Reflection
RuntimeModule decoratedModule, int decoratedMetadataToken, RuntimeType attributeFilterType, int attributeCtorToken, bool mustBeInheritable)
{
if (decoratedModule.Assembly.ReflectionOnly)
- throw new InvalidOperationException(Environment.GetResourceString("Arg_ReflectionOnlyCA"));
+ throw new InvalidOperationException(SR.Arg_ReflectionOnlyCA);
Contract.EndContractBlock();
CustomAttributeRecord[] car = CustomAttributeData.GetCustomAttributeRecords(decoratedModule, decoratedMetadataToken);
@@ -1577,11 +1576,11 @@ namespace System.Reflection
}
private unsafe static object[] GetCustomAttributes(
- RuntimeModule decoratedModule, int decoratedMetadataToken, int pcaCount,
+ RuntimeModule decoratedModule, int decoratedMetadataToken, int pcaCount,
RuntimeType attributeFilterType, bool mustBeInheritable, IList derivedAttributes, bool isDecoratedTargetSecurityTransparent)
{
if (decoratedModule.Assembly.ReflectionOnly)
- throw new InvalidOperationException(Environment.GetResourceString("Arg_ReflectionOnlyCA"));
+ throw new InvalidOperationException(SR.Arg_ReflectionOnlyCA);
Contract.EndContractBlock();
MetadataImport scope = decoratedModule.MetadataImport;
@@ -1614,8 +1613,8 @@ namespace System.Reflection
IntPtr blobEnd = (IntPtr)((byte*)blobStart + caRecord.blob.Length);
int blobLen = (int)((byte*)blobEnd - (byte*)blobStart);
- if (!FilterCustomAttributeRecord(caRecord, scope, ref lastAptcaOkAssembly,
- decoratedModule, decoratedMetadataToken, attributeFilterType, mustBeInheritable,
+ if (!FilterCustomAttributeRecord(caRecord, scope, ref lastAptcaOkAssembly,
+ decoratedModule, decoratedMetadataToken, attributeFilterType, mustBeInheritable,
attributes, derivedAttributes,
out attributeType, out ctor, out ctorHasParameters, out isVarArg))
continue;
@@ -1628,16 +1627,15 @@ namespace System.Reflection
}
else
{
-
}
// Leverage RuntimeConstructorInfo standard .ctor verfication
- RuntimeConstructorInfo.CheckCanCreateInstance(attributeType, isVarArg);
+ RuntimeConstructorInfo.CheckCanCreateInstance(attributeType, isVarArg);
// Create custom attribute object
if (ctorHasParameters)
{
- attribute = CreateCaObject(decoratedModule, ctor, ref blobStart, blobEnd, out cNamedArgs);
+ attribute = CreateCaObject(decoratedModule, ctor, ref blobStart, blobEnd, out cNamedArgs);
}
else
{
@@ -1674,7 +1672,7 @@ namespace System.Reflection
bool isProperty;
RuntimeType type;
object value;
-
+
IntPtr blobItr = caRecord.blob.Signature;
GetPropertyOrFieldData(decoratedModule, ref blobStart, blobEnd, out name, out isProperty, out type, out value);
@@ -1702,12 +1700,12 @@ namespace System.Reflection
if (property == null)
{
throw new CustomAttributeFormatException(
- String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString(
- isProperty ? "RFLCT.InvalidPropFail" : "RFLCT.InvalidFieldFail"), name));
+ String.Format(CultureInfo.CurrentUICulture,
+ isProperty ? SR.RFLCT_InvalidPropFail : SR.RFLCT_InvalidFieldFail, name));
}
RuntimeMethodInfo setMethod = property.GetSetMethod(true) as RuntimeMethodInfo;
-
+
// Public properties may have non-public setter methods
if (!setMethod.IsPublic)
continue;
@@ -1733,8 +1731,8 @@ namespace System.Reflection
catch (Exception e)
{
throw new CustomAttributeFormatException(
- String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString(
- isProperty ? "RFLCT.InvalidPropFail" : "RFLCT.InvalidFieldFail"), name), e);
+ String.Format(CultureInfo.CurrentUICulture,
+ isProperty ? SR.RFLCT_InvalidPropFail : SR.RFLCT_InvalidFieldFail, name), e);
}
#endregion
}
@@ -1756,7 +1754,7 @@ namespace System.Reflection
private unsafe static bool FilterCustomAttributeRecord(
CustomAttributeRecord caRecord,
MetadataImport scope,
- ref Assembly lastAptcaOkAssembly,
+ ref Assembly lastAptcaOkAssembly,
RuntimeModule decoratedModule,
MetadataToken decoratedToken,
RuntimeType attributeFilterType,
@@ -1772,7 +1770,7 @@ namespace System.Reflection
attributeType = null;
ctorHasParameters = false;
isVarArg = false;
-
+
IntPtr blobStart = caRecord.blob.Signature;
IntPtr blobEnd = (IntPtr)((byte*)blobStart + caRecord.blob.Length);
@@ -1817,13 +1815,13 @@ namespace System.Reflection
// Visibility checks
MetadataToken tkParent = new MetadataToken();
-
+
if (decoratedToken.IsParamDef)
{
tkParent = new MetadataToken(scope.GetParentToken(decoratedToken));
tkParent = new MetadataToken(scope.GetParentToken(tkParent));
- }
- else if (decoratedToken.IsMethodDef || decoratedToken.IsProperty || decoratedToken.IsEvent || decoratedToken.IsFieldDef)
+ }
+ else if (decoratedToken.IsMethodDef || decoratedToken.IsProperty || decoratedToken.IsEvent || decoratedToken.IsFieldDef)
{
tkParent = new MetadataToken(scope.GetParentToken(decoratedToken));
}
@@ -1842,7 +1840,7 @@ namespace System.Reflection
else
{
// We need to relax this when we add support for other types of decorated tokens.
- Debug.Assert(decoratedToken.IsModule || decoratedToken.IsAssembly,
+ Debug.Assert(decoratedToken.IsModule || decoratedToken.IsAssembly,
"The decoratedToken must be either an assembly, a module, a type, or a member.");
}
@@ -1907,7 +1905,7 @@ namespace System.Reflection
if (attributeUsageAttribute != null)
throw new FormatException(String.Format(
- CultureInfo.CurrentUICulture, Environment.GetResourceString("Format_AttributeUsage"), attributeType));
+ CultureInfo.CurrentUICulture, SR.Format_AttributeUsage, attributeType));
AttributeTargets targets;
bool inherited, allowMultiple;
@@ -1940,7 +1938,7 @@ namespace System.Reflection
{
byte* pBlob = (byte*)blob;
byte* pBlobEnd = (byte*)blobEnd;
- int cNamedArgs;
+ int cNamedArgs;
object ca = _CreateCaObject(module, ctor, &pBlob, pBlobEnd, &cNamedArgs);
blob = (IntPtr)pBlob;
namedArgs = cNamedArgs;
@@ -2025,9 +2023,9 @@ namespace System.Reflection
//AllowMultiple is true for TypeForwardedToAttribute
//Debug.Assert(usage.AllowMultiple == false, "Pseudo CA Error");
}
-#endregion
+ #endregion
-#region Internal Static
+ #region Internal Static
internal static bool IsSecurityAttribute(RuntimeType type)
{
// TODO: Cleanup
@@ -2083,12 +2081,12 @@ namespace System.Reflection
if (!all && s_pca.GetValueOrDefault(caType) == null && !IsSecurityAttribute(caType))
return false;
- if (all || caType == (RuntimeType)typeof(SerializableAttribute))
- {
+ if (all || caType == (RuntimeType)typeof(SerializableAttribute))
+ {
if (SerializableAttribute.IsDefined(type)) return true;
}
- if (all || caType == (RuntimeType)typeof(ComImportAttribute))
- {
+ if (all || caType == (RuntimeType)typeof(ComImportAttribute))
+ {
if (ComImportAttribute.IsDefined(type)) return true;
}
if (all || IsSecurityAttribute(caType))
@@ -2322,8 +2320,8 @@ namespace System.Reflection
{
if (FieldOffsetAttribute.IsDefined(field)) return true;
}
- if (all || caType == (RuntimeType)typeof(NonSerializedAttribute))
- {
+ if (all || caType == (RuntimeType)typeof(NonSerializedAttribute))
+ {
if (NonSerializedAttribute.IsDefined(field)) return true;
}
@@ -2392,6 +2390,6 @@ namespace System.Reflection
{
return false;
}
-#endregion
+ #endregion
}
}