diff options
author | Atsushi Kanamori <AtsushiKan@users.noreply.github.com> | 2017-09-06 16:49:26 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-06 16:49:26 +0300 |
commit | 2c837b6021577ad5779b047be6a27cb33e3e6da2 (patch) | |
tree | b5719c84f79d8add725432c185746cb291d40480 /src/System.Private.Reflection.Core | |
parent | d79385c674fa829725b2d435478a61ef058a9e56 (diff) |
Unify pseudo-attribute code between NativeFormat and Ecma (#4456)
This was following the old layering rules - resulting
in pointless duplication of logic between Native
and Ecma.
As a bonus, this also fixes an edge-case bug.
PreserveSigAttribute is not valid on constructors
and isn't synthesized by the full framework even
if you force that bit on. Project N now matches
that behavior.
Diffstat (limited to 'src/System.Private.Reflection.Core')
22 files changed, 105 insertions, 196 deletions
diff --git a/src/System.Private.Reflection.Core/src/Internal/Reflection/Core/Execution/ExecutionDomain.cs b/src/System.Private.Reflection.Core/src/Internal/Reflection/Core/Execution/ExecutionDomain.cs index 17ad69dc1..2f1657ed8 100644 --- a/src/System.Private.Reflection.Core/src/Internal/Reflection/Core/Execution/ExecutionDomain.cs +++ b/src/System.Private.Reflection.Core/src/Internal/Reflection/Core/Execution/ExecutionDomain.cs @@ -175,17 +175,6 @@ namespace Internal.Reflection.Core.Execution } } - // - // Get or create a CustomAttributeData object for a specific type and arguments. - // - public CustomAttributeData GetCustomAttributeData(Type attributeType, IList<CustomAttributeTypedArgument> constructorArguments, IList<CustomAttributeNamedArgument> namedArguments) - { - if (!attributeType.IsRuntimeImplemented()) - throw new InvalidOperationException(); - RuntimeTypeInfo runtimeAttributeType = attributeType.CastToRuntimeTypeInfo(); - return new RuntimePseudoCustomAttributeData(runtimeAttributeType, constructorArguments, namedArguments); - } - //======================================================================================= // This group of methods jointly service the Type.GetTypeFromHandle() path. The caller // is responsible for analyzing the RuntimeTypeHandle to figure out which flavor to call. diff --git a/src/System.Private.Reflection.Core/src/Internal/Reflection/Core/Execution/ExecutionEnvironment.cs b/src/System.Private.Reflection.Core/src/Internal/Reflection/Core/Execution/ExecutionEnvironment.cs index 5d8699ce3..71e8080a2 100644 --- a/src/System.Private.Reflection.Core/src/Internal/Reflection/Core/Execution/ExecutionEnvironment.cs +++ b/src/System.Private.Reflection.Core/src/Internal/Reflection/Core/Execution/ExecutionEnvironment.cs @@ -72,17 +72,6 @@ namespace Internal.Reflection.Core.Execution public abstract FieldAccessor TryGetFieldAccessor(MetadataReader reader, RuntimeTypeHandle declaringTypeHandle, RuntimeTypeHandle fieldTypeHandle, FieldHandle fieldHandle); //============================================================================================== - // Pseudo Custom Attributes - //============================================================================================== - public abstract IEnumerable<CustomAttributeData> GetPseudoCustomAttributes(MetadataReader reader, ScopeDefinitionHandle scopeDefinitionHandle); - public abstract IEnumerable<CustomAttributeData> GetPseudoCustomAttributes(MetadataReader reader, TypeDefinitionHandle typeDefinitionHandle); - public abstract IEnumerable<CustomAttributeData> GetPseudoCustomAttributes(MetadataReader reader, MethodHandle methodHandle, TypeDefinitionHandle declaringTypeHandle); - public abstract IEnumerable<CustomAttributeData> GetPseudoCustomAttributes(MetadataReader reader, ParameterHandle parameterHandle, MethodHandle declaringMethodHandle); - public abstract IEnumerable<CustomAttributeData> GetPseudoCustomAttributes(MetadataReader reader, FieldHandle fieldHandle, TypeDefinitionHandle declaringTypeHandle); - public abstract IEnumerable<CustomAttributeData> GetPseudoCustomAttributes(MetadataReader reader, PropertyHandle propertyHandle, TypeDefinitionHandle declaringTypeHandle); - public abstract IEnumerable<CustomAttributeData> GetPseudoCustomAttributes(MetadataReader reader, EventHandle eventHandle, TypeDefinitionHandle declaringTypeHandle); - - //============================================================================================== // RuntimeMethodHandle and RuntimeFieldHandle support. //============================================================================================== public abstract bool TryGetMethodFromHandle(RuntimeMethodHandle runtimeMethodHandle, out RuntimeTypeHandle declaringTypeHandle, out QMethodDefinition methodHandle, out RuntimeTypeHandle[] genericMethodTypeArgumentHandles); diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/Assemblies/NativeFormat/NativeFormatRuntimeAssembly.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/Assemblies/NativeFormat/NativeFormatRuntimeAssembly.cs index 317e44ebe..e3d7e2ec7 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/Assemblies/NativeFormat/NativeFormatRuntimeAssembly.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/Assemblies/NativeFormat/NativeFormatRuntimeAssembly.cs @@ -46,9 +46,6 @@ namespace System.Reflection.Runtime.Assemblies.NativeFormat { foreach (CustomAttributeData cad in RuntimeCustomAttributeData.GetCustomAttributes(scope.Reader, scope.ScopeDefinition.CustomAttributes)) yield return cad; - - foreach (CustomAttributeData cad in ReflectionCoreExecution.ExecutionEnvironment.GetPseudoCustomAttributes(scope.Reader, scope.Handle)) - yield return cad; } } } diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/CustomAttributes/RuntimePseudoCustomAttributeData.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/CustomAttributes/RuntimePseudoCustomAttributeData.cs index bc6bfb41a..6734900d7 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/CustomAttributes/RuntimePseudoCustomAttributeData.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/CustomAttributes/RuntimePseudoCustomAttributeData.cs @@ -17,7 +17,7 @@ namespace System.Reflection.Runtime.CustomAttributes // internal sealed class RuntimePseudoCustomAttributeData : RuntimeCustomAttributeData { - public RuntimePseudoCustomAttributeData(RuntimeTypeInfo attributeType, IList<CustomAttributeTypedArgument> constructorArguments, IList<CustomAttributeNamedArgument> namedArguments) + public RuntimePseudoCustomAttributeData(Type attributeType, IList<CustomAttributeTypedArgument> constructorArguments, IList<CustomAttributeNamedArgument> namedArguments) { _attributeType = attributeType; if (constructorArguments == null) @@ -74,7 +74,7 @@ namespace System.Reflection.Runtime.CustomAttributes // Equals/GetHashCode no need to override (they just implement reference equality but desktop never unified these things.) - private readonly RuntimeTypeInfo _attributeType; + private readonly Type _attributeType; private readonly ReadOnlyCollection<CustomAttributeTypedArgument> _constructorArguments; private readonly ReadOnlyCollection<CustomAttributeNamedArgument> _namedArguments; } diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/EventInfos/EcmaFormat/EcmaFormatRuntimeEventInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/EventInfos/EcmaFormat/EcmaFormatRuntimeEventInfo.cs index 87820be0a..7c0d038e3 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/EventInfos/EcmaFormat/EcmaFormatRuntimeEventInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/EventInfos/EcmaFormat/EcmaFormatRuntimeEventInfo.cs @@ -108,8 +108,7 @@ namespace System.Reflection.Runtime.EventInfos.EcmaFormat ReflectionTrace.EventInfo_CustomAttributes(this); #endif - foreach (CustomAttributeData cad in RuntimeCustomAttributeData.GetCustomAttributes(_reader, _event.GetCustomAttributes())) - yield return cad; + return RuntimeCustomAttributeData.GetCustomAttributes(_reader, _event.GetCustomAttributes()); } } diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/EventInfos/NativeFormat/NativeFormatRuntimeEventInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/EventInfos/NativeFormat/NativeFormatRuntimeEventInfo.cs index f738c4e3c..dbcd8ea57 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/EventInfos/NativeFormat/NativeFormatRuntimeEventInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/EventInfos/NativeFormat/NativeFormatRuntimeEventInfo.cs @@ -104,10 +104,7 @@ namespace System.Reflection.Runtime.EventInfos.NativeFormat ReflectionTrace.EventInfo_CustomAttributes(this); #endif - foreach (CustomAttributeData cad in RuntimeCustomAttributeData.GetCustomAttributes(_reader, _event.CustomAttributes)) - yield return cad; - foreach (CustomAttributeData cad in ReflectionCoreExecution.ExecutionEnvironment.GetPseudoCustomAttributes(_reader, _eventHandle, _definingTypeInfo.TypeDefinitionHandle)) - yield return cad; + return RuntimeCustomAttributeData.GetCustomAttributes(_reader, _event.CustomAttributes); } } diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/FieldInfos/EcmaFormat/EcmaFormatRuntimeFieldInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/FieldInfos/EcmaFormat/EcmaFormatRuntimeFieldInfo.cs index c0a1ed041..cc5f49247 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/FieldInfos/EcmaFormat/EcmaFormatRuntimeFieldInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/FieldInfos/EcmaFormat/EcmaFormatRuntimeFieldInfo.cs @@ -64,28 +64,6 @@ namespace System.Reflection.Runtime.FieldInfos.EcmaFormat _field = _reader.GetFieldDefinition(fieldHandle); } - public sealed override IEnumerable<CustomAttributeData> CustomAttributes - { - get - { -#if ENABLE_REFLECTION_TRACE - if (ReflectionTrace.Enabled) - ReflectionTrace.FieldInfo_CustomAttributes(this); -#endif - - IEnumerable<CustomAttributeData> customAttributes = RuntimeCustomAttributeData.GetCustomAttributes(_reader, _field.GetCustomAttributes()); - foreach (CustomAttributeData cad in customAttributes) - yield return cad; - - if (_definingTypeInfo.IsExplicitLayout) - { - int offset = _field.GetOffset(); - CustomAttributeTypedArgument offsetArgument = new CustomAttributeTypedArgument(typeof(Int32), offset); - yield return ReflectionCoreExecution.ExecutionDomain.GetCustomAttributeData(typeof(System.Runtime.InteropServices.FieldOffsetAttribute), new CustomAttributeTypedArgument[] { offsetArgument }, null); - } - } - } - public sealed override FieldAttributes Attributes { get @@ -204,6 +182,10 @@ namespace System.Reflection.Runtime.FieldInfos.EcmaFormat protected sealed override RuntimeTypeInfo DefiningType { get { return _definingTypeInfo; } } + protected sealed override IEnumerable<CustomAttributeData> TrueCustomAttributes => RuntimeCustomAttributeData.GetCustomAttributes(_reader, _field.GetCustomAttributes()); + + protected sealed override int ExplicitLayoutFieldOffsetData => _field.GetOffset(); + private readonly EcmaFormatRuntimeNamedTypeInfo _definingTypeInfo; private readonly FieldDefinitionHandle _fieldHandle; diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/FieldInfos/NativeFormat/NativeFormatRuntimeFieldInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/FieldInfos/NativeFormat/NativeFormatRuntimeFieldInfo.cs index fdc97ec4d..38476fb18 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/FieldInfos/NativeFormat/NativeFormatRuntimeFieldInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/FieldInfos/NativeFormat/NativeFormatRuntimeFieldInfo.cs @@ -61,23 +61,6 @@ namespace System.Reflection.Runtime.FieldInfos.NativeFormat _field = fieldHandle.GetField(_reader); } - public sealed override IEnumerable<CustomAttributeData> CustomAttributes - { - get - { -#if ENABLE_REFLECTION_TRACE - if (ReflectionTrace.Enabled) - ReflectionTrace.FieldInfo_CustomAttributes(this); -#endif - - IEnumerable<CustomAttributeData> customAttributes = RuntimeCustomAttributeData.GetCustomAttributes(_reader, _field.CustomAttributes); - foreach (CustomAttributeData cad in customAttributes) - yield return cad; - foreach (CustomAttributeData cad in ReflectionCoreExecution.ExecutionEnvironment.GetPseudoCustomAttributes(_reader, _fieldHandle, _definingTypeInfo.TypeDefinitionHandle)) - yield return cad; - } - } - public sealed override FieldAttributes Attributes { get @@ -182,6 +165,10 @@ namespace System.Reflection.Runtime.FieldInfos.NativeFormat protected sealed override RuntimeTypeInfo DefiningType { get { return _definingTypeInfo; } } + protected sealed override IEnumerable<CustomAttributeData> TrueCustomAttributes => RuntimeCustomAttributeData.GetCustomAttributes(_reader, _field.CustomAttributes); + + protected sealed override int ExplicitLayoutFieldOffsetData => (int)(_field.Offset); + private Handle FieldTypeHandle => _field.Signature.GetFieldSignature(_reader).Type; private readonly NativeFormatRuntimeNamedTypeInfo _definingTypeInfo; diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/FieldInfos/RuntimeFieldInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/FieldInfos/RuntimeFieldInfo.cs index e5fe2ceab..392f6db9e 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/FieldInfos/RuntimeFieldInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/FieldInfos/RuntimeFieldInfo.cs @@ -7,6 +7,7 @@ using System.Reflection; using System.Diagnostics; using System.Globalization; using System.Collections.Generic; +using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Reflection.Runtime.General; @@ -50,6 +51,27 @@ namespace System.Reflection.Runtime.FieldInfos _reflectedType = reflectedType; } + public sealed override IEnumerable<CustomAttributeData> CustomAttributes + { + get + { +#if ENABLE_REFLECTION_TRACE + if (ReflectionTrace.Enabled) + ReflectionTrace.FieldInfo_CustomAttributes(this); +#endif + + foreach (CustomAttributeData cad in TrueCustomAttributes) + yield return cad; + + if (DeclaringType.IsExplicitLayout) + { + int offset = ExplicitLayoutFieldOffsetData; + CustomAttributeTypedArgument offsetArgument = new CustomAttributeTypedArgument(typeof(int), offset); + yield return new RuntimePseudoCustomAttributeData(typeof(FieldOffsetAttribute), new CustomAttributeTypedArgument[] { offsetArgument }, null); + } + } + } + public sealed override Type DeclaringType { get @@ -182,7 +204,6 @@ namespace System.Reflection.Runtime.FieldInfos } // Types that derive from RuntimeFieldInfo must implement the following public surface area members - public abstract override IEnumerable<CustomAttributeData> CustomAttributes { get; } public abstract override FieldAttributes Attributes { get; } public abstract override int MetadataToken { get; } public abstract override String ToString(); @@ -258,6 +279,9 @@ namespace System.Reflection.Runtime.FieldInfos /// </summary> protected abstract RuntimeTypeInfo DefiningType { get; } + protected abstract IEnumerable<CustomAttributeData> TrueCustomAttributes { get; } + protected abstract int ExplicitLayoutFieldOffsetData { get; } + /// <summary> /// Returns the field offset (asserts and throws if not an instance field). Does not include the size of the object header. /// </summary> diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/EcmaFormat/EcmaFormatMethodCommon.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/EcmaFormat/EcmaFormatMethodCommon.cs index e44ba9459..3d697d8ec 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/EcmaFormat/EcmaFormatMethodCommon.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/EcmaFormat/EcmaFormatMethodCommon.cs @@ -157,19 +157,6 @@ namespace System.Reflection.Runtime.MethodInfos.EcmaFormat } } - public IEnumerable<CustomAttributeData> CustomAttributes - { - get - { - IEnumerable<CustomAttributeData> customAttributes = RuntimeCustomAttributeData.GetCustomAttributes(_reader, _method.GetCustomAttributes()); - foreach (CustomAttributeData cad in customAttributes) - yield return cad; - - if (0 != (_method.ImplAttributes & MethodImplAttributes.PreserveSig)) - yield return ReflectionCoreExecution.ExecutionDomain.GetCustomAttributeData(typeof(PreserveSigAttribute), null, null); - } - } - public RuntimeTypeInfo DeclaringType { get @@ -317,6 +304,8 @@ namespace System.Reflection.Runtime.MethodInfos.EcmaFormat return true; } + public IEnumerable<CustomAttributeData> TrueCustomAttributes => RuntimeCustomAttributeData.GetCustomAttributes(_reader, _method.GetCustomAttributes()); + public override bool Equals(Object obj) { if (!(obj is EcmaFormatMethodCommon)) diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/IRuntimeMethodCommon.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/IRuntimeMethodCommon.cs index df1de5e97..68c458102 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/IRuntimeMethodCommon.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/IRuntimeMethodCommon.cs @@ -26,7 +26,6 @@ namespace System.Reflection.Runtime.MethodInfos CallingConventions CallingConvention { get; } RuntimeTypeInfo ContextTypeInfo { get; } - IEnumerable<CustomAttributeData> CustomAttributes { get; } RuntimeTypeInfo DeclaringType { get; } RuntimeNamedTypeInfo DefiningTypeInfo { get; } MethodImplAttributes MethodImplementationFlags { get; } @@ -36,6 +35,7 @@ namespace System.Reflection.Runtime.MethodInfos /// Return an array of the types of the return value and parameter types. /// </summary> QSignatureTypeHandle[] QualifiedMethodSignature { get; } + IEnumerable<CustomAttributeData> TrueCustomAttributes { get; } /// <summary> /// Parse the metadata that describes parameters, and for each parameter for which there is specific metadata diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/NativeFormat/NativeFormatMethodCommon.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/NativeFormat/NativeFormatMethodCommon.cs index ba7d93981..dae0a916b 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/NativeFormat/NativeFormatMethodCommon.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/NativeFormat/NativeFormatMethodCommon.cs @@ -2,9 +2,6 @@ // 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; -using System.Text; -using System.Reflection; using System.Diagnostics; using System.Collections.Generic; using System.Runtime; @@ -15,7 +12,6 @@ using System.Reflection.Runtime.ParameterInfos; using System.Reflection.Runtime.ParameterInfos.NativeFormat; using System.Reflection.Runtime.CustomAttributes; -using Internal.Reflection.Core; using Internal.Reflection.Core.Execution; using Internal.Runtime.CompilerServices; using Internal.Runtime.TypeLoader; @@ -149,18 +145,6 @@ namespace System.Reflection.Runtime.MethodInfos.NativeFormat } } - public IEnumerable<CustomAttributeData> CustomAttributes - { - get - { - IEnumerable<CustomAttributeData> customAttributes = RuntimeCustomAttributeData.GetCustomAttributes(_reader, _method.CustomAttributes); - foreach (CustomAttributeData cad in customAttributes) - yield return cad; - foreach (CustomAttributeData cad in ReflectionCoreExecution.ExecutionEnvironment.GetPseudoCustomAttributes(_reader, _methodHandle, _definingTypeInfo.TypeDefinitionHandle)) - yield return cad; - } - } - public RuntimeTypeInfo DeclaringType { get @@ -317,6 +301,8 @@ namespace System.Reflection.Runtime.MethodInfos.NativeFormat return true; } + public IEnumerable<CustomAttributeData> TrueCustomAttributes => RuntimeCustomAttributeData.GetCustomAttributes(_reader, _method.CustomAttributes); + public override bool Equals(Object obj) { if (!(obj is NativeFormatMethodCommon)) diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/RuntimeNamedMethodInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/RuntimeNamedMethodInfo.cs index c158d76f1..f2138c9be 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/RuntimeNamedMethodInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/RuntimeNamedMethodInfo.cs @@ -6,9 +6,11 @@ using System; using System.Reflection; using System.Diagnostics; using System.Collections.Generic; +using System.Runtime.InteropServices; using System.Reflection.Runtime.General; using System.Reflection.Runtime.TypeInfos; using System.Reflection.Runtime.ParameterInfos; +using System.Reflection.Runtime.CustomAttributes; using Internal.Reflection.Core.Execution; @@ -80,7 +82,14 @@ namespace System.Reflection.Runtime.MethodInfos ReflectionTrace.MethodBase_CustomAttributes(this); #endif - return _common.CustomAttributes; + foreach (CustomAttributeData cad in _common.TrueCustomAttributes) + { + yield return cad; + } + + MethodImplAttributes implAttributes = _common.MethodImplementationFlags; + if (0 != (implAttributes & MethodImplAttributes.PreserveSig)) + yield return new RuntimePseudoCustomAttributeData(typeof(PreserveSigAttribute), null, null); } } diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/RuntimePlainConstructorInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/RuntimePlainConstructorInfo.cs index fb5c6a122..a0792d08d 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/RuntimePlainConstructorInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/RuntimePlainConstructorInfo.cs @@ -71,7 +71,7 @@ namespace System.Reflection.Runtime.MethodInfos ReflectionTrace.MethodBase_CustomAttributes(this); #endif - return _common.CustomAttributes; + return _common.TrueCustomAttributes; } } diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/ParameterInfos/EcmaFormat/EcmaFormatMethodParameterInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/ParameterInfos/EcmaFormat/EcmaFormatMethodParameterInfo.cs index 6fd760eed..71a59d364 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/ParameterInfos/EcmaFormat/EcmaFormatMethodParameterInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/ParameterInfos/EcmaFormat/EcmaFormatMethodParameterInfo.cs @@ -49,24 +49,6 @@ namespace System.Reflection.Runtime.ParameterInfos.EcmaFormat } } - public sealed override IEnumerable<CustomAttributeData> CustomAttributes - { - get - { - IEnumerable<CustomAttributeData> customAttributes = RuntimeCustomAttributeData.GetCustomAttributes(this.Reader, _parameter.GetCustomAttributes()); - foreach (CustomAttributeData cad in customAttributes) - yield return cad; - - ParameterAttributes attributes = Attributes; - if (0 != (attributes & ParameterAttributes.In)) - yield return ReflectionCoreExecution.ExecutionDomain.GetCustomAttributeData(typeof(InAttribute), null, null); - if (0 != (attributes & ParameterAttributes.Out)) - yield return ReflectionCoreExecution.ExecutionDomain.GetCustomAttributeData(typeof(OutAttribute), null, null); - if (0 != (attributes & ParameterAttributes.Optional)) - yield return ReflectionCoreExecution.ExecutionDomain.GetCustomAttributeData(typeof(OptionalAttribute), null, null); - } - } - public sealed override String Name { get @@ -83,6 +65,8 @@ namespace System.Reflection.Runtime.ParameterInfos.EcmaFormat } } + protected sealed override IEnumerable<CustomAttributeData> TrueCustomAttributes => RuntimeCustomAttributeData.GetCustomAttributes(this.Reader, _parameter.GetCustomAttributes()); + protected sealed override bool GetDefaultValueIfAvailable(bool raw, out object defaultValue) { return DefaultValueProcessing.GetDefaultValueIfAny(Reader, ref _parameter, this, raw, out defaultValue); diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/ParameterInfos/NativeFormat/NativeFormatMethodParameterInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/ParameterInfos/NativeFormat/NativeFormatMethodParameterInfo.cs index 4daadc890..8ed4f11b1 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/ParameterInfos/NativeFormat/NativeFormatMethodParameterInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/ParameterInfos/NativeFormat/NativeFormatMethodParameterInfo.cs @@ -47,19 +47,6 @@ namespace System.Reflection.Runtime.ParameterInfos.NativeFormat } } - public sealed override IEnumerable<CustomAttributeData> CustomAttributes - { - get - { - IEnumerable<CustomAttributeData> customAttributes = RuntimeCustomAttributeData.GetCustomAttributes(this.Reader, _parameter.CustomAttributes); - foreach (CustomAttributeData cad in customAttributes) - yield return cad; - MethodHandle declaringMethodHandle = _methodHandle; - foreach (CustomAttributeData cad in ReflectionCoreExecution.ExecutionEnvironment.GetPseudoCustomAttributes(this.Reader, _parameterHandle, declaringMethodHandle)) - yield return cad; - } - } - public sealed override String Name { get @@ -76,6 +63,8 @@ namespace System.Reflection.Runtime.ParameterInfos.NativeFormat } } + protected sealed override IEnumerable<CustomAttributeData> TrueCustomAttributes => RuntimeCustomAttributeData.GetCustomAttributes(this.Reader, _parameter.CustomAttributes); + protected sealed override bool GetDefaultValueIfAvailable(bool raw, out object defaultValue) { return DefaultValueParser.GetDefaultValueIfAny(Reader, _parameter.DefaultValue, ParameterType, CustomAttributes, raw, out defaultValue); diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/ParameterInfos/RuntimeFatMethodParameterInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/ParameterInfos/RuntimeFatMethodParameterInfo.cs index bf7dc0c14..57ce50467 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/ParameterInfos/RuntimeFatMethodParameterInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/ParameterInfos/RuntimeFatMethodParameterInfo.cs @@ -3,7 +3,10 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; +using System.Collections.Generic; +using System.Runtime.InteropServices; using System.Reflection.Runtime.General; +using System.Reflection.Runtime.CustomAttributes; namespace System.Reflection.Runtime.ParameterInfos { @@ -18,6 +21,25 @@ namespace System.Reflection.Runtime.ParameterInfos { } + public sealed override IEnumerable<CustomAttributeData> CustomAttributes + { + get + { + foreach (CustomAttributeData cad in TrueCustomAttributes) + yield return cad; + + ParameterAttributes attributes = Attributes; + if (0 != (attributes & ParameterAttributes.In)) + yield return new RuntimePseudoCustomAttributeData(typeof(InAttribute), null, null); + if (0 != (attributes & ParameterAttributes.Out)) + yield return new RuntimePseudoCustomAttributeData(typeof(OutAttribute), null, null); + if (0 != (attributes & ParameterAttributes.Optional)) + yield return new RuntimePseudoCustomAttributeData(typeof(OptionalAttribute), null, null); + } + } + + protected abstract IEnumerable<CustomAttributeData> TrueCustomAttributes { get; } + public sealed override bool HasDefaultValue => DefaultValueInfo.Item1; public sealed override object DefaultValue => DefaultValueInfo.Item2; diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/PropertyInfos/EcmaFormat/EcmaFormatRuntimePropertyInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/PropertyInfos/EcmaFormat/EcmaFormatRuntimePropertyInfo.cs index 47d9ba5f4..e25d3f543 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/PropertyInfos/EcmaFormat/EcmaFormatRuntimePropertyInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/PropertyInfos/EcmaFormat/EcmaFormatRuntimePropertyInfo.cs @@ -79,8 +79,7 @@ namespace System.Reflection.Runtime.PropertyInfos.EcmaFormat ReflectionTrace.PropertyInfo_CustomAttributes(this); #endif - foreach (CustomAttributeData cad in RuntimeCustomAttributeData.GetCustomAttributes(_reader, _property.GetCustomAttributes())) - yield return cad; + return RuntimeCustomAttributeData.GetCustomAttributes(_reader, _property.GetCustomAttributes()); } } diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/PropertyInfos/NativeFormat/NativeFormatRuntimePropertyInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/PropertyInfos/NativeFormat/NativeFormatRuntimePropertyInfo.cs index 2606d8174..56c22b86f 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/PropertyInfos/NativeFormat/NativeFormatRuntimePropertyInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/PropertyInfos/NativeFormat/NativeFormatRuntimePropertyInfo.cs @@ -79,10 +79,7 @@ namespace System.Reflection.Runtime.PropertyInfos.NativeFormat ReflectionTrace.PropertyInfo_CustomAttributes(this); #endif - foreach (CustomAttributeData cad in RuntimeCustomAttributeData.GetCustomAttributes(_reader, _property.CustomAttributes)) - yield return cad; - foreach (CustomAttributeData cad in ReflectionCoreExecution.ExecutionEnvironment.GetPseudoCustomAttributes(_reader, _propertyHandle, _definingTypeInfo.TypeDefinitionHandle)) - yield return cad; + return RuntimeCustomAttributeData.GetCustomAttributes(_reader, _property.CustomAttributes); } } diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/EcmaFormat/EcmaFormatRuntimeNamedTypeInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/EcmaFormat/EcmaFormatRuntimeNamedTypeInfo.cs index 0034bac7a..822bfb6f5 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/EcmaFormat/EcmaFormatRuntimeNamedTypeInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/EcmaFormat/EcmaFormatRuntimeNamedTypeInfo.cs @@ -42,24 +42,6 @@ namespace System.Reflection.Runtime.TypeInfos.EcmaFormat } } - public sealed override IEnumerable<CustomAttributeData> CustomAttributes - { - get - { -#if ENABLE_REFLECTION_TRACE - if (ReflectionTrace.Enabled) - ReflectionTrace.TypeInfo_CustomAttributes(this); -#endif - - IEnumerable<CustomAttributeData> customAttributes = RuntimeCustomAttributeData.GetCustomAttributes(_reader, _typeDefinition.GetCustomAttributes()); - foreach (CustomAttributeData cad in customAttributes) - yield return cad; - - if (0 != (_typeDefinition.Attributes & TypeAttributes.Import)) - yield return ReflectionCoreExecution.ExecutionDomain.GetCustomAttributeData(typeof(ComImportAttribute), null, null); - } - } - protected sealed override Guid? ComputeGuidFromCustomAttributes() { // @@ -218,6 +200,8 @@ namespace System.Reflection.Runtime.TypeInfos.EcmaFormat return name.EscapeTypeNameIdentifier(); } + protected sealed override IEnumerable<CustomAttributeData> TrueCustomAttributes => RuntimeCustomAttributeData.GetCustomAttributes(_reader, _typeDefinition.GetCustomAttributes()); + internal sealed override RuntimeTypeInfo[] RuntimeGenericTypeParameters { get diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeNamedTypeInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeNamedTypeInfo.cs index cf057083f..9fac5f941 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeNamedTypeInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeNamedTypeInfo.cs @@ -2,19 +2,14 @@ // 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; using System.Text; using System.Reflection; using System.Diagnostics; using System.Collections.Generic; -using System.Collections.Concurrent; using System.Reflection.Runtime.Assemblies; using System.Reflection.Runtime.General; -using System.Reflection.Runtime.MethodInfos; -using System.Reflection.Runtime.TypeInfos; using System.Reflection.Runtime.CustomAttributes; -using Internal.Reflection.Core.Execution; using Internal.Reflection.Tracing; using Internal.Metadata.NativeFormat; @@ -46,25 +41,6 @@ namespace System.Reflection.Runtime.TypeInfos.NativeFormat } } - public sealed override IEnumerable<CustomAttributeData> CustomAttributes - { - get - { -#if ENABLE_REFLECTION_TRACE - if (ReflectionTrace.Enabled) - ReflectionTrace.TypeInfo_CustomAttributes(this); -#endif - - IEnumerable<CustomAttributeData> customAttributes = RuntimeCustomAttributeData.GetCustomAttributes(_reader, _typeDefinition.CustomAttributes); - foreach (CustomAttributeData cad in customAttributes) - yield return cad; - foreach (CustomAttributeData cad in ReflectionCoreExecution.ExecutionEnvironment.GetPseudoCustomAttributes(_reader, _typeDefinitionHandle)) - { - yield return cad; - } - } - } - protected sealed override Guid? ComputeGuidFromCustomAttributes() { // @@ -210,6 +186,8 @@ namespace System.Reflection.Runtime.TypeInfos.NativeFormat return name.EscapeTypeNameIdentifier(); } + protected sealed override IEnumerable<CustomAttributeData> TrueCustomAttributes => RuntimeCustomAttributeData.GetCustomAttributes(_reader, _typeDefinition.CustomAttributes); + internal sealed override RuntimeTypeInfo[] RuntimeGenericTypeParameters { get diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeNamedTypeInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeNamedTypeInfo.cs index da34e9714..6f40ed267 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeNamedTypeInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeNamedTypeInfo.cs @@ -2,26 +2,15 @@ // 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; -using System.Text; -using System.Reflection; using System.Diagnostics; using System.Collections.Generic; using System.Collections.Concurrent; +using System.Runtime.InteropServices; using System.Reflection.Runtime.General; -using System.Reflection.Runtime.TypeInfos; -using System.Reflection.Runtime.Assemblies; using System.Reflection.Runtime.CustomAttributes; -using Internal.LowLevelLinq; -using Internal.Reflection.Core.Execution; - using Internal.Reflection.Tracing; -using CharSet = System.Runtime.InteropServices.CharSet; -using LayoutKind = System.Runtime.InteropServices.LayoutKind; -using StructLayoutAttribute = System.Runtime.InteropServices.StructLayoutAttribute; - namespace System.Reflection.Runtime.TypeInfos { // @@ -43,6 +32,23 @@ namespace System.Reflection.Runtime.TypeInfos } } + public sealed override IEnumerable<CustomAttributeData> CustomAttributes + { + get + { +#if ENABLE_REFLECTION_TRACE + if (ReflectionTrace.Enabled) + ReflectionTrace.TypeInfo_CustomAttributes(this); +#endif + + foreach (CustomAttributeData cad in TrueCustomAttributes) + yield return cad; + + if (0 != (Attributes & TypeAttributes.Import)) + yield return new RuntimePseudoCustomAttributeData(typeof(ComImportAttribute), null, null); + } + } + public bool Equals(RuntimeNamedTypeInfo other) { // RuntimeTypeInfo.Equals(object) is the one that encapsulates our unification strategy so defer to him. @@ -164,6 +170,8 @@ namespace System.Reflection.Runtime.TypeInfos } } + protected abstract IEnumerable<CustomAttributeData> TrueCustomAttributes { get; } + // // Returns the anchoring typedef that declares the members that this type wants returned by the Declared*** properties. // The Declared*** properties will project the anchoring typedef's members by overriding their DeclaringType property with "this" |