mirror of https://github.com/icsharpcode/ILSpy.git
64 changed files with 3980 additions and 316 deletions
@ -1,6 +1,3 @@
@@ -1,6 +1,3 @@
|
||||
[submodule "cecil"] |
||||
path = cecil |
||||
url = https://github.com/jbevain/cecil.git |
||||
[submodule "ILSpy-tests"] |
||||
path = ILSpy-tests |
||||
url = https://github.com/icsharpcode/ILSpy-tests |
||||
|
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
using System; |
||||
|
||||
namespace Issue1157 |
||||
{ |
||||
internal abstract class BaseClass |
||||
{ |
||||
public abstract event EventHandler IDontKnowMeHereOut; |
||||
} |
||||
|
||||
internal class OtherClass : BaseClass |
||||
{ |
||||
public override event EventHandler IDontKnowMeHereOut; |
||||
} |
||||
} |
@ -0,0 +1,173 @@
@@ -0,0 +1,173 @@
|
||||
.assembly Issue1157 |
||||
{ |
||||
.hash algorithm 0x00008004 // SHA1 |
||||
.ver 1:0:0:0 |
||||
} |
||||
|
||||
.module Issue1157.exe |
||||
// MVID: {4C6C7F98-AEB2-4A19-BE6F-43171E6113F1} |
||||
.corflags 0x00020003 // ILOnly, Required32Bit, Preferred32Bit |
||||
|
||||
.class private auto ansi abstract beforefieldinit Issue1157.BaseClass |
||||
extends [mscorlib]System.Object |
||||
{ |
||||
// Methods |
||||
.method public hidebysig specialname newslot abstract virtual |
||||
instance void add_IDontKnowMeHereOut ( |
||||
class [mscorlib]System.EventHandler 'value' |
||||
) cil managed |
||||
{ |
||||
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( |
||||
01 00 00 00 |
||||
) |
||||
} // end of method BaseClass::add_IDontKnowMeHereOut |
||||
|
||||
.method public hidebysig specialname newslot abstract virtual |
||||
instance void remove_IDontKnowMeHereOut ( |
||||
class [mscorlib]System.EventHandler 'value' |
||||
) cil managed |
||||
{ |
||||
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( |
||||
01 00 00 00 |
||||
) |
||||
} // end of method BaseClass::remove_IDontKnowMeHereOut |
||||
|
||||
.method family hidebysig specialname rtspecialname |
||||
instance void .ctor () cil managed |
||||
{ |
||||
// Method begins at RVA 0x2063 |
||||
// Code size 8 (0x8) |
||||
.maxstack 8 |
||||
|
||||
IL_0000: ldarg.0 |
||||
IL_0001: call instance void [mscorlib]System.Object::.ctor() |
||||
IL_0006: nop |
||||
IL_0007: ret |
||||
} // end of method BaseClass::.ctor |
||||
|
||||
// Events |
||||
.event [mscorlib]System.EventHandler IDontKnowMeHereOut |
||||
{ |
||||
.addon instance void Issue1157.BaseClass::add_IDontKnowMeHereOut(class [mscorlib]System.EventHandler) |
||||
.removeon instance void Issue1157.BaseClass::remove_IDontKnowMeHereOut(class [mscorlib]System.EventHandler) |
||||
} |
||||
|
||||
|
||||
} // end of class Issue1157.BaseClass |
||||
|
||||
.class private auto ansi beforefieldinit Issue1157.OtherClass |
||||
extends Issue1157.BaseClass |
||||
{ |
||||
// Fields |
||||
.field private class [mscorlib]System.EventHandler IDontKnowMeHereOut |
||||
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( |
||||
01 00 00 00 |
||||
) |
||||
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( |
||||
01 00 00 00 00 00 00 00 |
||||
) |
||||
|
||||
// Methods |
||||
.method public hidebysig specialname virtual |
||||
instance void add_IDontKnowMeHereOut ( |
||||
class [mscorlib]System.EventHandler 'value' |
||||
) cil managed |
||||
{ |
||||
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( |
||||
01 00 00 00 |
||||
) |
||||
// Method begins at RVA 0x206c |
||||
// Code size 41 (0x29) |
||||
.maxstack 3 |
||||
.locals init ( |
||||
[0] class [mscorlib]System.EventHandler, |
||||
[1] class [mscorlib]System.EventHandler, |
||||
[2] class [mscorlib]System.EventHandler |
||||
) |
||||
|
||||
IL_0000: ldarg.0 |
||||
IL_0001: ldfld class [mscorlib]System.EventHandler Issue1157.OtherClass::IDontKnowMeHereOut |
||||
IL_0006: stloc.0 |
||||
// loop start (head: IL_0007) |
||||
IL_0007: ldloc.0 |
||||
IL_0008: stloc.1 |
||||
IL_0009: ldloc.1 |
||||
IL_000a: ldarg.1 |
||||
IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Combine(class [mscorlib]System.Delegate, class [mscorlib]System.Delegate) |
||||
IL_0010: castclass [mscorlib]System.EventHandler |
||||
IL_0015: stloc.2 |
||||
IL_0016: ldarg.0 |
||||
IL_0017: ldflda class [mscorlib]System.EventHandler Issue1157.OtherClass::IDontKnowMeHereOut |
||||
IL_001c: ldloc.2 |
||||
IL_001d: ldloc.1 |
||||
IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange<class [mscorlib]System.EventHandler>(!!0&, !!0, !!0) |
||||
IL_0023: stloc.0 |
||||
IL_0024: ldloc.0 |
||||
IL_0025: ldloc.1 |
||||
IL_0026: bne.un.s IL_0007 |
||||
// end loop |
||||
IL_0028: ret |
||||
} // end of method OtherClass::add_IDontKnowMeHereOut |
||||
|
||||
.method public hidebysig specialname virtual |
||||
instance void remove_IDontKnowMeHereOut ( |
||||
class [mscorlib]System.EventHandler 'value' |
||||
) cil managed |
||||
{ |
||||
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( |
||||
01 00 00 00 |
||||
) |
||||
// Method begins at RVA 0x20a4 |
||||
// Code size 41 (0x29) |
||||
.maxstack 3 |
||||
.locals init ( |
||||
[0] class [mscorlib]System.EventHandler, |
||||
[1] class [mscorlib]System.EventHandler, |
||||
[2] class [mscorlib]System.EventHandler |
||||
) |
||||
|
||||
IL_0000: ldarg.0 |
||||
IL_0001: ldfld class [mscorlib]System.EventHandler Issue1157.OtherClass::IDontKnowMeHereOut |
||||
IL_0006: stloc.0 |
||||
// loop start (head: IL_0007) |
||||
IL_0007: ldloc.0 |
||||
IL_0008: stloc.1 |
||||
IL_0009: ldloc.1 |
||||
IL_000a: ldarg.1 |
||||
IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Remove(class [mscorlib]System.Delegate, class [mscorlib]System.Delegate) |
||||
IL_0010: castclass [mscorlib]System.EventHandler |
||||
IL_0015: stloc.2 |
||||
IL_0016: ldarg.0 |
||||
IL_0017: ldflda class [mscorlib]System.EventHandler Issue1157.OtherClass::IDontKnowMeHereOut |
||||
IL_001c: ldloc.2 |
||||
IL_001d: ldloc.1 |
||||
IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange<class [mscorlib]System.EventHandler>(!!0&, !!0, !!0) |
||||
IL_0023: stloc.0 |
||||
IL_0024: ldloc.0 |
||||
IL_0025: ldloc.1 |
||||
IL_0026: bne.un.s IL_0007 |
||||
// end loop |
||||
IL_0028: ret |
||||
} // end of method OtherClass::remove_IDontKnowMeHereOut |
||||
|
||||
.method public hidebysig specialname rtspecialname |
||||
instance void .ctor () cil managed |
||||
{ |
||||
// Method begins at RVA 0x20d9 |
||||
// Code size 8 (0x8) |
||||
.maxstack 8 |
||||
|
||||
IL_0000: ldarg.0 |
||||
IL_0001: call instance void Issue1157.BaseClass::.ctor() |
||||
IL_0006: nop |
||||
IL_0007: ret |
||||
} // end of method OtherClass::.ctor |
||||
|
||||
// Events |
||||
.event [mscorlib]System.EventHandler IDontKnowMeHereOut |
||||
{ |
||||
.addon instance void Issue1157.OtherClass::add_IDontKnowMeHereOut(class [mscorlib]System.EventHandler) |
||||
.removeon instance void Issue1157.OtherClass::remove_IDontKnowMeHereOut(class [mscorlib]System.EventHandler) |
||||
} |
||||
|
||||
} // end of class Issue1157.OtherClass |
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
// Copyright (c) 2018 Daniel Grunwald
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty |
||||
{ |
||||
public class NamedArguments |
||||
{ |
||||
private class ClassWithNamedArgCtor |
||||
{ |
||||
internal ClassWithNamedArgCtor(bool arg1 = false, bool arg2 = false) |
||||
{ |
||||
} |
||||
|
||||
internal ClassWithNamedArgCtor() |
||||
: this(arg2: Get(1) != 1, arg1: Get(2) == 2) |
||||
{ |
||||
} |
||||
} |
||||
|
||||
public void Use(int a, int b, int c) |
||||
{ |
||||
} |
||||
|
||||
public static int Get(int i) |
||||
{ |
||||
return i; |
||||
} |
||||
|
||||
public void Test() |
||||
{ |
||||
Use(Get(1), Get(2), Get(3)); |
||||
Use(Get(1), c: Get(2), b: Get(3)); |
||||
Use(b: Get(1), a: Get(2), c: Get(3)); |
||||
} |
||||
|
||||
public void NotNamedArgs() |
||||
{ |
||||
int b = Get(1); |
||||
Use(Get(2), b, Get(3)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,193 @@
@@ -0,0 +1,193 @@
|
||||
|
||||
|
||||
|
||||
|
||||
// Metadata version: v4.0.30319 |
||||
.assembly extern mscorlib |
||||
{ |
||||
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. |
||||
.ver 4:0:0:0 |
||||
} |
||||
.assembly NamedArguments |
||||
{ |
||||
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) |
||||
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx |
||||
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. |
||||
.permissionset reqmin |
||||
= {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} |
||||
.hash algorithm 0x00008004 |
||||
.ver 0:0:0:0 |
||||
} |
||||
.module NamedArguments.dll |
||||
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) |
||||
.imagebase 0x10000000 |
||||
.file alignment 0x00000200 |
||||
.stackreserve 0x00100000 |
||||
.subsystem 0x0003 // WINDOWS_CUI |
||||
.corflags 0x00000001 // ILONLY |
||||
|
||||
|
||||
// =============== CLASS MEMBERS DECLARATION =================== |
||||
|
||||
.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments |
||||
extends [mscorlib]System.Object |
||||
{ |
||||
.class auto ansi nested private beforefieldinit ClassWithNamedArgCtor |
||||
extends [mscorlib]System.Object |
||||
{ |
||||
.method assembly hidebysig specialname rtspecialname |
||||
instance void .ctor([opt] bool arg1, |
||||
[opt] bool arg2) cil managed |
||||
{ |
||||
.param [1] = bool(false) |
||||
.param [2] = bool(false) |
||||
// Code size 10 (0xa) |
||||
.maxstack 8 |
||||
IL_0000: ldarg.0 |
||||
IL_0001: call instance void [mscorlib]System.Object::.ctor() |
||||
IL_0006: nop |
||||
IL_0007: nop |
||||
IL_0008: nop |
||||
IL_0009: ret |
||||
} // end of method ClassWithNamedArgCtor::.ctor |
||||
|
||||
.method assembly hidebysig specialname rtspecialname |
||||
instance void .ctor() cil managed |
||||
{ |
||||
// Code size 33 (0x21) |
||||
.maxstack 3 |
||||
.locals init (bool V_0) |
||||
IL_0000: ldarg.0 |
||||
IL_0001: ldc.i4.1 |
||||
IL_0002: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0007: ldc.i4.1 |
||||
IL_0008: ceq |
||||
IL_000a: ldc.i4.0 |
||||
IL_000b: ceq |
||||
IL_000d: stloc.0 |
||||
IL_000e: ldc.i4.2 |
||||
IL_000f: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0014: ldc.i4.2 |
||||
IL_0015: ceq |
||||
IL_0017: ldloc.0 |
||||
IL_0018: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments/ClassWithNamedArgCtor::.ctor(bool, |
||||
bool) |
||||
IL_001d: nop |
||||
IL_001e: nop |
||||
IL_001f: nop |
||||
IL_0020: ret |
||||
} // end of method ClassWithNamedArgCtor::.ctor |
||||
|
||||
} // end of class ClassWithNamedArgCtor |
||||
|
||||
.method public hidebysig instance void |
||||
Use(int32 a, |
||||
int32 b, |
||||
int32 c) cil managed |
||||
{ |
||||
// Code size 2 (0x2) |
||||
.maxstack 8 |
||||
IL_0000: nop |
||||
IL_0001: ret |
||||
} // end of method NamedArguments::Use |
||||
|
||||
.method public hidebysig static int32 Get(int32 i) cil managed |
||||
{ |
||||
// Code size 7 (0x7) |
||||
.maxstack 1 |
||||
.locals init (int32 V_0) |
||||
IL_0000: nop |
||||
IL_0001: ldarg.0 |
||||
IL_0002: stloc.0 |
||||
IL_0003: br.s IL_0005 |
||||
|
||||
IL_0005: ldloc.0 |
||||
IL_0006: ret |
||||
} // end of method NamedArguments::Get |
||||
|
||||
.method public hidebysig instance void |
||||
Test() cil managed |
||||
{ |
||||
// Code size 81 (0x51) |
||||
.maxstack 4 |
||||
.locals init (int32 V_0) |
||||
IL_0000: nop |
||||
IL_0001: ldarg.0 |
||||
IL_0002: ldc.i4.1 |
||||
IL_0003: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0008: ldc.i4.2 |
||||
IL_0009: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_000e: ldc.i4.3 |
||||
IL_000f: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0014: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Use(int32, |
||||
int32, |
||||
int32) |
||||
IL_0019: nop |
||||
IL_001a: ldarg.0 |
||||
IL_001b: ldc.i4.1 |
||||
IL_001c: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0021: ldc.i4.2 |
||||
IL_0022: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0027: stloc.0 |
||||
IL_0028: ldc.i4.3 |
||||
IL_0029: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_002e: ldloc.0 |
||||
IL_002f: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Use(int32, |
||||
int32, |
||||
int32) |
||||
IL_0034: nop |
||||
IL_0035: ldarg.0 |
||||
IL_0036: ldc.i4.1 |
||||
IL_0037: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_003c: stloc.0 |
||||
IL_003d: ldc.i4.2 |
||||
IL_003e: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0043: ldloc.0 |
||||
IL_0044: ldc.i4.3 |
||||
IL_0045: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_004a: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Use(int32, |
||||
int32, |
||||
int32) |
||||
IL_004f: nop |
||||
IL_0050: ret |
||||
} // end of method NamedArguments::Test |
||||
|
||||
.method public hidebysig instance void |
||||
NotNamedArgs() cil managed |
||||
{ |
||||
// Code size 29 (0x1d) |
||||
.maxstack 4 |
||||
.locals init (int32 V_0) |
||||
IL_0000: nop |
||||
IL_0001: ldc.i4.1 |
||||
IL_0002: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0007: stloc.0 |
||||
IL_0008: ldarg.0 |
||||
IL_0009: ldc.i4.2 |
||||
IL_000a: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_000f: ldloc.0 |
||||
IL_0010: ldc.i4.3 |
||||
IL_0011: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0016: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Use(int32, |
||||
int32, |
||||
int32) |
||||
IL_001b: nop |
||||
IL_001c: ret |
||||
} // end of method NamedArguments::NotNamedArgs |
||||
|
||||
.method public hidebysig specialname rtspecialname |
||||
instance void .ctor() cil managed |
||||
{ |
||||
// 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 NamedArguments::.ctor |
||||
|
||||
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments |
||||
|
||||
|
||||
// ============================================================= |
||||
|
||||
// *********** DISASSEMBLY COMPLETE *********************** |
@ -0,0 +1,175 @@
@@ -0,0 +1,175 @@
|
||||
|
||||
|
||||
|
||||
|
||||
// Metadata version: v4.0.30319 |
||||
.assembly extern mscorlib |
||||
{ |
||||
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. |
||||
.ver 4:0:0:0 |
||||
} |
||||
.assembly NamedArguments.opt |
||||
{ |
||||
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) |
||||
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx |
||||
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. |
||||
.permissionset reqmin |
||||
= {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} |
||||
.hash algorithm 0x00008004 |
||||
.ver 0:0:0:0 |
||||
} |
||||
.module NamedArguments.opt.dll |
||||
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) |
||||
.imagebase 0x10000000 |
||||
.file alignment 0x00000200 |
||||
.stackreserve 0x00100000 |
||||
.subsystem 0x0003 // WINDOWS_CUI |
||||
.corflags 0x00000001 // ILONLY |
||||
|
||||
|
||||
// =============== CLASS MEMBERS DECLARATION =================== |
||||
|
||||
.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments |
||||
extends [mscorlib]System.Object |
||||
{ |
||||
.class auto ansi nested private beforefieldinit ClassWithNamedArgCtor |
||||
extends [mscorlib]System.Object |
||||
{ |
||||
.method assembly hidebysig specialname rtspecialname |
||||
instance void .ctor([opt] bool arg1, |
||||
[opt] bool arg2) cil managed |
||||
{ |
||||
.param [1] = bool(false) |
||||
.param [2] = bool(false) |
||||
// 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 ClassWithNamedArgCtor::.ctor |
||||
|
||||
.method assembly hidebysig specialname rtspecialname |
||||
instance void .ctor() cil managed |
||||
{ |
||||
// Code size 30 (0x1e) |
||||
.maxstack 3 |
||||
.locals init (bool V_0) |
||||
IL_0000: ldarg.0 |
||||
IL_0001: ldc.i4.1 |
||||
IL_0002: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0007: ldc.i4.1 |
||||
IL_0008: ceq |
||||
IL_000a: ldc.i4.0 |
||||
IL_000b: ceq |
||||
IL_000d: stloc.0 |
||||
IL_000e: ldc.i4.2 |
||||
IL_000f: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0014: ldc.i4.2 |
||||
IL_0015: ceq |
||||
IL_0017: ldloc.0 |
||||
IL_0018: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments/ClassWithNamedArgCtor::.ctor(bool, |
||||
bool) |
||||
IL_001d: ret |
||||
} // end of method ClassWithNamedArgCtor::.ctor |
||||
|
||||
} // end of class ClassWithNamedArgCtor |
||||
|
||||
.method public hidebysig instance void |
||||
Use(int32 a, |
||||
int32 b, |
||||
int32 c) cil managed |
||||
{ |
||||
// Code size 1 (0x1) |
||||
.maxstack 8 |
||||
IL_0000: ret |
||||
} // end of method NamedArguments::Use |
||||
|
||||
.method public hidebysig static int32 Get(int32 i) cil managed |
||||
{ |
||||
// Code size 2 (0x2) |
||||
.maxstack 8 |
||||
IL_0000: ldarg.0 |
||||
IL_0001: ret |
||||
} // end of method NamedArguments::Get |
||||
|
||||
.method public hidebysig instance void |
||||
Test() cil managed |
||||
{ |
||||
// Code size 77 (0x4d) |
||||
.maxstack 4 |
||||
.locals init (int32 V_0, |
||||
int32 V_1) |
||||
IL_0000: ldarg.0 |
||||
IL_0001: ldc.i4.1 |
||||
IL_0002: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0007: ldc.i4.2 |
||||
IL_0008: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_000d: ldc.i4.3 |
||||
IL_000e: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0013: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Use(int32, |
||||
int32, |
||||
int32) |
||||
IL_0018: ldarg.0 |
||||
IL_0019: ldc.i4.1 |
||||
IL_001a: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_001f: ldc.i4.2 |
||||
IL_0020: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0025: stloc.0 |
||||
IL_0026: ldc.i4.3 |
||||
IL_0027: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_002c: ldloc.0 |
||||
IL_002d: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Use(int32, |
||||
int32, |
||||
int32) |
||||
IL_0032: ldarg.0 |
||||
IL_0033: ldc.i4.1 |
||||
IL_0034: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0039: stloc.1 |
||||
IL_003a: ldc.i4.2 |
||||
IL_003b: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0040: ldloc.1 |
||||
IL_0041: ldc.i4.3 |
||||
IL_0042: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0047: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Use(int32, |
||||
int32, |
||||
int32) |
||||
IL_004c: ret |
||||
} // end of method NamedArguments::Test |
||||
|
||||
.method public hidebysig instance void |
||||
NotNamedArgs() cil managed |
||||
{ |
||||
// Code size 27 (0x1b) |
||||
.maxstack 4 |
||||
.locals init (int32 V_0) |
||||
IL_0000: ldc.i4.1 |
||||
IL_0001: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0006: stloc.0 |
||||
IL_0007: ldarg.0 |
||||
IL_0008: ldc.i4.2 |
||||
IL_0009: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_000e: ldloc.0 |
||||
IL_000f: ldc.i4.3 |
||||
IL_0010: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0015: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Use(int32, |
||||
int32, |
||||
int32) |
||||
IL_001a: ret |
||||
} // end of method NamedArguments::NotNamedArgs |
||||
|
||||
.method public hidebysig specialname rtspecialname |
||||
instance void .ctor() cil managed |
||||
{ |
||||
// 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 NamedArguments::.ctor |
||||
|
||||
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments |
||||
|
||||
|
||||
// ============================================================= |
||||
|
||||
// *********** DISASSEMBLY COMPLETE *********************** |
@ -0,0 +1,178 @@
@@ -0,0 +1,178 @@
|
||||
|
||||
|
||||
|
||||
|
||||
// Metadata version: v4.0.30319 |
||||
.assembly extern mscorlib |
||||
{ |
||||
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. |
||||
.ver 4:0:0:0 |
||||
} |
||||
.assembly NamedArguments |
||||
{ |
||||
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) |
||||
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx |
||||
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. |
||||
|
||||
// --- The following custom attribute is added automatically, do not uncomment ------- |
||||
// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 ) |
||||
|
||||
.permissionset reqmin |
||||
= {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} |
||||
.hash algorithm 0x00008004 |
||||
.ver 0:0:0:0 |
||||
} |
||||
.module NamedArguments.dll |
||||
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) |
||||
.imagebase 0x10000000 |
||||
.file alignment 0x00000200 |
||||
.stackreserve 0x00100000 |
||||
.subsystem 0x0003 // WINDOWS_CUI |
||||
.corflags 0x00000001 // ILONLY |
||||
|
||||
|
||||
// =============== CLASS MEMBERS DECLARATION =================== |
||||
|
||||
.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments |
||||
extends [mscorlib]System.Object |
||||
{ |
||||
.class auto ansi nested private beforefieldinit ClassWithNamedArgCtor |
||||
extends [mscorlib]System.Object |
||||
{ |
||||
.method assembly hidebysig specialname rtspecialname |
||||
instance void .ctor([opt] bool arg1, |
||||
[opt] bool arg2) cil managed |
||||
{ |
||||
.param [1] = bool(false) |
||||
.param [2] = bool(false) |
||||
// 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 ClassWithNamedArgCtor::.ctor |
||||
|
||||
.method assembly hidebysig specialname rtspecialname |
||||
instance void .ctor() cil managed |
||||
{ |
||||
// Code size 30 (0x1e) |
||||
.maxstack 3 |
||||
.locals init (bool V_0) |
||||
IL_0000: ldarg.0 |
||||
IL_0001: ldc.i4.1 |
||||
IL_0002: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0007: ldc.i4.1 |
||||
IL_0008: ceq |
||||
IL_000a: ldc.i4.0 |
||||
IL_000b: ceq |
||||
IL_000d: stloc.0 |
||||
IL_000e: ldc.i4.2 |
||||
IL_000f: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0014: ldc.i4.2 |
||||
IL_0015: ceq |
||||
IL_0017: ldloc.0 |
||||
IL_0018: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments/ClassWithNamedArgCtor::.ctor(bool, |
||||
bool) |
||||
IL_001d: ret |
||||
} // end of method ClassWithNamedArgCtor::.ctor |
||||
|
||||
} // end of class ClassWithNamedArgCtor |
||||
|
||||
.method public hidebysig instance void |
||||
Use(int32 a, |
||||
int32 b, |
||||
int32 c) cil managed |
||||
{ |
||||
// Code size 1 (0x1) |
||||
.maxstack 8 |
||||
IL_0000: ret |
||||
} // end of method NamedArguments::Use |
||||
|
||||
.method public hidebysig static int32 Get(int32 i) cil managed |
||||
{ |
||||
// Code size 2 (0x2) |
||||
.maxstack 8 |
||||
IL_0000: ldarg.0 |
||||
IL_0001: ret |
||||
} // end of method NamedArguments::Get |
||||
|
||||
.method public hidebysig instance void |
||||
Test() cil managed |
||||
{ |
||||
// Code size 77 (0x4d) |
||||
.maxstack 4 |
||||
.locals init (int32 V_0) |
||||
IL_0000: ldarg.0 |
||||
IL_0001: ldc.i4.1 |
||||
IL_0002: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0007: ldc.i4.2 |
||||
IL_0008: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_000d: ldc.i4.3 |
||||
IL_000e: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0013: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Use(int32, |
||||
int32, |
||||
int32) |
||||
IL_0018: ldarg.0 |
||||
IL_0019: ldc.i4.1 |
||||
IL_001a: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_001f: ldc.i4.2 |
||||
IL_0020: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0025: stloc.0 |
||||
IL_0026: ldc.i4.3 |
||||
IL_0027: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_002c: ldloc.0 |
||||
IL_002d: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Use(int32, |
||||
int32, |
||||
int32) |
||||
IL_0032: ldarg.0 |
||||
IL_0033: ldc.i4.1 |
||||
IL_0034: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0039: stloc.0 |
||||
IL_003a: ldc.i4.2 |
||||
IL_003b: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0040: ldloc.0 |
||||
IL_0041: ldc.i4.3 |
||||
IL_0042: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0047: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Use(int32, |
||||
int32, |
||||
int32) |
||||
IL_004c: ret |
||||
} // end of method NamedArguments::Test |
||||
|
||||
.method public hidebysig instance void |
||||
NotNamedArgs() cil managed |
||||
{ |
||||
// Code size 27 (0x1b) |
||||
.maxstack 4 |
||||
.locals init (int32 V_0) |
||||
IL_0000: ldc.i4.1 |
||||
IL_0001: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0006: stloc.0 |
||||
IL_0007: ldarg.0 |
||||
IL_0008: ldc.i4.2 |
||||
IL_0009: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_000e: ldloc.0 |
||||
IL_000f: ldc.i4.3 |
||||
IL_0010: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0015: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Use(int32, |
||||
int32, |
||||
int32) |
||||
IL_001a: ret |
||||
} // end of method NamedArguments::NotNamedArgs |
||||
|
||||
.method public hidebysig specialname rtspecialname |
||||
instance void .ctor() cil managed |
||||
{ |
||||
// 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 NamedArguments::.ctor |
||||
|
||||
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments |
||||
|
||||
|
||||
// ============================================================= |
||||
|
||||
// *********** DISASSEMBLY COMPLETE *********************** |
@ -0,0 +1,196 @@
@@ -0,0 +1,196 @@
|
||||
|
||||
|
||||
|
||||
|
||||
// Metadata version: v4.0.30319 |
||||
.assembly extern mscorlib |
||||
{ |
||||
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. |
||||
.ver 4:0:0:0 |
||||
} |
||||
.assembly NamedArguments |
||||
{ |
||||
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) |
||||
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx |
||||
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. |
||||
|
||||
// --- The following custom attribute is added automatically, do not uncomment ------- |
||||
// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 ) |
||||
|
||||
.permissionset reqmin |
||||
= {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} |
||||
.hash algorithm 0x00008004 |
||||
.ver 0:0:0:0 |
||||
} |
||||
.module NamedArguments.dll |
||||
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) |
||||
.imagebase 0x10000000 |
||||
.file alignment 0x00000200 |
||||
.stackreserve 0x00100000 |
||||
.subsystem 0x0003 // WINDOWS_CUI |
||||
.corflags 0x00000001 // ILONLY |
||||
|
||||
|
||||
// =============== CLASS MEMBERS DECLARATION =================== |
||||
|
||||
.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments |
||||
extends [mscorlib]System.Object |
||||
{ |
||||
.class auto ansi nested private beforefieldinit ClassWithNamedArgCtor |
||||
extends [mscorlib]System.Object |
||||
{ |
||||
.method assembly hidebysig specialname rtspecialname |
||||
instance void .ctor([opt] bool arg1, |
||||
[opt] bool arg2) cil managed |
||||
{ |
||||
.param [1] = bool(false) |
||||
.param [2] = bool(false) |
||||
// Code size 9 (0x9) |
||||
.maxstack 8 |
||||
IL_0000: ldarg.0 |
||||
IL_0001: call instance void [mscorlib]System.Object::.ctor() |
||||
IL_0006: nop |
||||
IL_0007: nop |
||||
IL_0008: ret |
||||
} // end of method ClassWithNamedArgCtor::.ctor |
||||
|
||||
.method assembly hidebysig specialname rtspecialname |
||||
instance void .ctor() cil managed |
||||
{ |
||||
// Code size 32 (0x20) |
||||
.maxstack 3 |
||||
.locals init (bool V_0) |
||||
IL_0000: ldarg.0 |
||||
IL_0001: ldc.i4.1 |
||||
IL_0002: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0007: ldc.i4.1 |
||||
IL_0008: ceq |
||||
IL_000a: ldc.i4.0 |
||||
IL_000b: ceq |
||||
IL_000d: stloc.0 |
||||
IL_000e: ldc.i4.2 |
||||
IL_000f: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0014: ldc.i4.2 |
||||
IL_0015: ceq |
||||
IL_0017: ldloc.0 |
||||
IL_0018: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments/ClassWithNamedArgCtor::.ctor(bool, |
||||
bool) |
||||
IL_001d: nop |
||||
IL_001e: nop |
||||
IL_001f: ret |
||||
} // end of method ClassWithNamedArgCtor::.ctor |
||||
|
||||
} // end of class ClassWithNamedArgCtor |
||||
|
||||
.method public hidebysig instance void |
||||
Use(int32 a, |
||||
int32 b, |
||||
int32 c) cil managed |
||||
{ |
||||
// Code size 2 (0x2) |
||||
.maxstack 8 |
||||
IL_0000: nop |
||||
IL_0001: ret |
||||
} // end of method NamedArguments::Use |
||||
|
||||
.method public hidebysig static int32 Get(int32 i) cil managed |
||||
{ |
||||
// Code size 7 (0x7) |
||||
.maxstack 1 |
||||
.locals init (int32 V_0) |
||||
IL_0000: nop |
||||
IL_0001: ldarg.0 |
||||
IL_0002: stloc.0 |
||||
IL_0003: br.s IL_0005 |
||||
|
||||
IL_0005: ldloc.0 |
||||
IL_0006: ret |
||||
} // end of method NamedArguments::Get |
||||
|
||||
.method public hidebysig instance void |
||||
Test() cil managed |
||||
{ |
||||
// Code size 81 (0x51) |
||||
.maxstack 4 |
||||
.locals init (int32 V_0) |
||||
IL_0000: nop |
||||
IL_0001: ldarg.0 |
||||
IL_0002: ldc.i4.1 |
||||
IL_0003: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0008: ldc.i4.2 |
||||
IL_0009: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_000e: ldc.i4.3 |
||||
IL_000f: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0014: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Use(int32, |
||||
int32, |
||||
int32) |
||||
IL_0019: nop |
||||
IL_001a: ldarg.0 |
||||
IL_001b: ldc.i4.1 |
||||
IL_001c: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0021: ldc.i4.2 |
||||
IL_0022: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0027: stloc.0 |
||||
IL_0028: ldc.i4.3 |
||||
IL_0029: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_002e: ldloc.0 |
||||
IL_002f: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Use(int32, |
||||
int32, |
||||
int32) |
||||
IL_0034: nop |
||||
IL_0035: ldarg.0 |
||||
IL_0036: ldc.i4.1 |
||||
IL_0037: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_003c: stloc.0 |
||||
IL_003d: ldc.i4.2 |
||||
IL_003e: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0043: ldloc.0 |
||||
IL_0044: ldc.i4.3 |
||||
IL_0045: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_004a: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Use(int32, |
||||
int32, |
||||
int32) |
||||
IL_004f: nop |
||||
IL_0050: ret |
||||
} // end of method NamedArguments::Test |
||||
|
||||
.method public hidebysig instance void |
||||
NotNamedArgs() cil managed |
||||
{ |
||||
// Code size 29 (0x1d) |
||||
.maxstack 4 |
||||
.locals init (int32 V_0) |
||||
IL_0000: nop |
||||
IL_0001: ldc.i4.1 |
||||
IL_0002: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0007: stloc.0 |
||||
IL_0008: ldarg.0 |
||||
IL_0009: ldc.i4.2 |
||||
IL_000a: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_000f: ldloc.0 |
||||
IL_0010: ldc.i4.3 |
||||
IL_0011: call int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Get(int32) |
||||
IL_0016: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments::Use(int32, |
||||
int32, |
||||
int32) |
||||
IL_001b: nop |
||||
IL_001c: ret |
||||
} // end of method NamedArguments::NotNamedArgs |
||||
|
||||
.method public hidebysig specialname rtspecialname |
||||
instance void .ctor() cil managed |
||||
{ |
||||
// Code size 8 (0x8) |
||||
.maxstack 8 |
||||
IL_0000: ldarg.0 |
||||
IL_0001: call instance void [mscorlib]System.Object::.ctor() |
||||
IL_0006: nop |
||||
IL_0007: ret |
||||
} // end of method NamedArguments::.ctor |
||||
|
||||
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.NamedArguments |
||||
|
||||
|
||||
// ============================================================= |
||||
|
||||
// *********** DISASSEMBLY COMPLETE *********************** |
@ -0,0 +1,111 @@
@@ -0,0 +1,111 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using ICSharpCode.Decompiler.TypeSystem; |
||||
|
||||
namespace ICSharpCode.Decompiler.IL.Transforms |
||||
{ |
||||
using FindResult = ILInlining.FindResult; |
||||
|
||||
class NamedArgumentTransform : IStatementTransform |
||||
{ |
||||
public static FindResult CanIntroduceNamedArgument(CallInstruction call, ILInstruction child, ILVariable v, out ILInstruction loadInst) |
||||
{ |
||||
loadInst = null; |
||||
Debug.Assert(child.Parent == call); |
||||
if (call.IsInstanceCall && child.ChildIndex == 0) |
||||
return FindResult.Stop; // cannot use named arg to move expressionBeingMoved before this pointer
|
||||
if (call.Method.IsOperator || call.Method.IsAccessor) |
||||
return FindResult.Stop; // cannot use named arg for operators or accessors
|
||||
if (call.Method is VarArgInstanceMethod) |
||||
return FindResult.Stop; // CallBuilder doesn't support named args when using varargs
|
||||
if (call.Method.IsConstructor) { |
||||
IType type = call.Method.DeclaringType; |
||||
if (type.Kind == TypeKind.Delegate || type.IsAnonymousType()) |
||||
return FindResult.Stop; |
||||
} |
||||
if (call.Method.Parameters.Any(p => string.IsNullOrEmpty(p.Name))) |
||||
return FindResult.Stop; // cannot use named arguments
|
||||
for (int i = child.ChildIndex; i < call.Arguments.Count; i++) { |
||||
if (call.Arguments[i] is LdLoc ldloc && ldloc.Variable == v) { |
||||
loadInst = ldloc; |
||||
return FindResult.NamedArgument; |
||||
} |
||||
} |
||||
return FindResult.Stop; |
||||
} |
||||
|
||||
internal static FindResult CanExtendNamedArgument(Block block, ILVariable v, ILInstruction expressionBeingMoved, out ILInstruction loadInst) |
||||
{ |
||||
Debug.Assert(block.Kind == BlockKind.CallWithNamedArgs); |
||||
var firstArg = ((StLoc)block.Instructions[0]).Value; |
||||
var r = ILInlining.FindLoadInNext(firstArg, v, expressionBeingMoved, out loadInst); |
||||
if (r == FindResult.Found || r == FindResult.NamedArgument) { |
||||
return r; // OK, inline into first instruction of block
|
||||
} |
||||
var call = (CallInstruction)block.FinalInstruction; |
||||
if (call.IsInstanceCall) { |
||||
// For instance calls, block.Instructions[0] is the argument
|
||||
// for the 'this' pointer. We can only insert at position 1.
|
||||
if (r == FindResult.Stop) { |
||||
// error: can't move expressionBeingMoved after block.Instructions[0]
|
||||
return FindResult.Stop; |
||||
} |
||||
// Because we always ensure block.Instructions[0] is the 'this' argument,
|
||||
// it's possible that the place we actually need to inline into
|
||||
// is within block.Instructions[1]:
|
||||
if (block.Instructions.Count > 1) { |
||||
r = ILInlining.FindLoadInNext(block.Instructions[1], v, expressionBeingMoved, out loadInst); |
||||
if (r == FindResult.Found || r == FindResult.NamedArgument) { |
||||
return r; // OK, inline into block.Instructions[1]
|
||||
} |
||||
} |
||||
} |
||||
foreach (var arg in call.Arguments) { |
||||
if (arg.MatchLdLoc(v)) { |
||||
loadInst = arg; |
||||
return FindResult.NamedArgument; |
||||
} |
||||
} |
||||
return FindResult.Stop; |
||||
} |
||||
|
||||
internal static bool DoInline(ILVariable v, StLoc originalStore, LdLoc loadInst, InliningOptions options, ILTransformContext context) |
||||
{ |
||||
if ((options & InliningOptions.Aggressive) == 0 && originalStore.ILStackWasEmpty) |
||||
return false; |
||||
context.Step($"Introduce named argument '{v.Name}'", originalStore); |
||||
var call = (CallInstruction)loadInst.Parent; |
||||
if (!(call.Parent is Block namedArgBlock) || namedArgBlock.Kind != BlockKind.CallWithNamedArgs) { |
||||
// create namedArgBlock:
|
||||
namedArgBlock = new Block(BlockKind.CallWithNamedArgs); |
||||
call.ReplaceWith(namedArgBlock); |
||||
namedArgBlock.FinalInstruction = call; |
||||
if (call.IsInstanceCall) { |
||||
IType thisVarType = call.Method.DeclaringType; |
||||
if (CallInstruction.ExpectedTypeForThisPointer(thisVarType) == StackType.Ref) { |
||||
thisVarType = new ByReferenceType(thisVarType); |
||||
} |
||||
var function = call.Ancestors.OfType<ILFunction>().First(); |
||||
var thisArgVar = function.RegisterVariable(VariableKind.NamedArgument, thisVarType, "this_arg"); |
||||
namedArgBlock.Instructions.Add(new StLoc(thisArgVar, call.Arguments[0])); |
||||
call.Arguments[0] = new LdLoc(thisArgVar); |
||||
} |
||||
} |
||||
v.Kind = VariableKind.NamedArgument; |
||||
namedArgBlock.Instructions.Insert(call.IsInstanceCall ? 1 : 0, originalStore); |
||||
return true; |
||||
} |
||||
|
||||
public void Run(Block block, int pos, StatementTransformContext context) |
||||
{ |
||||
if (!context.Settings.NamedArguments) |
||||
return; |
||||
var options = ILInlining.OptionsForBlock(block); |
||||
options |= InliningOptions.IntroduceNamedArguments; |
||||
ILInlining.InlineOneIfPossible(block, pos, options, context: context); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
using VSLangProj; |
||||
|
||||
namespace ICSharpCode.ILSpy.AddIn.Commands |
||||
{ |
||||
/// <summary>
|
||||
/// Represents an assembly reference item in Solution Explorer, which can be opened in ILSpy.
|
||||
/// </summary>
|
||||
class AssemblyReferenceForILSpy |
||||
{ |
||||
Reference reference; |
||||
|
||||
AssemblyReferenceForILSpy(Reference reference) |
||||
{ |
||||
this.reference = reference; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Detects whether the given selected item represents a supported project.
|
||||
/// </summary>
|
||||
/// <param name="itemData">Data object of selected item to check.</param>
|
||||
/// <returns><see cref="AssemblyReferenceForILSpy"/> instance or <c>null</c>, if item is not a supported project.</returns>
|
||||
public static AssemblyReferenceForILSpy Detect(object itemData) |
||||
{ |
||||
return (itemData is Reference reference) ? new AssemblyReferenceForILSpy(reference) : null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// If possible retrieves parameters to use for launching ILSpy instance.
|
||||
/// </summary>
|
||||
/// <param name="projectReferences">List of current project's references.</param>
|
||||
/// <returns>Parameters object or <c>null, if not applicable.</c></returns>
|
||||
public ILSpyParameters GetILSpyParameters(Dictionary<string, string> projectReferences) |
||||
{ |
||||
if (projectReferences.TryGetValue(reference.Name, out var path)) |
||||
return new ILSpyParameters(new[] { path }); |
||||
|
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
using EnvDTE; |
||||
|
||||
namespace ICSharpCode.ILSpy.AddIn.Commands |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a NuGet package item in Solution Explorer, which can be opened in ILSpy.
|
||||
/// </summary>
|
||||
class NuGetReferenceForILSpy |
||||
{ |
||||
ProjectItem projectItem; |
||||
|
||||
NuGetReferenceForILSpy(ProjectItem projectItem) |
||||
{ |
||||
this.projectItem = projectItem; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Detects whether the given selected item represents a supported project.
|
||||
/// </summary>
|
||||
/// <param name="itemData">Data object of selected item to check.</param>
|
||||
/// <returns><see cref="NuGetReferenceForILSpy"/> instance or <c>null</c>, if item is not a supported project.</returns>
|
||||
public static NuGetReferenceForILSpy Detect(object itemData) |
||||
{ |
||||
if (itemData is ProjectItem projectItem) { |
||||
var properties = Utils.GetProperties(projectItem.Properties, "Type"); |
||||
if ((properties[0] as string) == "Package") { |
||||
return new NuGetReferenceForILSpy(projectItem); |
||||
} |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// If possible retrieves parameters to use for launching ILSpy instance.
|
||||
/// </summary>
|
||||
/// <returns>Parameters object or <c>null, if not applicable.</c></returns>
|
||||
public ILSpyParameters GetILSpyParameters() |
||||
{ |
||||
var properties = Utils.GetProperties(projectItem.Properties, "Name", "Version", "Path"); |
||||
if (properties[0] != null && properties[1] != null && properties[2] != null) { |
||||
return new ILSpyParameters(new[] { $"{properties[2]}\\{properties[0]}.{properties[1]}.nupkg" }); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
using System.IO; |
||||
using System.Linq; |
||||
using EnvDTE; |
||||
|
||||
namespace ICSharpCode.ILSpy.AddIn.Commands |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a project item in Solution Explorer, which can be opened in ILSpy.
|
||||
/// </summary>
|
||||
class ProjectItemForILSpy |
||||
{ |
||||
SelectedItem item; |
||||
Project project; |
||||
Microsoft.CodeAnalysis.Project roslynProject; |
||||
|
||||
ProjectItemForILSpy(Project project, Microsoft.CodeAnalysis.Project roslynProject, SelectedItem item) |
||||
{ |
||||
this.project = project; |
||||
this.roslynProject = roslynProject; |
||||
this.item = item; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Detects whether the given <see cref="SelectedItem"/> represents a supported project.
|
||||
/// </summary>
|
||||
/// <param name="item">Selected item to check.</param>
|
||||
/// <returns><see cref="ProjectItemForILSpy"/> instance or <c>null</c>, if item is not a supported project.</returns>
|
||||
public static ProjectItemForILSpy Detect(ILSpyAddInPackage package, SelectedItem item) |
||||
{ |
||||
var project = item.Project; |
||||
var roslynProject = package.Workspace.CurrentSolution.Projects.FirstOrDefault(p => p.FilePath == project.FileName); |
||||
if (roslynProject == null) |
||||
return null; |
||||
|
||||
return new ProjectItemForILSpy(project, roslynProject, item); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// If possible retrieves parameters to use for launching ILSpy instance.
|
||||
/// </summary>
|
||||
/// <param name="package">Package instance.</param>
|
||||
/// <returns>Parameters object or <c>null, if not applicable.</c></returns>
|
||||
public ILSpyParameters GetILSpyParameters(ILSpyAddInPackage package) |
||||
{ |
||||
return new ILSpyParameters(new[] { Utils.GetProjectOutputAssembly(project, roslynProject) }); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,78 @@
@@ -0,0 +1,78 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
using EnvDTE; |
||||
using Mono.Cecil; |
||||
|
||||
namespace ICSharpCode.ILSpy.AddIn.Commands |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a project reference item in Solution Explorer, which can be opened in ILSpy.
|
||||
/// </summary>
|
||||
class ProjectReferenceForILSpy |
||||
{ |
||||
ProjectItem projectItem; |
||||
string fusionName; |
||||
string resolvedPath; |
||||
|
||||
ProjectReferenceForILSpy(ProjectItem projectItem, string fusionName, string resolvedPath) |
||||
{ |
||||
this.projectItem = projectItem; |
||||
this.fusionName = fusionName; |
||||
this.resolvedPath = resolvedPath; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Detects whether the given selected item represents a supported project.
|
||||
/// </summary>
|
||||
/// <param name="itemData">Data object of selected item to check.</param>
|
||||
/// <returns><see cref="ProjectReferenceForILSpy"/> instance or <c>null</c>, if item is not a supported project.</returns>
|
||||
public static ProjectReferenceForILSpy Detect(object itemData) |
||||
{ |
||||
if (itemData is ProjectItem projectItem) { |
||||
var properties = Utils.GetProperties(projectItem.Properties, "FusionName", "ResolvedPath"); |
||||
string fusionName = properties[0] as string; |
||||
string resolvedPath = properties[1] as string; |
||||
if ((fusionName != null) || (resolvedPath != null)) { |
||||
return new ProjectReferenceForILSpy(projectItem, fusionName, resolvedPath); |
||||
} |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// If possible retrieves parameters to use for launching ILSpy instance.
|
||||
/// </summary>
|
||||
/// <param name="projectReferences">List of current project's references.</param>
|
||||
/// <returns>Parameters object or <c>null, if not applicable.</c></returns>
|
||||
public ILSpyParameters GetILSpyParameters(Dictionary<string, string> projectReferences) |
||||
{ |
||||
string fileName = projectItem.ContainingProject?.FileName; |
||||
if (!string.IsNullOrEmpty(fileName)) { |
||||
if (projectReferences.TryGetValue(projectItem.Name, out string path)) { |
||||
return new ILSpyParameters(new[] { path }); |
||||
} |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// If possible retrieves parameters to use for launching ILSpy instance.
|
||||
/// </summary>
|
||||
/// <returns>Parameters object or <c>null, if not applicable.</c></returns>
|
||||
public ILSpyParameters GetILSpyParameters() |
||||
{ |
||||
if (resolvedPath != null) { |
||||
return new ILSpyParameters(new[] { $"{resolvedPath}" }); |
||||
} else if (!string.IsNullOrWhiteSpace(fusionName)) { |
||||
return new ILSpyParameters(new string[] { GacInterop.FindAssemblyInNetGac(AssemblyNameReference.Parse(fusionName)) }); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,821 @@
@@ -0,0 +1,821 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Linq; |
||||
using System.Threading; |
||||
using Microsoft.CodeAnalysis.CSharp.Syntax; |
||||
using Microsoft.CodeAnalysis.Shared.Extensions; |
||||
using Microsoft.CodeAnalysis.Text; |
||||
using Roslyn.Utilities; |
||||
using Microsoft.CodeAnalysis; |
||||
using Microsoft.CodeAnalysis.CSharp; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace ICSharpCode.ILSpy.AddIn |
||||
{ |
||||
static class SyntaxNodeExtensions |
||||
{ |
||||
public static IEnumerable<SyntaxNode> GetAncestors(this SyntaxNode node) |
||||
{ |
||||
var current = node.Parent; |
||||
|
||||
while (current != null) |
||||
{ |
||||
yield return current; |
||||
|
||||
current = current is IStructuredTriviaSyntax |
||||
? ((IStructuredTriviaSyntax)current).ParentTrivia.Token.Parent |
||||
: current.Parent; |
||||
} |
||||
} |
||||
|
||||
public static IEnumerable<TNode> GetAncestors<TNode>(this SyntaxNode node) |
||||
where TNode : SyntaxNode |
||||
{ |
||||
var current = node.Parent; |
||||
while (current != null) |
||||
{ |
||||
if (current is TNode) |
||||
{ |
||||
yield return (TNode)current; |
||||
} |
||||
|
||||
current = current is IStructuredTriviaSyntax |
||||
? ((IStructuredTriviaSyntax)current).ParentTrivia.Token.Parent |
||||
: current.Parent; |
||||
} |
||||
} |
||||
|
||||
public static TNode GetAncestor<TNode>(this SyntaxNode node) |
||||
where TNode : SyntaxNode |
||||
{ |
||||
if (node == null) |
||||
{ |
||||
return default(TNode); |
||||
} |
||||
|
||||
return node.GetAncestors<TNode>().FirstOrDefault(); |
||||
} |
||||
|
||||
public static TNode GetAncestorOrThis<TNode>(this SyntaxNode node) |
||||
where TNode : SyntaxNode |
||||
{ |
||||
if (node == null) |
||||
{ |
||||
return default(TNode); |
||||
} |
||||
|
||||
return node.GetAncestorsOrThis<TNode>().FirstOrDefault(); |
||||
} |
||||
|
||||
public static IEnumerable<TNode> GetAncestorsOrThis<TNode>(this SyntaxNode node) |
||||
where TNode : SyntaxNode |
||||
{ |
||||
var current = node; |
||||
while (current != null) |
||||
{ |
||||
if (current is TNode) |
||||
{ |
||||
yield return (TNode)current; |
||||
} |
||||
|
||||
current = current is IStructuredTriviaSyntax |
||||
? ((IStructuredTriviaSyntax)current).ParentTrivia.Token.Parent |
||||
: current.Parent; |
||||
} |
||||
} |
||||
|
||||
public static bool HasAncestor<TNode>(this SyntaxNode node) |
||||
where TNode : SyntaxNode |
||||
{ |
||||
return node.GetAncestors<TNode>().Any(); |
||||
} |
||||
|
||||
public static bool CheckParent<T>(this SyntaxNode node, Func<T, bool> valueChecker) where T : SyntaxNode |
||||
{ |
||||
if (node == null) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
var parentNode = node.Parent as T; |
||||
if (parentNode == null) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
return valueChecker(parentNode); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns true if is a given token is a child token of of a certain type of parent node.
|
||||
/// </summary>
|
||||
/// <typeparam name="TParent">The type of the parent node.</typeparam>
|
||||
/// <param name="node">The node that we are testing.</param>
|
||||
/// <param name="childGetter">A function that, when given the parent node, returns the child token we are interested in.</param>
|
||||
public static bool IsChildNode<TParent>(this SyntaxNode node, Func<TParent, SyntaxNode> childGetter) |
||||
where TParent : SyntaxNode |
||||
{ |
||||
var ancestor = node.GetAncestor<TParent>(); |
||||
if (ancestor == null) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
var ancestorNode = childGetter(ancestor); |
||||
|
||||
return node == ancestorNode; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns true if this node is found underneath the specified child in the given parent.
|
||||
/// </summary>
|
||||
public static bool IsFoundUnder<TParent>(this SyntaxNode node, Func<TParent, SyntaxNode> childGetter) |
||||
where TParent : SyntaxNode |
||||
{ |
||||
var ancestor = node.GetAncestor<TParent>(); |
||||
if (ancestor == null) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
var child = childGetter(ancestor); |
||||
|
||||
// See if node passes through child on the way up to ancestor.
|
||||
return node.GetAncestorsOrThis<SyntaxNode>().Contains(child); |
||||
} |
||||
|
||||
public static SyntaxNode GetCommonRoot(this SyntaxNode node1, SyntaxNode node2) |
||||
{ |
||||
//Contract.ThrowIfTrue(node1.RawKind == 0 || node2.RawKind == 0);
|
||||
|
||||
// find common starting node from two nodes.
|
||||
// as long as two nodes belong to same tree, there must be at least one common root (Ex, compilation unit)
|
||||
var ancestors = node1.GetAncestorsOrThis<SyntaxNode>(); |
||||
var set = new HashSet<SyntaxNode>(node2.GetAncestorsOrThis<SyntaxNode>()); |
||||
|
||||
return ancestors.First(set.Contains); |
||||
} |
||||
|
||||
public static int Width(this SyntaxNode node) |
||||
{ |
||||
return node.Span.Length; |
||||
} |
||||
|
||||
public static int FullWidth(this SyntaxNode node) |
||||
{ |
||||
return node.FullSpan.Length; |
||||
} |
||||
|
||||
public static SyntaxNode FindInnermostCommonNode( |
||||
this IEnumerable<SyntaxNode> nodes, |
||||
Func<SyntaxNode, bool> predicate) |
||||
{ |
||||
IEnumerable<SyntaxNode> blocks = null; |
||||
foreach (var node in nodes) |
||||
{ |
||||
blocks = blocks == null |
||||
? node.AncestorsAndSelf().Where(predicate) |
||||
: blocks.Intersect(node.AncestorsAndSelf().Where(predicate)); |
||||
} |
||||
|
||||
return blocks == null ? null : blocks.First(); |
||||
} |
||||
|
||||
public static TSyntaxNode FindInnermostCommonNode<TSyntaxNode>(this IEnumerable<SyntaxNode> nodes) |
||||
where TSyntaxNode : SyntaxNode |
||||
{ |
||||
return (TSyntaxNode)nodes.FindInnermostCommonNode(n => n is TSyntaxNode); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// create a new root node from the given root after adding annotations to the tokens
|
||||
///
|
||||
/// tokens should belong to the given root
|
||||
/// </summary>
|
||||
public static SyntaxNode AddAnnotations(this SyntaxNode root, IEnumerable<Tuple<SyntaxToken, SyntaxAnnotation>> pairs) |
||||
{ |
||||
// Contract.ThrowIfNull(root);
|
||||
// Contract.ThrowIfNull(pairs);
|
||||
|
||||
var tokenMap = pairs.GroupBy(p => p.Item1, p => p.Item2).ToDictionary(g => g.Key, g => g.ToArray()); |
||||
return root.ReplaceTokens(tokenMap.Keys, (o, n) => o.WithAdditionalAnnotations(tokenMap[o])); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// create a new root node from the given root after adding annotations to the nodes
|
||||
///
|
||||
/// nodes should belong to the given root
|
||||
/// </summary>
|
||||
public static SyntaxNode AddAnnotations(this SyntaxNode root, IEnumerable<Tuple<SyntaxNode, SyntaxAnnotation>> pairs) |
||||
{ |
||||
// Contract.ThrowIfNull(root);
|
||||
// Contract.ThrowIfNull(pairs);
|
||||
|
||||
var tokenMap = pairs.GroupBy(p => p.Item1, p => p.Item2).ToDictionary(g => g.Key, g => g.ToArray()); |
||||
return root.ReplaceNodes(tokenMap.Keys, (o, n) => o.WithAdditionalAnnotations(tokenMap[o])); |
||||
} |
||||
|
||||
public static TextSpan GetContainedSpan(this IEnumerable<SyntaxNode> nodes) |
||||
{ |
||||
// Contract.ThrowIfNull(nodes);
|
||||
// Contract.ThrowIfFalse(nodes.Any());
|
||||
|
||||
TextSpan fullSpan = nodes.First().Span; |
||||
foreach (var node in nodes) |
||||
{ |
||||
fullSpan = TextSpan.FromBounds( |
||||
Math.Min(fullSpan.Start, node.SpanStart), |
||||
Math.Max(fullSpan.End, node.Span.End)); |
||||
} |
||||
|
||||
return fullSpan; |
||||
} |
||||
|
||||
public static IEnumerable<TextSpan> GetContiguousSpans( |
||||
this IEnumerable<SyntaxNode> nodes, Func<SyntaxNode, SyntaxToken> getLastToken = null) |
||||
{ |
||||
SyntaxNode lastNode = null; |
||||
TextSpan? textSpan = null; |
||||
foreach (var node in nodes) |
||||
{ |
||||
if (lastNode == null) |
||||
{ |
||||
textSpan = node.Span; |
||||
} |
||||
else |
||||
{ |
||||
var lastToken = getLastToken == null |
||||
? lastNode.GetLastToken() |
||||
: getLastToken(lastNode); |
||||
if (lastToken.GetNextToken(includeDirectives: true) == node.GetFirstToken()) |
||||
{ |
||||
// Expand the span
|
||||
textSpan = TextSpan.FromBounds(textSpan.Value.Start, node.Span.End); |
||||
} |
||||
else |
||||
{ |
||||
// Return the last span, and start a new one
|
||||
yield return textSpan.Value; |
||||
textSpan = node.Span; |
||||
} |
||||
} |
||||
|
||||
lastNode = node; |
||||
} |
||||
|
||||
if (textSpan.HasValue) |
||||
{ |
||||
yield return textSpan.Value; |
||||
} |
||||
} |
||||
|
||||
//public static bool OverlapsHiddenPosition(this SyntaxNode node, CancellationToken cancellationToken)
|
||||
//{
|
||||
// return node.OverlapsHiddenPosition(node.Span, cancellationToken);
|
||||
//}
|
||||
|
||||
//public static bool OverlapsHiddenPosition(this SyntaxNode node, TextSpan span, CancellationToken cancellationToken)
|
||||
//{
|
||||
// return node.SyntaxTree.OverlapsHiddenPosition(span, cancellationToken);
|
||||
//}
|
||||
|
||||
//public static bool OverlapsHiddenPosition(this SyntaxNode declaration, SyntaxNode startNode, SyntaxNode endNode, CancellationToken cancellationToken)
|
||||
//{
|
||||
// var start = startNode.Span.End;
|
||||
// var end = endNode.SpanStart;
|
||||
|
||||
// var textSpan = TextSpan.FromBounds(start, end);
|
||||
// return declaration.OverlapsHiddenPosition(textSpan, cancellationToken);
|
||||
//}
|
||||
|
||||
public static IEnumerable<T> GetAnnotatedNodes<T>(this SyntaxNode node, SyntaxAnnotation syntaxAnnotation) where T : SyntaxNode |
||||
{ |
||||
return node.GetAnnotatedNodesAndTokens(syntaxAnnotation).Select(n => n.AsNode()).OfType<T>(); |
||||
} |
||||
|
||||
public static bool IsKind(this SyntaxNode node, SyntaxKind kind1, SyntaxKind kind2) |
||||
{ |
||||
if (node == null) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
var csharpKind = node.Kind(); |
||||
return csharpKind == kind1 || csharpKind == kind2; |
||||
} |
||||
|
||||
public static bool IsKind(this SyntaxNode node, SyntaxKind kind1, SyntaxKind kind2, SyntaxKind kind3) |
||||
{ |
||||
if (node == null) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
var csharpKind = node.Kind(); |
||||
return csharpKind == kind1 || csharpKind == kind2 || csharpKind == kind3; |
||||
} |
||||
|
||||
public static bool IsKind(this SyntaxNode node, SyntaxKind kind1, SyntaxKind kind2, SyntaxKind kind3, SyntaxKind kind4) |
||||
{ |
||||
if (node == null) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
var csharpKind = node.Kind(); |
||||
return csharpKind == kind1 || csharpKind == kind2 || csharpKind == kind3 || csharpKind == kind4; |
||||
} |
||||
|
||||
public static bool IsKind(this SyntaxNode node, SyntaxKind kind1, SyntaxKind kind2, SyntaxKind kind3, SyntaxKind kind4, SyntaxKind kind5) |
||||
{ |
||||
if (node == null) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
var csharpKind = node.Kind(); |
||||
return csharpKind == kind1 || csharpKind == kind2 || csharpKind == kind3 || csharpKind == kind4 || csharpKind == kind5; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the list of using directives that affect <paramref name="node"/>. The list will be returned in
|
||||
/// top down order.
|
||||
/// </summary>
|
||||
public static IEnumerable<UsingDirectiveSyntax> GetEnclosingUsingDirectives(this SyntaxNode node) |
||||
{ |
||||
return node.GetAncestorOrThis<CompilationUnitSyntax>().Usings |
||||
.Concat(node.GetAncestorsOrThis<NamespaceDeclarationSyntax>() |
||||
.Reverse() |
||||
.SelectMany(n => n.Usings)); |
||||
} |
||||
|
||||
public static bool IsUnsafeContext(this SyntaxNode node) |
||||
{ |
||||
if (node.GetAncestor<UnsafeStatementSyntax>() != null) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
return node.GetAncestors<MemberDeclarationSyntax>().Any( |
||||
m => m.GetModifiers().Any(SyntaxKind.UnsafeKeyword)); |
||||
} |
||||
|
||||
public static bool IsInStaticContext(this SyntaxNode node) |
||||
{ |
||||
// this/base calls are always static.
|
||||
if (node.FirstAncestorOrSelf<ConstructorInitializerSyntax>() != null) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
var memberDeclaration = node.FirstAncestorOrSelf<MemberDeclarationSyntax>(); |
||||
if (memberDeclaration == null) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
switch (memberDeclaration.Kind()) |
||||
{ |
||||
case SyntaxKind.MethodDeclaration: |
||||
case SyntaxKind.ConstructorDeclaration: |
||||
case SyntaxKind.PropertyDeclaration: |
||||
case SyntaxKind.EventDeclaration: |
||||
case SyntaxKind.IndexerDeclaration: |
||||
return memberDeclaration.GetModifiers().Any(SyntaxKind.StaticKeyword); |
||||
|
||||
case SyntaxKind.FieldDeclaration: |
||||
// Inside a field one can only access static members of a type.
|
||||
return true; |
||||
|
||||
case SyntaxKind.DestructorDeclaration: |
||||
return false; |
||||
} |
||||
|
||||
// Global statements are not a static context.
|
||||
if (node.FirstAncestorOrSelf<GlobalStatementSyntax>() != null) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
// any other location is considered static
|
||||
return true; |
||||
} |
||||
|
||||
public static NamespaceDeclarationSyntax GetInnermostNamespaceDeclarationWithUsings(this SyntaxNode contextNode) |
||||
{ |
||||
var usingDirectiveAncsestor = contextNode.GetAncestor<UsingDirectiveSyntax>(); |
||||
if (usingDirectiveAncsestor == null) |
||||
{ |
||||
return contextNode.GetAncestorsOrThis<NamespaceDeclarationSyntax>().FirstOrDefault(n => n.Usings.Count > 0); |
||||
} |
||||
else |
||||
{ |
||||
// We are inside a using directive. In this case, we should find and return the first 'parent' namespace with usings.
|
||||
var containingNamespace = usingDirectiveAncsestor.GetAncestor<NamespaceDeclarationSyntax>(); |
||||
if (containingNamespace == null) |
||||
{ |
||||
// We are inside a top level using directive (i.e. one that's directly in the compilation unit).
|
||||
return null; |
||||
} |
||||
else |
||||
{ |
||||
return containingNamespace.GetAncestors<NamespaceDeclarationSyntax>().FirstOrDefault(n => n.Usings.Count > 0); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns all of the trivia to the left of this token up to the previous token (concatenates
|
||||
/// the previous token's trailing trivia and this token's leading trivia).
|
||||
/// </summary>
|
||||
public static IEnumerable<SyntaxTrivia> GetAllPrecedingTriviaToPreviousToken(this SyntaxToken token) |
||||
{ |
||||
var prevToken = token.GetPreviousToken(includeSkipped: true); |
||||
if (prevToken.Kind() == SyntaxKind.None) |
||||
{ |
||||
return token.LeadingTrivia; |
||||
} |
||||
|
||||
return prevToken.TrailingTrivia.Concat(token.LeadingTrivia); |
||||
} |
||||
|
||||
public static bool IsBreakableConstruct(this SyntaxNode node) |
||||
{ |
||||
switch (node.Kind()) |
||||
{ |
||||
case SyntaxKind.DoStatement: |
||||
case SyntaxKind.WhileStatement: |
||||
case SyntaxKind.SwitchStatement: |
||||
case SyntaxKind.ForStatement: |
||||
case SyntaxKind.ForEachStatement: |
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public static bool IsContinuableConstruct(this SyntaxNode node) |
||||
{ |
||||
switch (node.Kind()) |
||||
{ |
||||
case SyntaxKind.DoStatement: |
||||
case SyntaxKind.WhileStatement: |
||||
case SyntaxKind.ForStatement: |
||||
case SyntaxKind.ForEachStatement: |
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public static bool IsReturnableConstruct(this SyntaxNode node) |
||||
{ |
||||
switch (node.Kind()) |
||||
{ |
||||
case SyntaxKind.AnonymousMethodExpression: |
||||
case SyntaxKind.SimpleLambdaExpression: |
||||
case SyntaxKind.ParenthesizedLambdaExpression: |
||||
case SyntaxKind.MethodDeclaration: |
||||
case SyntaxKind.ConstructorDeclaration: |
||||
case SyntaxKind.DestructorDeclaration: |
||||
case SyntaxKind.GetAccessorDeclaration: |
||||
case SyntaxKind.SetAccessorDeclaration: |
||||
case SyntaxKind.OperatorDeclaration: |
||||
case SyntaxKind.AddAccessorDeclaration: |
||||
case SyntaxKind.RemoveAccessorDeclaration: |
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public static bool IsAnyArgumentList(this SyntaxNode node) |
||||
{ |
||||
return node.IsKind(SyntaxKind.ArgumentList) || |
||||
node.IsKind(SyntaxKind.AttributeArgumentList) || |
||||
node.IsKind(SyntaxKind.BracketedArgumentList) || |
||||
node.IsKind(SyntaxKind.TypeArgumentList); |
||||
} |
||||
|
||||
public static bool IsAnyLambda(this SyntaxNode node) |
||||
{ |
||||
return |
||||
node.IsKind(SyntaxKind.ParenthesizedLambdaExpression) || |
||||
node.IsKind(SyntaxKind.SimpleLambdaExpression); |
||||
} |
||||
|
||||
public static bool IsAnyLambdaOrAnonymousMethod(this SyntaxNode node) |
||||
{ |
||||
return node.IsAnyLambda() || node.IsKind(SyntaxKind.AnonymousMethodExpression); |
||||
} |
||||
|
||||
public static bool IsAnyAssignExpression(this SyntaxNode node) |
||||
{ |
||||
return SyntaxFacts.IsAssignmentExpression(node.Kind()); |
||||
} |
||||
|
||||
public static bool IsParentKind(this SyntaxNode node, SyntaxKind kind) |
||||
{ |
||||
return node != null && node.Parent.IsKind(kind); |
||||
} |
||||
|
||||
public static bool IsParentKind(this SyntaxToken node, SyntaxKind kind) |
||||
{ |
||||
return node.Parent != null && node.Parent.IsKind(kind); |
||||
} |
||||
|
||||
public static bool IsCompoundAssignExpression(this SyntaxNode node) |
||||
{ |
||||
switch (node.Kind()) |
||||
{ |
||||
case SyntaxKind.AddAssignmentExpression: |
||||
case SyntaxKind.SubtractAssignmentExpression: |
||||
case SyntaxKind.MultiplyAssignmentExpression: |
||||
case SyntaxKind.DivideAssignmentExpression: |
||||
case SyntaxKind.ModuloAssignmentExpression: |
||||
case SyntaxKind.AndAssignmentExpression: |
||||
case SyntaxKind.ExclusiveOrAssignmentExpression: |
||||
case SyntaxKind.OrAssignmentExpression: |
||||
case SyntaxKind.LeftShiftAssignmentExpression: |
||||
case SyntaxKind.RightShiftAssignmentExpression: |
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public static bool IsLeftSideOfAssignExpression(this SyntaxNode node) |
||||
{ |
||||
return node.IsParentKind(SyntaxKind.SimpleAssignmentExpression) && |
||||
((AssignmentExpressionSyntax)node.Parent).Left == node; |
||||
} |
||||
|
||||
public static bool IsLeftSideOfAnyAssignExpression(this SyntaxNode node) |
||||
{ |
||||
return node.Parent.IsAnyAssignExpression() && |
||||
((AssignmentExpressionSyntax)node.Parent).Left == node; |
||||
} |
||||
|
||||
public static bool IsRightSideOfAnyAssignExpression(this SyntaxNode node) |
||||
{ |
||||
return node.Parent.IsAnyAssignExpression() && |
||||
((AssignmentExpressionSyntax)node.Parent).Right == node; |
||||
} |
||||
|
||||
public static bool IsVariableDeclaratorValue(this SyntaxNode node) |
||||
{ |
||||
return |
||||
node.IsParentKind(SyntaxKind.EqualsValueClause) && |
||||
node.Parent.IsParentKind(SyntaxKind.VariableDeclarator) && |
||||
((EqualsValueClauseSyntax)node.Parent).Value == node; |
||||
} |
||||
|
||||
public static BlockSyntax FindInnermostCommonBlock(this IEnumerable<SyntaxNode> nodes) |
||||
{ |
||||
return nodes.FindInnermostCommonNode<BlockSyntax>(); |
||||
} |
||||
|
||||
public static IEnumerable<SyntaxNode> GetAncestorsOrThis(this SyntaxNode node, Func<SyntaxNode, bool> predicate) |
||||
{ |
||||
var current = node; |
||||
while (current != null) |
||||
{ |
||||
if (predicate(current)) |
||||
{ |
||||
yield return current; |
||||
} |
||||
|
||||
current = current.Parent; |
||||
} |
||||
} |
||||
|
||||
public static SyntaxNode GetParent(this SyntaxNode node) |
||||
{ |
||||
return node != null ? node.Parent : null; |
||||
} |
||||
|
||||
public static ValueTuple<SyntaxToken, SyntaxToken> GetBraces(this SyntaxNode node) |
||||
{ |
||||
var namespaceNode = node as NamespaceDeclarationSyntax; |
||||
if (namespaceNode != null) |
||||
{ |
||||
return ValueTuple.Create(namespaceNode.OpenBraceToken, namespaceNode.CloseBraceToken); |
||||
} |
||||
|
||||
var baseTypeNode = node as BaseTypeDeclarationSyntax; |
||||
if (baseTypeNode != null) |
||||
{ |
||||
return ValueTuple.Create(baseTypeNode.OpenBraceToken, baseTypeNode.CloseBraceToken); |
||||
} |
||||
|
||||
var accessorListNode = node as AccessorListSyntax; |
||||
if (accessorListNode != null) |
||||
{ |
||||
return ValueTuple.Create(accessorListNode.OpenBraceToken, accessorListNode.CloseBraceToken); |
||||
} |
||||
|
||||
var blockNode = node as BlockSyntax; |
||||
if (blockNode != null) |
||||
{ |
||||
return ValueTuple.Create(blockNode.OpenBraceToken, blockNode.CloseBraceToken); |
||||
} |
||||
|
||||
var switchStatementNode = node as SwitchStatementSyntax; |
||||
if (switchStatementNode != null) |
||||
{ |
||||
return ValueTuple.Create(switchStatementNode.OpenBraceToken, switchStatementNode.CloseBraceToken); |
||||
} |
||||
|
||||
var anonymousObjectCreationExpression = node as AnonymousObjectCreationExpressionSyntax; |
||||
if (anonymousObjectCreationExpression != null) |
||||
{ |
||||
return ValueTuple.Create(anonymousObjectCreationExpression.OpenBraceToken, anonymousObjectCreationExpression.CloseBraceToken); |
||||
} |
||||
|
||||
var initializeExpressionNode = node as InitializerExpressionSyntax; |
||||
if (initializeExpressionNode != null) |
||||
{ |
||||
return ValueTuple.Create(initializeExpressionNode.OpenBraceToken, initializeExpressionNode.CloseBraceToken); |
||||
} |
||||
|
||||
return new ValueTuple<SyntaxToken, SyntaxToken>(); |
||||
} |
||||
|
||||
public static SyntaxTokenList GetModifiers(this SyntaxNode member) |
||||
{ |
||||
if (member != null) |
||||
{ |
||||
switch (member.Kind()) |
||||
{ |
||||
case SyntaxKind.EnumDeclaration: |
||||
return ((EnumDeclarationSyntax)member).Modifiers; |
||||
case SyntaxKind.ClassDeclaration: |
||||
case SyntaxKind.InterfaceDeclaration: |
||||
case SyntaxKind.StructDeclaration: |
||||
return ((TypeDeclarationSyntax)member).Modifiers; |
||||
case SyntaxKind.DelegateDeclaration: |
||||
return ((DelegateDeclarationSyntax)member).Modifiers; |
||||
case SyntaxKind.FieldDeclaration: |
||||
return ((FieldDeclarationSyntax)member).Modifiers; |
||||
case SyntaxKind.EventFieldDeclaration: |
||||
return ((EventFieldDeclarationSyntax)member).Modifiers; |
||||
case SyntaxKind.ConstructorDeclaration: |
||||
return ((ConstructorDeclarationSyntax)member).Modifiers; |
||||
case SyntaxKind.DestructorDeclaration: |
||||
return ((DestructorDeclarationSyntax)member).Modifiers; |
||||
case SyntaxKind.PropertyDeclaration: |
||||
return ((PropertyDeclarationSyntax)member).Modifiers; |
||||
case SyntaxKind.EventDeclaration: |
||||
return ((EventDeclarationSyntax)member).Modifiers; |
||||
case SyntaxKind.IndexerDeclaration: |
||||
return ((IndexerDeclarationSyntax)member).Modifiers; |
||||
case SyntaxKind.OperatorDeclaration: |
||||
return ((OperatorDeclarationSyntax)member).Modifiers; |
||||
case SyntaxKind.ConversionOperatorDeclaration: |
||||
return ((ConversionOperatorDeclarationSyntax)member).Modifiers; |
||||
case SyntaxKind.MethodDeclaration: |
||||
return ((MethodDeclarationSyntax)member).Modifiers; |
||||
case SyntaxKind.GetAccessorDeclaration: |
||||
case SyntaxKind.SetAccessorDeclaration: |
||||
case SyntaxKind.AddAccessorDeclaration: |
||||
case SyntaxKind.RemoveAccessorDeclaration: |
||||
return ((AccessorDeclarationSyntax)member).Modifiers; |
||||
} |
||||
} |
||||
|
||||
return default(SyntaxTokenList); |
||||
} |
||||
|
||||
public static SyntaxNode WithModifiers(this SyntaxNode member, SyntaxTokenList modifiers) |
||||
{ |
||||
if (member != null) |
||||
{ |
||||
switch (member.Kind()) |
||||
{ |
||||
case SyntaxKind.EnumDeclaration: |
||||
return ((EnumDeclarationSyntax)member).WithModifiers(modifiers); |
||||
case SyntaxKind.ClassDeclaration: |
||||
case SyntaxKind.InterfaceDeclaration: |
||||
case SyntaxKind.StructDeclaration: |
||||
return ((TypeDeclarationSyntax)member).WithModifiers(modifiers); |
||||
case SyntaxKind.DelegateDeclaration: |
||||
return ((DelegateDeclarationSyntax)member).WithModifiers(modifiers); |
||||
case SyntaxKind.FieldDeclaration: |
||||
return ((FieldDeclarationSyntax)member).WithModifiers(modifiers); |
||||
case SyntaxKind.EventFieldDeclaration: |
||||
return ((EventFieldDeclarationSyntax)member).WithModifiers(modifiers); |
||||
case SyntaxKind.ConstructorDeclaration: |
||||
return ((ConstructorDeclarationSyntax)member).WithModifiers(modifiers); |
||||
case SyntaxKind.DestructorDeclaration: |
||||
return ((DestructorDeclarationSyntax)member).WithModifiers(modifiers); |
||||
case SyntaxKind.PropertyDeclaration: |
||||
return ((PropertyDeclarationSyntax)member).WithModifiers(modifiers); |
||||
case SyntaxKind.EventDeclaration: |
||||
return ((EventDeclarationSyntax)member).WithModifiers(modifiers); |
||||
case SyntaxKind.IndexerDeclaration: |
||||
return ((IndexerDeclarationSyntax)member).WithModifiers(modifiers); |
||||
case SyntaxKind.OperatorDeclaration: |
||||
return ((OperatorDeclarationSyntax)member).WithModifiers(modifiers); |
||||
case SyntaxKind.ConversionOperatorDeclaration: |
||||
return ((ConversionOperatorDeclarationSyntax)member).WithModifiers(modifiers); |
||||
case SyntaxKind.MethodDeclaration: |
||||
return ((MethodDeclarationSyntax)member).WithModifiers(modifiers); |
||||
case SyntaxKind.GetAccessorDeclaration: |
||||
case SyntaxKind.SetAccessorDeclaration: |
||||
case SyntaxKind.AddAccessorDeclaration: |
||||
case SyntaxKind.RemoveAccessorDeclaration: |
||||
return ((AccessorDeclarationSyntax)member).WithModifiers(modifiers); |
||||
} |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
public static TypeDeclarationSyntax WithModifiers( |
||||
this TypeDeclarationSyntax node, SyntaxTokenList modifiers) |
||||
{ |
||||
switch (node.Kind()) |
||||
{ |
||||
case SyntaxKind.ClassDeclaration: |
||||
return ((ClassDeclarationSyntax)node).WithModifiers(modifiers); |
||||
case SyntaxKind.InterfaceDeclaration: |
||||
return ((InterfaceDeclarationSyntax)node).WithModifiers(modifiers); |
||||
case SyntaxKind.StructDeclaration: |
||||
return ((StructDeclarationSyntax)node).WithModifiers(modifiers); |
||||
} |
||||
|
||||
throw new InvalidOperationException(); |
||||
} |
||||
|
||||
public static bool CheckTopLevel(this SyntaxNode node, TextSpan span) |
||||
{ |
||||
var block = node as BlockSyntax; |
||||
if (block != null) |
||||
{ |
||||
return block.ContainsInBlockBody(span); |
||||
} |
||||
|
||||
var field = node as FieldDeclarationSyntax; |
||||
if (field != null) |
||||
{ |
||||
foreach (var variable in field.Declaration.Variables) |
||||
{ |
||||
if (variable.Initializer != null && variable.Initializer.Span.Contains(span)) |
||||
{ |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
var global = node as GlobalStatementSyntax; |
||||
if (global != null) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
var constructorInitializer = node as ConstructorInitializerSyntax; |
||||
if (constructorInitializer != null) |
||||
{ |
||||
return constructorInitializer.ContainsInArgument(span); |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public static bool ContainsInArgument(this ConstructorInitializerSyntax initializer, TextSpan textSpan) |
||||
{ |
||||
if (initializer == null) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
return initializer.ArgumentList.Arguments.Any(a => a.Span.Contains(textSpan)); |
||||
} |
||||
|
||||
public static bool ContainsInBlockBody(this BlockSyntax block, TextSpan textSpan) |
||||
{ |
||||
if (block == null) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
var blockSpan = TextSpan.FromBounds(block.OpenBraceToken.Span.End, block.CloseBraceToken.SpanStart); |
||||
return blockSpan.Contains(textSpan); |
||||
} |
||||
|
||||
public static bool IsDelegateOrConstructorOrMethodParameterList(this SyntaxNode node) |
||||
{ |
||||
if (!node.IsKind(SyntaxKind.ParameterList)) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
return |
||||
node.IsParentKind(SyntaxKind.MethodDeclaration) || |
||||
node.IsParentKind(SyntaxKind.ConstructorDeclaration) || |
||||
node.IsParentKind(SyntaxKind.DelegateDeclaration); |
||||
} |
||||
|
||||
} |
||||
} |
@ -1,7 +1,7 @@
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<PackageManifest Version="2.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011"> |
||||
<Metadata> |
||||
<Identity Id="a9120dbe-164a-4891-842f-fb7829273838" Version="1.8.0.0" Language="en-US" Publisher="ic#code" /> |
||||
<Identity Id="a9120dbe-164a-4891-842f-fb7829273838" Version="$INSERTVERSION$" Language="en-US" Publisher="ic#code" /> |
||||
<DisplayName>ILSpy</DisplayName> |
||||
<Description xml:space="preserve">Integrates the ILSpy decompiler into Visual Studio.</Description> |
||||
<MoreInfo>http://www.ilspy.net</MoreInfo> |
Loading…
Reference in new issue