Browse Source

Merge pull request #2903 from ltrzesniewski/interfaceimpl

Use `.interfaceimpl type` syntax
pull/2934/head
Daniel Grunwald 2 years ago committed by GitHub
parent
commit
52bab53294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .gitignore
  2. 6
      ICSharpCode.Decompiler.Tests/DisassemblerPrettyTestRunner.cs
  3. 1
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  4. 75
      ICSharpCode.Decompiler.Tests/TestCases/Disassembler/Pretty/InterfaceImplAttributes.il
  5. 14
      ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs
  6. 6
      ILSpy/TextView/ILAsm-Mode-Dark.xshd
  7. 6
      ILSpy/TextView/ILAsm-Mode.xshd

1
.gitignore vendored

@ -8,6 +8,7 @@ _ReSharper*/ @@ -8,6 +8,7 @@ _ReSharper*/
*.ReSharper
*.patch
.vs/
.idea/
/ILSpy.AddIn*/Packages/*
/ILSpy.AddIn*/source.extension.vsixmanifest
/ICSharpCode.Decompiler.Tests/TestCases/Disassembler/Pretty/*.dll

6
ICSharpCode.Decompiler.Tests/DisassemblerPrettyTestRunner.cs

@ -64,6 +64,12 @@ namespace ICSharpCode.Decompiler.Tests @@ -64,6 +64,12 @@ namespace ICSharpCode.Decompiler.Tests
await Run(ilExpectedFile: Path.Combine(TestCasePath, "SortMembers.expected.il"), asmOptions: AssemblerOptions.SortedOutput);
}
[Test]
public async Task InterfaceImplAttributes()
{
await Run();
}
async Task Run([CallerMemberName] string testName = null, string ilExpectedFile = null, AssemblerOptions asmOptions = AssemblerOptions.None)
{
var ilInputFile = Path.Combine(TestCasePath, testName + ".il");

1
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -73,6 +73,7 @@ @@ -73,6 +73,7 @@
<None Include="TestCases\Correctness\StackTests.il" />
<None Include="TestCases\Correctness\StackTypes.il" />
<None Include="TestCases\Correctness\Uninit.vb" />
<None Include="TestCases\Disassembler\Pretty\InterfaceImplAttributes.il" />
<None Include="TestCases\Disassembler\Pretty\SortMembers.expected.il" />
<None Include="TestCases\Disassembler\Pretty\SortMembers.il" />
<None Include="TestCases\ILPretty\GuessAccessors.cs" />

75
ICSharpCode.Decompiler.Tests/TestCases/Disassembler/Pretty/InterfaceImplAttributes.il

@ -0,0 +1,75 @@ @@ -0,0 +1,75 @@
.assembly extern mscorlib
{
.publickeytoken = (
b7 7a 5c 56 19 34 e0 89
)
.ver 4:0:0:0
}
.assembly InterfaceImplAttributes
{
.custom instance void [mscorlib]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = (
01 00 07 31 2e 30 2e 30 2e 30 00 00
)
.hash algorithm 0x00008004 // SHA1
.ver 1:0:0:0
}
.module InterfaceImplAttributes.dll
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WindowsCui
.corflags 0x00000001 // ILOnly
.class private auto ansi '<Module>'
{
} // end of class <Module>
.class public auto ansi beforefieldinit TestType
extends [mscorlib]System.Object
implements ITestInterfaceA
{
.interfaceimpl type ITestInterfaceA
.custom instance void TestAttributeA::.ctor() = (
01 00 00 00
)
// Methods
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
// Method begins at RVA 0x2050
// Header size: 1
// Code size: 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method TestType::.ctor
} // end of class TestType
.class interface public auto ansi abstract ITestInterfaceA
{
} // end of class ITestInterfaceA
.class public auto ansi beforefieldinit TestAttributeA
extends [mscorlib]System.Attribute
{
// Methods
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
// Method begins at RVA 0x2058
// Header size: 1
// Code size: 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Attribute::.ctor()
IL_0006: ret
} // end of method TestAttributeA::.ctor
} // end of class TestAttributeA

14
ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs

@ -1577,7 +1577,6 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -1577,7 +1577,6 @@ namespace ICSharpCode.Decompiler.Disassembler
output.Write(" ");
first = false;
var iface = module.Metadata.GetInterfaceImplementation(i);
WriteAttributes(module, iface.GetCustomAttributes());
iface.Interface.WriteTo(module, output, genericContext, ILNameSyntax.TypeName);
}
output.WriteLine();
@ -1601,6 +1600,19 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -1601,6 +1600,19 @@ namespace ICSharpCode.Decompiler.Disassembler
output.WriteLine(".size {0}", layout.Size);
output.WriteLine();
}
foreach (var ifaceHandle in interfaces)
{
var iface = module.Metadata.GetInterfaceImplementation(ifaceHandle);
var customAttributes = iface.GetCustomAttributes();
if (customAttributes.Count != 0)
{
output.Write(".interfaceimpl type ");
iface.Interface.WriteTo(module, output, genericContext, ILNameSyntax.TypeName);
output.WriteLine();
WriteAttributes(module, customAttributes);
output.WriteLine();
}
}
var nestedTypes = Process(module, typeDefinition.GetNestedTypes());
if (nestedTypes.Any())
{

6
ILSpy/TextView/ILAsm-Mode-Dark.xshd

@ -356,6 +356,7 @@ @@ -356,6 +356,7 @@
<Word>true</Word>
<Word>false</Word>
<Word>strict</Word>
<Word>type</Word>
</Keywords>
<Keywords color="Directives">
<Word>.class</Word>
@ -385,6 +386,7 @@ @@ -385,6 +386,7 @@
<Word>.permissionset</Word>
<Word>.line</Word>
<Word>.language</Word>
<Word>.interfaceimpl</Word>
<Word>#line</Word>
</Keywords>
<Keywords color="Security">
@ -516,6 +518,10 @@ @@ -516,6 +518,10 @@
<Begin>"</Begin>
<End>"</End>
</Span>
<Span>
<Begin>'</Begin>
<End>'</End>
</Span>
</RuleSet>
<RuleSet name="CommentMarkerSet" ignoreCase="false">
<Keywords foreground="#FFFF0000" fontWeight="bold">

6
ILSpy/TextView/ILAsm-Mode.xshd

@ -356,6 +356,7 @@ @@ -356,6 +356,7 @@
<Word>true</Word>
<Word>false</Word>
<Word>strict</Word>
<Word>type</Word>
</Keywords>
<Keywords color="Directives">
<Word>.class</Word>
@ -385,6 +386,7 @@ @@ -385,6 +386,7 @@
<Word>.permissionset</Word>
<Word>.line</Word>
<Word>.language</Word>
<Word>.interfaceimpl</Word>
<Word>#line</Word>
</Keywords>
<Keywords color="Security">
@ -516,6 +518,10 @@ @@ -516,6 +518,10 @@
<Begin>"</Begin>
<End>"</End>
</Span>
<Span>
<Begin>'</Begin>
<End>'</End>
</Span>
</RuleSet>
<RuleSet name="CommentMarkerSet" ignoreCase="false">
<Keywords foreground="#FFFF0000" fontWeight="bold">

Loading…
Cancel
Save