@ -166,7 +166,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
@@ -166,7 +166,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
try {
var nullableContext = methodDef . GetCustomAttributes ( ) . GetNullableContext ( module . metadata ) ? ? DeclaringTypeDefinition . NullableContext ;
var signature = methodDef . DecodeSignature ( module . TypeProvider , genericContext ) ;
( returnType , parameters ) = DecodeSignature ( module , this , signature , methodDef . GetParameters ( ) , nullableContext ) ;
( returnType , parameters ) = DecodeSignature ( module , this , signature , methodDef . GetParameters ( ) , nullableContext , module . OptionsForEntity ( this ) ) ;
} catch ( BadImageFormatException ) {
returnType = SpecialType . UnknownType ;
parameters = Empty < IParameter > . Array ;
@ -175,11 +175,13 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
@@ -175,11 +175,13 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
LazyInit . GetOrSet ( ref this . parameters , parameters ) ;
}
internal static ( IType , IParameter [ ] ) DecodeSignature ( MetadataModule module , IParameterizedMember owner , MethodSignature < IType > signature , ParameterHandleCollection ? parameterHandles , Nullability nullableContext )
internal static ( IType , IParameter [ ] ) DecodeSignature ( MetadataModule module , IParameterizedMember owner ,
MethodSignature < IType > signature , ParameterHandleCollection ? parameterHandles ,
Nullability nullableContext , TypeSystemOptions typeSystemOptions ,
CustomAttributeHandleCollection ? returnTypeAttributes = null )
{
var metadata = module . metadata ;
int i = 0 ;
CustomAttributeHandleCollection ? returnTypeAttributes = null ;
IParameter [ ] parameters = new IParameter [ signature . RequiredParameterCount
+ ( signature . Header . CallingConvention = = SignatureCallingConvention . VarArgs ? 1 : 0 ) ] ;
IType parameterType ;
@ -187,8 +189,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
@@ -187,8 +189,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
foreach ( var parameterHandle in parameterHandles ) {
var par = metadata . GetParameter ( parameterHandle ) ;
if ( par . SequenceNumber = = 0 ) {
// "parameter" holds return type attributes
returnTypeAttributes = par . GetCustomAttributes ( ) ;
// "parameter" holds return type attributes.
// Note: for properties, the attributes normally stored on a method's return type
// are instead stored as normal attributes on the property.
// So MetadataProperty provides a non-null value for returnTypeAttributes,
// which then should be preferred over the attributes on the accessor's parameters.
if ( returnTypeAttributes = = null ) {
returnTypeAttributes = par . GetCustomAttributes ( ) ;
}
} else if ( par . SequenceNumber > 0 & & i < signature . RequiredParameterCount ) {
// "Successive rows of the Param table that are owned by the same method shall be
// ordered by increasing Sequence value - although gaps in the sequence are allowed"
@ -196,14 +204,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
@@ -196,14 +204,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
// Fill gaps in the sequence with non-metadata parameters:
while ( i < par . SequenceNumber - 1 ) {
parameterType = ApplyAttributeTypeVisitor . ApplyAttributesToType (
signature . ParameterTypes [ i ] , module . Compilation , null , metadata , module . T ypeSystemOptions, nullableContext ) ;
signature . ParameterTypes [ i ] , module . Compilation , null , metadata , t ypeSystemOptions, nullableContext ) ;
parameters [ i ] = new DefaultParameter ( parameterType , name : string . Empty , owner ,
referenceKind : parameterType . Kind = = TypeKind . ByReference ? ReferenceKind . Ref : ReferenceKind . None ) ;
i + + ;
}
parameterType = ApplyAttributeTypeVisitor . ApplyAttributesToType (
signature . ParameterTypes [ i ] , module . Compilation ,
par . GetCustomAttributes ( ) , metadata , module . T ypeSystemOptions, nullableContext ) ;
par . GetCustomAttributes ( ) , metadata , t ypeSystemOptions, nullableContext ) ;
parameters [ i ] = new MetadataParameter ( module , owner , parameterType , parameterHandle ) ;
i + + ;
}
@ -211,7 +219,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
@@ -211,7 +219,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
}
while ( i < signature . RequiredParameterCount ) {
parameterType = ApplyAttributeTypeVisitor . ApplyAttributesToType (
signature . ParameterTypes [ i ] , module . Compilation , null , metadata , module . T ypeSystemOptions, nullableContext ) ;
signature . ParameterTypes [ i ] , module . Compilation , null , metadata , t ypeSystemOptions, nullableContext ) ;
parameters [ i ] = new DefaultParameter ( parameterType , name : string . Empty , owner ,
referenceKind : parameterType . Kind = = TypeKind . ByReference ? ReferenceKind . Ref : ReferenceKind . None ) ;
i + + ;
@ -222,7 +230,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
@@ -222,7 +230,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
}
Debug . Assert ( i = = parameters . Length ) ;
var returnType = ApplyAttributeTypeVisitor . ApplyAttributesToType ( signature . ReturnType ,
module . Compilation , returnTypeAttributes , metadata , module . T ypeSystemOptions, nullableContext ) ;
module . Compilation , returnTypeAttributes , metadata , t ypeSystemOptions, nullableContext ) ;
return ( returnType , parameters ) ;
}
#endregion