@ -30,52 +30,88 @@ namespace ICSharpCode.Decompiler.Disassembler
{
{
public static class MetadataExtensions
public static class MetadataExtensions
{
{
public static void WriteTo ( this Metadata . TypeDefinition typeDefinition , ITextOutput output , ILNameSyntax syntax = ILNameSyntax . Signature )
public static void WriteTo ( this EntityHandle entity , PEFile module , ITextOutput output , GenericContext genericContex t , ILNameSyntax syntax = ILNameSyntax . Signature )
{
{
var metadata = typeDefinition . Module . GetMetadataReader ( ) ;
if ( entity . IsNil )
output . WriteReference ( typeDefinition . This ( ) . GetFullTypeName ( metadata ) . ToILNameString ( ) , typeDefinition ) ;
throw new ArgumentNullException ( nameof ( entity ) ) ;
if ( module = = null )
throw new ArgumentNullException ( nameof ( module ) ) ;
var metadata = module . Metadata ;
Action < ILNameSyntax > signature ;
MethodSignature < Action < ILNameSyntax > > methodSignature ;
string memberName ;
switch ( entity . Kind ) {
case HandleKind . TypeDefinition : {
var td = metadata . GetTypeDefinition ( ( TypeDefinitionHandle ) entity ) ;
output . WriteReference ( td . GetFullTypeName ( metadata ) . ToILNameString ( ) , new Metadata . TypeDefinition ( module , ( TypeDefinitionHandle ) entity ) ) ;
break ;
}
}
case HandleKind . TypeReference : {
public static void WriteTo ( this Metadata . FieldDefinition field , ITextOutput output )
var tr = metadata . GetTypeReference ( ( TypeReferenceHandle ) entity ) ;
{
if ( ! tr . ResolutionScope . IsNil ) {
var metadata = field . Module . GetMetadataReader ( ) ;
output . Write ( "[" ) ;
var fieldDefinition = metadata . GetFieldDefinition ( field . Handle ) ;
var currentTypeRef = tr ;
var declaringType = new Metadata . TypeDefinition ( field . Module , fieldDefinition . GetDeclaringType ( ) ) ;
while ( currentTypeRef . ResolutionScope . Kind = = HandleKind . TypeReference ) {
var signature = fieldDefinition . DecodeSignature ( new DisassemblerSignatureProvider ( field . Module , output ) , new GenericContext ( declaringType ) ) ;
currentTypeRef = metadata . GetTypeReference ( ( TypeReferenceHandle ) currentTypeRef . ResolutionScope ) ;
}
switch ( currentTypeRef . ResolutionScope . Kind ) {
case HandleKind . ModuleDefinition :
var modDef = metadata . GetModuleDefinition ( ) ;
output . Write ( DisassemblerHelpers . Escape ( metadata . GetString ( modDef . Name ) ) ) ;
break ;
case HandleKind . ModuleReference :
break ;
case HandleKind . AssemblyReference :
var asmRef = metadata . GetAssemblyReference ( ( AssemblyReferenceHandle ) currentTypeRef . ResolutionScope ) ;
output . Write ( DisassemblerHelpers . Escape ( metadata . GetString ( asmRef . Name ) ) ) ;
break ;
}
output . Write ( "]" ) ;
}
output . WriteReference ( entity . GetFullTypeName ( metadata ) . ToILNameString ( ) , new Metadata . TypeReference ( module , ( TypeReferenceHandle ) entity ) ) ;
break ;
}
case HandleKind . TypeSpecification : {
var ts = metadata . GetTypeSpecification ( ( TypeSpecificationHandle ) entity ) ;
signature = ts . DecodeSignature ( new DisassemblerSignatureProvider ( module , output ) , genericContext ) ;
signature ( syntax ) ;
break ;
}
case HandleKind . FieldDefinition : {
var fd = metadata . GetFieldDefinition ( ( FieldDefinitionHandle ) entity ) ;
signature = fd . DecodeSignature ( new DisassemblerSignatureProvider ( module , output ) , new GenericContext ( fd . GetDeclaringType ( ) , module ) ) ;
signature ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
signature ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
output . Write ( ' ' ) ;
output . Write ( ' ' ) ;
declaringType . WriteTo ( output , ILNameSyntax . TypeName ) ;
( ( EntityHan dle ) fd . GetD eclaringType( ) ) . WriteTo ( module , output , GenericContext . Empty , ILNameSyntax . TypeName ) ;
output . Write ( "::" ) ;
output . Write ( "::" ) ;
output . Write ( DisassemblerHelpers . Escape ( metadata . GetString ( fieldDefinition . Name ) ) ) ;
output . Write ( DisassemblerHelpers . Escape ( metadata . GetString ( fd . Name ) ) ) ;
break ;
}
}
case HandleKind . MethodDefinition : {
public static void WriteTo ( this Metadata . MethodDefinition method , ITextOutput output )
var md = metadata . GetMethodDefinition ( ( MethodDefinitionHandle ) entity ) ;
{
methodSignature = md . DecodeSignature ( new DisassemblerSignatureProvider ( module , output ) , new GenericContext ( ( MethodDefinitionHandle ) entity , module ) ) ;
var metadata = method . Module . GetMetadataReader ( ) ;
if ( methodSignature . Header . HasExplicitThis ) {
var methodDefinition = method . This ( ) ;
var signature = methodDefinition . DecodeSignature ( new DisassemblerSignatureProvider ( method . Module , output ) , new GenericContext ( method ) ) ;
if ( signature . Header . HasExplicitThis ) {
output . Write ( "instance explicit " ) ;
output . Write ( "instance explicit " ) ;
} else if ( signature . Header . IsInstance ) {
} else if ( methodSignature . Header . IsInstance ) {
output . Write ( "instance " ) ;
output . Write ( "instance " ) ;
}
}
if ( signature . Header . CallingConvention = = SignatureCallingConvention . VarArgs ) {
if ( methodS ignature. Header . CallingConvention = = SignatureCallingConvention . VarArgs ) {
output . Write ( "vararg " ) ;
output . Write ( "vararg " ) ;
}
}
signature . ReturnType ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
methodS ignature . ReturnType ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
output . Write ( ' ' ) ;
output . Write ( ' ' ) ;
var declaringType = methodDefinition . GetDeclaringType ( ) ;
var declaringType = md . GetDeclaringType ( ) ;
if ( ! declaringType . IsNil ) {
if ( ! declaringType . IsNil ) {
new Metadata . TypeDefinition ( method . Module , declaringType ) . WriteTo ( output , ILNameSyntax . TypeName ) ;
( ( EntityHandle ) declaringType ) . WriteTo ( module , output , genericContex t , ILNameSyntax . TypeName ) ;
output . Write ( "::" ) ;
output . Write ( "::" ) ;
}
}
bool isCompilerControlled = ( metho dDefinition . Attributes & MethodAttributes . MemberAccessMask ) = = MethodAttributes . PrivateScope ;
bool isCompilerControlled = ( md . Attributes & MethodAttributes . MemberAccessMask ) = = MethodAttributes . PrivateScope ;
if ( isCompilerControlled ) {
if ( isCompilerControlled ) {
output . Write ( DisassemblerHelpers . Escape ( metadata . GetString ( metho dDefinition . Name ) + "$PST" + MetadataTokens . GetToken ( method . Handle ) . ToString ( "X8" ) ) ) ;
output . Write ( DisassemblerHelpers . Escape ( metadata . GetString ( md . Name ) + "$PST" + MetadataTokens . GetToken ( entity ) . ToString ( "X8" ) ) ) ;
} else {
} else {
output . Write ( DisassemblerHelpers . Escape ( metadata . GetString ( metho dDefinition . Name ) ) ) ;
output . Write ( DisassemblerHelpers . Escape ( metadata . GetString ( md . Name ) ) ) ;
}
}
var genericParameters = metho dDefinition . GetGenericParameters ( ) ;
var genericParameters = md . GetGenericParameters ( ) ;
if ( genericParameters . Count > 0 ) {
if ( genericParameters . Count > 0 ) {
output . Write ( '<' ) ;
output . Write ( '<' ) ;
for ( int i = 0 ; i < genericParameters . Count ; i + + ) {
for ( int i = 0 ; i < genericParameters . Count ; i + + ) {
@ -97,7 +133,7 @@ namespace ICSharpCode.Decompiler.Disassembler
if ( j > 0 )
if ( j > 0 )
output . Write ( ", " ) ;
output . Write ( ", " ) ;
var constraint = metadata . GetGenericParameterConstraint ( constraints [ j ] ) ;
var constraint = metadata . GetGenericParameterConstraint ( constraints [ j ] ) ;
constraint . Type . WriteTo ( method . Module , output , new GenericContext ( method ) , ILNameSyntax . TypeName ) ;
constraint . Type . WriteTo ( module , output , new GenericContext ( ( MethodDefinitionHandle ) entity , module ) , ILNameSyntax . TypeName ) ;
}
}
output . Write ( ") " ) ;
output . Write ( ") " ) ;
}
}
@ -111,102 +147,74 @@ namespace ICSharpCode.Decompiler.Disassembler
output . Write ( '>' ) ;
output . Write ( '>' ) ;
}
}
output . Write ( "(" ) ;
output . Write ( "(" ) ;
for ( int i = 0 ; i < s ignature. ParameterTypes . Length ; + + i ) {
for ( int i = 0 ; i < methodS ignature. ParameterTypes . Length ; + + i ) {
if ( i > 0 )
if ( i > 0 )
output . Write ( ", " ) ;
output . Write ( ", " ) ;
s ignature. ParameterTypes [ i ] ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
methodS ignature . ParameterTypes [ i ] ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
}
}
output . Write ( ")" ) ;
output . Write ( ")" ) ;
}
public static void WriteTo ( this EntityHandle entity , PEFile module , ITextOutput output , GenericContext genericContext , ILNameSyntax syntax = ILNameSyntax . Signature )
{
if ( entity . IsNil )
throw new ArgumentNullException ( nameof ( entity ) ) ;
if ( module = = null )
throw new ArgumentNullException ( nameof ( module ) ) ;
WriteTo ( new Entity ( module , entity ) , output , genericContext , syntax ) ;
}
public static void WriteTo ( this Entity entity , ITextOutput output , GenericContext genericContext , ILNameSyntax syntax = ILNameSyntax . Signature )
{
if ( entity . IsNil )
throw new ArgumentNullException ( nameof ( entity ) ) ;
var metadata = entity . Module . GetMetadataReader ( ) ;
switch ( entity . Handle . Kind ) {
case HandleKind . TypeDefinition :
WriteTo ( entity , output , syntax ) ;
break ;
case HandleKind . TypeReference :
WriteTo ( new Metadata . TypeReference ( entity . Module , ( TypeReferenceHandle ) entity . Handle ) , output , syntax ) ;
break ;
case HandleKind . TypeSpecification :
WriteTo ( new Metadata . TypeSpecification ( entity . Module , ( TypeSpecificationHandle ) entity . Handle ) , output , genericContext , syntax ) ;
break ;
case HandleKind . FieldDefinition :
WriteTo ( ( Metadata . FieldDefinition ) entity , output ) ;
break ;
case HandleKind . MethodDefinition :
WriteTo ( ( Metadata . MethodDefinition ) entity , output ) ;
break ;
break ;
}
case HandleKind . MemberReference :
case HandleKind . MemberReference :
WriteTo ( ( MemberReferenceHandle ) entity . Handle , entity . Module , output , genericContext , syntax ) ;
var mr = metadata . GetMemberReference ( ( MemberReferenceHandle ) entity ) ;
break ;
memberName = metadata . GetString ( mr . Name ) ;
case HandleKind . MethodSpecification :
switch ( mr . GetKind ( ) ) {
WriteTo ( ( MethodSpecificationHandle ) entity . Handle , entity . Module , output , genericContext , syntax ) ;
case MemberReferenceKind . Method :
break ;
methodSignature = mr . DecodeMethodSignature ( new DisassemblerSignatureProvider ( module , output ) , genericContext ) ;
case HandleKind . PropertyDefinition :
if ( methodSignature . Header . HasExplicitThis ) {
case HandleKind . EventDefinition :
output . Write ( "instance explicit " ) ;
throw new NotSupportedException ( ) ;
} else if ( methodSignature . Header . IsInstance ) {
case HandleKind . StandaloneSignature :
output . Write ( "instance " ) ;
var standaloneSig = metadata . GetStandaloneSignature ( ( StandaloneSignatureHandle ) entity . Handle ) ;
}
switch ( standaloneSig . GetKind ( ) ) {
if ( methodSignature . Header . CallingConvention = = SignatureCallingConvention . VarArgs ) {
case StandaloneSignatureKind . Method :
output . Write ( "vararg " ) ;
var methodSig = standaloneSig . DecodeMethodSignature ( new DisassemblerSignatureProvider ( entity . Module , output ) , genericContext ) ;
}
methodSig . ReturnType ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
methodSignature . ReturnType ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
output . Write ( '(' ) ;
output . Write ( ' ' ) ;
for ( int i = 0 ; i < methodSig . ParameterTypes . Length ; i + + ) {
WriteParent ( output , module , metadata , mr . Parent , genericContext , syntax ) ;
output . Write ( "::" ) ;
output . Write ( DisassemblerHelpers . Escape ( memberName ) ) ;
output . Write ( "(" ) ;
for ( int i = 0 ; i < methodSignature . ParameterTypes . Length ; + + i ) {
if ( i > 0 )
if ( i > 0 )
output . Write ( ", " ) ;
output . Write ( ", " ) ;
methodSig . ParameterTypes [ i ] ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
if ( i = = methodSignature . RequiredParameterCount )
output . Write ( "..., " ) ;
methodSignature . ParameterTypes [ i ] ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
}
}
output . Write ( ')' ) ;
output . Write ( ")" ) ;
break ;
break ;
case StandaloneSignatureKind . LocalVariables :
case MemberReferenceKind . Field :
default :
var fieldSignature = mr . DecodeFieldSignature ( new DisassemblerSignatureProvider ( module , output ) , genericContext ) ;
throw new NotSupportedException ( ) ;
fieldSignature ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
}
output . Write ( ' ' ) ;
WriteParent ( output , module , metadata , mr . Parent , genericContext , syntax ) ;
output . Write ( "::" ) ;
output . Write ( DisassemblerHelpers . Escape ( memberName ) ) ;
break ;
break ;
default :
throw new NotSupportedException ( ) ;
}
}
}
break ;
case HandleKind . MethodSpecification :
public static void WriteTo ( this MethodSpecificationHandle handle , PEFile module , ITextOutput output , GenericContext genericContext , ILNameSyntax syntax )
var ms = metadata . GetMethodSpecification ( ( MethodSpecificationHandle ) entity ) ;
{
var metadata = module . GetMetadataReader ( ) ;
var ms = metadata . GetMethodSpecification ( handle ) ;
var substitution = ms . DecodeSignature ( new DisassemblerSignatureProvider ( module , output ) , genericContext ) ;
var substitution = ms . DecodeSignature ( new DisassemblerSignatureProvider ( module , output ) , genericContext ) ;
MethodSignature < Action < ILNameSyntax > > signature ;
switch ( ms . Method . Kind ) {
switch ( ms . Method . Kind ) {
case HandleKind . MethodDefinition :
case HandleKind . MethodDefinition :
var methodDefinition = metadata . GetMethodDefinition ( ( MethodDefinitionHandle ) ms . Method ) ;
var methodDefinition = metadata . GetMethodDefinition ( ( MethodDefinitionHandle ) ms . Method ) ;
var methodName = metadata . GetString ( methodDefinition . Name ) ;
var methodName = metadata . GetString ( methodDefinition . Name ) ;
s ignature = methodDefinition . DecodeSignature ( new DisassemblerSignatureProvider ( module , output ) , genericContext ) ;
methodS ignature = methodDefinition . DecodeSignature ( new DisassemblerSignatureProvider ( module , output ) , genericContext ) ;
if ( s ignature. Header . HasExplicitThis ) {
if ( methodS ignature. Header . HasExplicitThis ) {
output . Write ( "instance explicit " ) ;
output . Write ( "instance explicit " ) ;
} else if ( s ignature. Header . IsInstance ) {
} else if ( methodS ignature. Header . IsInstance ) {
output . Write ( "instance " ) ;
output . Write ( "instance " ) ;
}
}
if ( s ignature. Header . CallingConvention = = SignatureCallingConvention . VarArgs ) {
if ( methodS ignature. Header . CallingConvention = = SignatureCallingConvention . VarArgs ) {
output . Write ( "vararg " ) ;
output . Write ( "vararg " ) ;
}
}
s ignature. ReturnType ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
methodS ignature . ReturnType ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
output . Write ( ' ' ) ;
output . Write ( ' ' ) ;
var declaringType = methodDefinition . GetDeclaringType ( ) ;
var declaringType = methodDefinition . GetDeclaringType ( ) ;
if ( ! declaringType . IsNil ) {
if ( ! declaringType . IsNil ) {
new Metadata . TypeDefinition ( module , declaringType ) . WriteTo ( outpu t, ILNameSyntax . TypeName ) ;
( ( EntityHandle ) declaringType ) . WriteTo ( module , output , genericContex t , ILNameSyntax . TypeName ) ;
output . Write ( "::" ) ;
output . Write ( "::" ) ;
}
}
bool isCompilerControlled = ( methodDefinition . Attributes & MethodAttributes . MemberAccessMask ) = = MethodAttributes . PrivateScope ;
bool isCompilerControlled = ( methodDefinition . Attributes & MethodAttributes . MemberAccessMask ) = = MethodAttributes . PrivateScope ;
@ -223,26 +231,26 @@ namespace ICSharpCode.Decompiler.Disassembler
}
}
output . Write ( '>' ) ;
output . Write ( '>' ) ;
output . Write ( "(" ) ;
output . Write ( "(" ) ;
for ( int i = 0 ; i < s ignature. ParameterTypes . Length ; + + i ) {
for ( int i = 0 ; i < methodS ignature. ParameterTypes . Length ; + + i ) {
if ( i > 0 )
if ( i > 0 )
output . Write ( ", " ) ;
output . Write ( ", " ) ;
s ignature. ParameterTypes [ i ] ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
methodS ignature . ParameterTypes [ i ] ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
}
}
output . Write ( ")" ) ;
output . Write ( ")" ) ;
break ;
break ;
case HandleKind . MemberReference :
case HandleKind . MemberReference :
var memberReference = metadata . GetMemberReference ( ( MemberReferenceHandle ) ms . Method ) ;
var memberReference = metadata . GetMemberReference ( ( MemberReferenceHandle ) ms . Method ) ;
var memberName = metadata . GetString ( memberReference . Name ) ;
memberName = metadata . GetString ( memberReference . Name ) ;
s ignature = memberReference . DecodeMethodSignature ( new DisassemblerSignatureProvider ( module , output ) , genericContext ) ;
methodS ignature = memberReference . DecodeMethodSignature ( new DisassemblerSignatureProvider ( module , output ) , genericContext ) ;
if ( s ignature. Header . HasExplicitThis ) {
if ( methodS ignature. Header . HasExplicitThis ) {
output . Write ( "instance explicit " ) ;
output . Write ( "instance explicit " ) ;
} else if ( s ignature. Header . IsInstance ) {
} else if ( methodS ignature. Header . IsInstance ) {
output . Write ( "instance " ) ;
output . Write ( "instance " ) ;
}
}
if ( s ignature. Header . CallingConvention = = SignatureCallingConvention . VarArgs ) {
if ( methodS ignature. Header . CallingConvention = = SignatureCallingConvention . VarArgs ) {
output . Write ( "vararg " ) ;
output . Write ( "vararg " ) ;
}
}
s ignature. ReturnType ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
methodS ignature . ReturnType ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
output . Write ( ' ' ) ;
output . Write ( ' ' ) ;
WriteParent ( output , module , metadata , memberReference . Parent , genericContext , syntax ) ;
WriteParent ( output , module , metadata , memberReference . Parent , genericContext , syntax ) ;
output . Write ( "::" ) ;
output . Write ( "::" ) ;
@ -255,88 +263,40 @@ namespace ICSharpCode.Decompiler.Disassembler
}
}
output . Write ( '>' ) ;
output . Write ( '>' ) ;
output . Write ( "(" ) ;
output . Write ( "(" ) ;
for ( int i = 0 ; i < s ignature. ParameterTypes . Length ; + + i ) {
for ( int i = 0 ; i < methodS ignature. ParameterTypes . Length ; + + i ) {
if ( i > 0 )
if ( i > 0 )
output . Write ( ", " ) ;
output . Write ( ", " ) ;
s ignature. ParameterTypes [ i ] ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
methodS ignature . ParameterTypes [ i ] ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
}
}
output . Write ( ")" ) ;
output . Write ( ")" ) ;
break ;
break ;
}
}
}
break ;
case HandleKind . PropertyDefinition :
public static void WriteTo ( this MemberReferenceHandle handle , PEFile module , ITextOutput output , GenericContext genericContext , ILNameSyntax syntax = ILNameSyntax . Signature )
case HandleKind . EventDefinition :
{
throw new NotSupportedException ( ) ;
var metadata = module . GetMetadataReader ( ) ;
case HandleKind . StandaloneSignature :
var mr = metadata . GetMemberReference ( handle ) ;
var standaloneSig = metadata . GetStandaloneSignature ( ( StandaloneSignatureHandle ) entity ) ;
var memberName = metadata . GetString ( mr . Name ) ;
switch ( standaloneSig . GetKind ( ) ) {
switch ( mr . GetKind ( ) ) {
case StandaloneSignatureKind . Method :
case MemberReferenceKind . Method :
var methodSig = standaloneSig . DecodeMethodSignature ( new DisassemblerSignatureProvider ( module , output ) , genericContext ) ;
var methodSignature = mr . DecodeMethodSignature ( new DisassemblerSignatureProvider ( module , output ) , genericContext ) ;
methodSig . ReturnType ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
if ( methodSignature . Header . HasExplicitThis ) {
output . Write ( '(' ) ;
output . Write ( "instance explicit " ) ;
for ( int i = 0 ; i < methodSig . ParameterTypes . Length ; i + + ) {
} else if ( methodSignature . Header . IsInstance ) {
output . Write ( "instance " ) ;
}
if ( methodSignature . Header . CallingConvention = = SignatureCallingConvention . VarArgs ) {
output . Write ( "vararg " ) ;
}
methodSignature . ReturnType ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
output . Write ( ' ' ) ;
WriteParent ( output , module , metadata , mr . Parent , genericContext , syntax ) ;
output . Write ( "::" ) ;
output . Write ( DisassemblerHelpers . Escape ( memberName ) ) ;
output . Write ( "(" ) ;
for ( int i = 0 ; i < methodSignature . ParameterTypes . Length ; + + i ) {
if ( i > 0 )
if ( i > 0 )
output . Write ( ", " ) ;
output . Write ( ", " ) ;
if ( i = = methodSignature . RequiredParameterCount )
methodSig . ParameterTypes [ i ] ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
output . Write ( "..., " ) ;
methodSignature . ParameterTypes [ i ] ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
}
}
output . Write ( ")" ) ;
output . Write ( ')' ) ;
break ;
case MemberReferenceKind . Field :
var fieldSignature = mr . DecodeFieldSignature ( new DisassemblerSignatureProvider ( module , output ) , genericContext ) ;
fieldSignature ( ILNameSyntax . SignatureNoNamedTypeParameters ) ;
output . Write ( ' ' ) ;
WriteParent ( output , module , metadata , mr . Parent , genericContext , syntax ) ;
output . Write ( "::" ) ;
output . Write ( DisassemblerHelpers . Escape ( memberName ) ) ;
break ;
break ;
case StandaloneSignatureKind . LocalVariables :
default :
throw new NotSupportedException ( ) ;
}
}
}
public static void WriteTo ( this Metadata . TypeReference typeRef , ITextOutput output , ILNameSyntax syntax = ILNameSyntax . Signature )
{
var metadata = typeRef . Module . GetMetadataReader ( ) ;
if ( ! typeRef . ResolutionScope . IsNil ) {
output . Write ( "[" ) ;
var currentTypeRef = typeRef ;
while ( currentTypeRef . ResolutionScope . Kind = = HandleKind . TypeReference ) {
currentTypeRef = new Metadata . TypeReference ( currentTypeRef . Module , ( TypeReferenceHandle ) currentTypeRef . ResolutionScope ) ;
}
switch ( currentTypeRef . ResolutionScope . Kind ) {
case HandleKind . ModuleDefinition :
var modDef = metadata . GetModuleDefinition ( ) ;
output . Write ( DisassemblerHelpers . Escape ( metadata . GetString ( modDef . Name ) ) ) ;
break ;
break ;
case HandleKind . ModuleReference :
default :
break ;
throw new NotSupportedException ( ) ;
case HandleKind . AssemblyReference :
var asmRef = metadata . GetAssemblyReference ( ( AssemblyReferenceHandle ) currentTypeRef . ResolutionScope ) ;
output . Write ( DisassemblerHelpers . Escape ( metadata . GetString ( asmRef . Name ) ) ) ;
break ;
}
output . Write ( "]" ) ;
}
output . WriteReference ( typeRef . FullName . ToILNameString ( ) , typeRef ) ;
}
}
public static void WriteTo ( this Metadata . TypeSpecification typeSpecification , ITextOutput output , GenericContext genericContext , ILNameSyntax syntax = ILNameSyntax . Signature )
{
var signature = typeSpecification . DecodeSignature ( new DisassemblerSignatureProvider ( typeSpecification . Module , output ) , genericContext ) ;
signature ( syntax ) ;
}
}
static void WriteParent ( ITextOutput output , PEFile module , MetadataReader metadata , EntityHandle parentHandle , GenericContext genericContext , ILNameSyntax syntax )
static void WriteParent ( ITextOutput output , PEFile module , MetadataReader metadata , EntityHandle parentHandle , GenericContext genericContext , ILNameSyntax syntax )
@ -344,7 +304,7 @@ namespace ICSharpCode.Decompiler.Disassembler
switch ( parentHandle . Kind ) {
switch ( parentHandle . Kind ) {
case HandleKind . MethodDefinition :
case HandleKind . MethodDefinition :
var methodDef = metadata . GetMethodDefinition ( ( MethodDefinitionHandle ) parentHandle ) ;
var methodDef = metadata . GetMethodDefinition ( ( MethodDefinitionHandle ) parentHandle ) ;
new Metadata . TypeDefinition ( module , methodDef . GetDeclaringType ( ) ) . WriteTo ( output , syntax ) ;
( ( EntityHandle ) methodDef . GetDeclaringType ( ) ) . WriteTo ( module , output , genericContex t , syntax ) ;
break ;
break ;
case HandleKind . ModuleReference :
case HandleKind . ModuleReference :
output . Write ( '[' ) ;
output . Write ( '[' ) ;
@ -353,87 +313,11 @@ namespace ICSharpCode.Decompiler.Disassembler
output . Write ( ']' ) ;
output . Write ( ']' ) ;
break ;
break ;
case HandleKind . TypeDefinition :
case HandleKind . TypeDefinition :
new Metadata . TypeDefinition ( module , ( TypeDefinitionHandle ) parentHandle ) . WriteTo ( output , syntax ) ;
break ;
case HandleKind . TypeReference :
case HandleKind . TypeReference :
new Metadata . TypeReference ( module , ( TypeReferenceHandle ) parentHandle ) . WriteTo ( output , syntax ) ;
break ;
case HandleKind . TypeSpecification :
case HandleKind . TypeSpecification :
new Metadata . TypeSpecification ( module , ( TypeSpecificationHandle ) parentHandle ) . WriteTo ( output , genericContext , syntax ) ;
parentHandle . WriteTo ( module , output , genericContext , syntax ) ;
break ;
break ;
}
}
}
}
/ *
public static bool IsBaseTypeOf ( this ITypeReference baseType , ITypeReference derivedType )
{
var derivedTypeDefinition = derivedType . GetDefinition ( ) ;
while ( ! derivedTypeDefinition . IsNil ) {
if ( derivedTypeDefinition . FullName = = baseType . FullName )
return true ;
derivedTypeDefinition = derivedTypeDefinition . BaseType . GetDefinition ( ) ;
}
return false ;
}
}
public class TypeUsedInSignature : ISignatureTypeProvider < bool , Unit >
{
readonly PEFile module ;
readonly Metadata . TypeDefinition type ;
public TypeUsedInSignature ( ITypeReference type )
{
this . module = type . Module ;
this . type = type . GetDefinition ( ) ;
}
public bool GetArrayType ( bool elementType , ArrayShape shape ) = > elementType ;
public bool GetByReferenceType ( bool elementType ) = > elementType ;
public bool GetFunctionPointerType ( MethodSignature < bool > signature )
{
throw new NotImplementedException ( ) ;
}
public bool GetGenericInstantiation ( bool genericType , ImmutableArray < bool > typeArguments )
{
throw new NotImplementedException ( ) ;
}
public bool GetGenericMethodParameter ( Unit genericContext , int index ) = > false ;
public bool GetGenericTypeParameter ( Unit genericContext , int index ) = > false ;
public bool GetModifiedType ( bool modifier , bool unmodifiedType , bool isRequired )
{
throw new NotImplementedException ( ) ;
}
public bool GetPinnedType ( bool elementType ) = > elementType ;
public bool GetPointerType ( bool elementType ) = > elementType ;
public bool GetPrimitiveType ( PrimitiveTypeCode typeCode )
{
throw new NotImplementedException ( ) ;
}
public bool GetSZArrayType ( bool elementType ) = > elementType ;
public bool GetTypeFromDefinition ( MetadataReader reader , TypeDefinitionHandle handle , byte rawTypeKind )
{
return module = = type . Module & & handle = = type . Handle ;
}
public bool GetTypeFromReference ( MetadataReader reader , TypeReferenceHandle handle , byte rawTypeKind )
{
return new Metadata . TypeReference ( module , handle ) . GetDefinition ( ) = = type ;
}
public bool GetTypeFromSpecification ( MetadataReader reader , Unit genericContext , TypeSpecificationHandle handle , byte rawTypeKind )
{
return new Metadata . TypeSpecification ( module , handle ) . GetDefinition ( ) = = type ;
} * /
}
}
}
}