Browse Source

Merge pull request #706 from bbi-yoyo/dev.yggy.navigate-to-item

Fix "Open code in ILSpy" for overloaded methods with multi-dimensional array parameters.
pull/707/head
Siegfried Pammer 9 years ago
parent
commit
7e321f8eb0
  1. 40
      ILSpy.AddIn/CodeElementXmlDocKeyProvider.cs
  2. 14
      ILSpy.AddIn/Samples/ILSpyAddInSamples.cs

40
ILSpy.AddIn/CodeElementXmlDocKeyProvider.cs

@ -11,7 +11,7 @@ namespace ICSharpCode.ILSpy.AddIn
/// Used to support the "/navigateTo" command line option when opening ILSpy. Must match /// Used to support the "/navigateTo" command line option when opening ILSpy. Must match
/// the logic of ICSharpCode.ILSpy.XmlDoc.XmlDocKeyProvider, which does the same thing for /// the logic of ICSharpCode.ILSpy.XmlDoc.XmlDocKeyProvider, which does the same thing for
/// a Mono.Cecil.MemberReference. See "ID string format" in Appendix A of the C# language /// a Mono.Cecil.MemberReference. See "ID string format" in Appendix A of the C# language
/// specification for formatting requirements. /// specification for formatting requirements, and Samples/ILSpyAddInSamples.cs for examples.
/// </remarks> /// </remarks>
public static class CodeElementXmlDocKeyProvider public static class CodeElementXmlDocKeyProvider
{ {
@ -191,16 +191,44 @@ namespace ICSharpCode.ILSpy.AddIn
substringStart = i + 1; substringStart = i + 1;
b.Append('}'); b.Append('}');
break; break;
case '[': case '[':
case ']': AppendParameterTypeSubstring(b, parameterTypeString, substringStart, i, genericTypeParameters, genericMethodParameters);
b.Append('[');
// Skip ahead to the closing bracket, counting commas to determine array rank.
int rank = 1;
do {
++i;
ch = parameterTypeString[i];
if (ch == ',') {
++rank;
}
}
while (ch != ']');
substringStart = i + 1;
// For multi-dimensional arrays, add "0:" default array bounds. Note that non-standard bounds are not possible via C# declaration.
if (rank > 1) {
for (int r = 0; r < rank; ++r) {
if (r != 0) {
b.Append(',');
}
b.Append("0:");
}
}
b.Append(']');
break;
case ',': case ',':
AppendParameterTypeSubstring(b, parameterTypeString, substringStart, i, genericTypeParameters, genericMethodParameters); AppendParameterTypeSubstring(b, parameterTypeString, substringStart, i, genericTypeParameters, genericMethodParameters);
substringStart = i + 1; substringStart = i + 1;
// Skip space after comma if present. // Skip space after comma if present. (e.g. System.Collections.Generic.KeyValuePair`2{System.String,System.String}.)
if ((substringStart < parameterTypeString.Length) && (parameterTypeString[substringStart] == ' ')) { if (parameterTypeString[substringStart] == ' ') {
++substringStart; ++substringStart;
} }
b.Append(ch); b.Append(',');
break; break;
} }
} }
@ -214,7 +242,7 @@ namespace ICSharpCode.ILSpy.AddIn
} }
// Note there is no need to append a '*' for pointers, as this is included in the full name of the type. // Note there is no need to append a '*' for pointers, as this is included in the full name of the type.
// Multi-dimensional and nested arrays are also captured in the full name of the type. // Multi-dimensional and jagged arrays are handled above during string parsing.
} }
private static void AppendParameterTypeSubstring(StringBuilder b, string parameterTypeString, int substringStart, int substringStop, string[] genericTypeParameters, string[] genericMethodParameters) private static void AppendParameterTypeSubstring(StringBuilder b, string parameterTypeString, int substringStart, int substringStop, string[] genericTypeParameters, string[] genericMethodParameters)

14
ILSpy.AddIn/Samples/ILSpyAddInSamples.cs

@ -331,12 +331,12 @@ namespace ILSpy.AddIn.Tests
{ {
} }
// NOT? M:ILSpy.AddIn.Tests.SomeGenericClass`2.ArrayMethod(`0[,],System.Int32[,]) // M:ILSpy.AddIn.Tests.SomeGenericClass`2.ArrayMethod(`0[0:,0:],System.Int32[0:,0:])
public void ArrayMethod(T1[,] x, int[,] y) public void ArrayMethod(T1[,] x, int[,] y)
{ {
} }
// NOT? M:ILSpy.AddIn.Tests.SomeGenericClass`2.ArrayMethod(System.Int32[,],System.Int32[,]) // M:ILSpy.AddIn.Tests.SomeGenericClass`2.ArrayMethod(System.Int32[0:,0:],System.Int32[0:,0:])
public void ArrayMethod(int[,] x, int[,] y) public void ArrayMethod(int[,] x, int[,] y)
{ {
} }
@ -349,27 +349,21 @@ namespace ILSpy.AddIn.Tests
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassGenericMethod``2(`0,``0,ILSpy.AddIn.Tests.SomeClass) // M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassGenericMethod``2(`0,``0,ILSpy.AddIn.Tests.SomeClass)
public T3 GenericClassGenericMethod<T3, T4>(T1 x, T3 y, SomeClass z) public T3 GenericClassGenericMethod<T3, T4>(T1 x, T3 y, SomeClass z)
{ {
mField1 = x;
string foo = y.ToString() + z.ToString();
return y; return y;
} }
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassGenericMethod``2(`0,``0,ILSpy.AddIn.Tests.SomeClass[]@) // M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassGenericMethod``2(`0,``0,ILSpy.AddIn.Tests.SomeClass[]@)
public T3 GenericClassGenericMethod<T3, T4>(T1 x, T3 y, out SomeClass[] z) public T3 GenericClassGenericMethod<T3, T4>(T1 x, T3 y, out SomeClass[] z)
{ {
mField1 = x;
z = null; z = null;
string foo = y.ToString() + z.ToString();
return y; return y;
} }
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassGenericMethod``2(System.Int32[],ILSpy.AddIn.Tests.SomeGenericClass{``0,``1}) // M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassGenericMethod``2(System.Int32[],ILSpy.AddIn.Tests.SomeGenericClass{``0[],``1[0:,0:,0:]}[0:,0:,0:])
public void GenericClassGenericMethod<T3, T4>(int[] x, SomeGenericClass<T3, T4> y) public void GenericClassGenericMethod<T3, T4>(int[] x, SomeGenericClass<T3[], T4[,,]>[,,] y)
{ {
string foo = x.ToString() + y.ToString();
} }
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.op_Addition(ILSpy.AddIn.Tests.SomeGenericClass{`0,`1},ILSpy.AddIn.Tests.SomeGenericClass{`0,`1}) // M:ILSpy.AddIn.Tests.SomeGenericClass`2.op_Addition(ILSpy.AddIn.Tests.SomeGenericClass{`0,`1},ILSpy.AddIn.Tests.SomeGenericClass{`0,`1})
public static SomeGenericClass<T1, T2> operator +(SomeGenericClass<T1, T2> a, SomeGenericClass<T1, T2> b) public static SomeGenericClass<T1, T2> operator +(SomeGenericClass<T1, T2> a, SomeGenericClass<T1, T2> b)
{ {

Loading…
Cancel
Save