mirror of https://github.com/icsharpcode/ILSpy.git
8 changed files with 321 additions and 27 deletions
@ -0,0 +1,168 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Text; |
||||||
|
using Mono.Cecil; |
||||||
|
|
||||||
|
namespace ICSharpCode.ILSpy |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Provides XML documentation tags.
|
||||||
|
/// </summary>
|
||||||
|
sealed class XmlDocKeyProvider |
||||||
|
{ |
||||||
|
#region GetKey
|
||||||
|
public static string GetKey(MemberReference member) |
||||||
|
{ |
||||||
|
StringBuilder b = new StringBuilder(); |
||||||
|
if (member is TypeReference) { |
||||||
|
b.Append("T:"); |
||||||
|
AppendTypeName(b, (TypeDefinition)member); |
||||||
|
} else { |
||||||
|
if (member is FieldReference) |
||||||
|
b.Append("F:"); |
||||||
|
else if (member is PropertyDefinition) |
||||||
|
b.Append("P:"); |
||||||
|
else if (member is EventDefinition) |
||||||
|
b.Append("E:"); |
||||||
|
else if (member is MethodReference) |
||||||
|
b.Append("M:"); |
||||||
|
AppendTypeName(b, member.DeclaringType); |
||||||
|
b.Append('.'); |
||||||
|
b.Append(member.Name); |
||||||
|
IList<ParameterDefinition> parameters; |
||||||
|
if (member is PropertyDefinition) { |
||||||
|
parameters = ((PropertyDefinition)member).Parameters; |
||||||
|
} else if (member is MethodReference) { |
||||||
|
parameters = ((MethodReference)member).Parameters; |
||||||
|
} else { |
||||||
|
parameters = null; |
||||||
|
} |
||||||
|
if (parameters != null && parameters.Count > 0) { |
||||||
|
b.Append('('); |
||||||
|
for (int i = 0; i < parameters.Count; i++) { |
||||||
|
if (i > 0) b.Append(','); |
||||||
|
AppendTypeName(b, parameters[i].ParameterType); |
||||||
|
} |
||||||
|
b.Append(')'); |
||||||
|
} |
||||||
|
} |
||||||
|
return b.ToString(); |
||||||
|
} |
||||||
|
|
||||||
|
static void AppendTypeName(StringBuilder b, TypeReference type) |
||||||
|
{ |
||||||
|
if (type is TypeSpecification) { |
||||||
|
AppendTypeName(b, ((TypeSpecification)type).ElementType); |
||||||
|
ArrayType arrayType = type as ArrayType; |
||||||
|
if (arrayType != null) { |
||||||
|
b.Append('['); |
||||||
|
for (int i = 1; i < arrayType.Dimensions.Count; i++) { |
||||||
|
b.Append(','); |
||||||
|
} |
||||||
|
b.Append(']'); |
||||||
|
} |
||||||
|
ByReferenceType refType = type as ByReferenceType; |
||||||
|
if (refType != null) { |
||||||
|
b.Append('@'); |
||||||
|
} |
||||||
|
GenericInstanceType giType = type as GenericInstanceType; |
||||||
|
if (giType != null) { |
||||||
|
b.Append('{'); |
||||||
|
for (int i = 0; i < giType.GenericArguments.Count; i++) { |
||||||
|
if (i > 0) b.Append(','); |
||||||
|
AppendTypeName(b, giType.GenericArguments[i]); |
||||||
|
} |
||||||
|
b.Append('}'); |
||||||
|
} |
||||||
|
PointerType ptrType = type as PointerType; |
||||||
|
if (ptrType != null) { |
||||||
|
b.Append('*'); // TODO: is this correct?
|
||||||
|
} |
||||||
|
} else { |
||||||
|
GenericParameter gp = type as GenericParameter; |
||||||
|
if (gp != null) { |
||||||
|
b.Append('`'); |
||||||
|
if (gp.Owner.GenericParameterType == GenericParameterType.Method) { |
||||||
|
b.Append('`'); |
||||||
|
} |
||||||
|
b.Append(gp.Position); |
||||||
|
} else if (type.DeclaringType != null) { |
||||||
|
AppendTypeName(b, type.DeclaringType); |
||||||
|
b.Append('.'); |
||||||
|
b.Append(type.Name); |
||||||
|
} else { |
||||||
|
b.Append(type.FullName); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region FindMemberByKey
|
||||||
|
public static MemberReference FindMemberByKey(ModuleDefinition module, string key) |
||||||
|
{ |
||||||
|
if (module == null) |
||||||
|
throw new ArgumentNullException("module"); |
||||||
|
if (key == null || key.Length < 2 || key[1] != ':') |
||||||
|
return null; |
||||||
|
switch (key[0]) { |
||||||
|
case 'T': |
||||||
|
return FindType(module, key.Substring(2)); |
||||||
|
case 'F': |
||||||
|
return FindMember(module, key, type => type.Fields); |
||||||
|
case 'P': |
||||||
|
return FindMember(module, key, type => type.Properties); |
||||||
|
case 'E': |
||||||
|
return FindMember(module, key, type => type.Events); |
||||||
|
case 'M': |
||||||
|
return FindMember(module, key, type => type.Methods); |
||||||
|
default: |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static MemberReference FindMember(ModuleDefinition module, string key, Func<TypeDefinition, IEnumerable<MemberReference>> memberSelector) |
||||||
|
{ |
||||||
|
int pos = key.IndexOf('('); |
||||||
|
int dotPos; |
||||||
|
if (pos > 0) { |
||||||
|
dotPos = key.LastIndexOf('.', 0, pos); |
||||||
|
} else { |
||||||
|
dotPos = key.LastIndexOf('.'); |
||||||
|
} |
||||||
|
TypeDefinition type = FindType(module, key.Substring(2, dotPos - 2)); |
||||||
|
if (type == null) |
||||||
|
return null; |
||||||
|
foreach (MemberReference member in memberSelector(type)) { |
||||||
|
if (GetKey(member) == key) |
||||||
|
return member; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
static TypeDefinition FindType(ModuleDefinition module, string name) |
||||||
|
{ |
||||||
|
int pos = name.LastIndexOf('.'); |
||||||
|
string ns; |
||||||
|
if (pos >= 0) { |
||||||
|
ns = name.Substring(0, pos); |
||||||
|
name = name.Substring(pos + 1); |
||||||
|
} else { |
||||||
|
ns = string.Empty; |
||||||
|
} |
||||||
|
TypeDefinition type = module.GetType(ns, name); |
||||||
|
if (type == null && ns.Length > 0) { |
||||||
|
// try if this is a nested type
|
||||||
|
type = FindType(module, ns); |
||||||
|
if (type != null) { |
||||||
|
type = type.NestedTypes.FirstOrDefault(t => t.Name == name); |
||||||
|
} |
||||||
|
} |
||||||
|
return type; |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,52 @@ |
|||||||
|
ILSpy Command Line Arguments |
||||||
|
|
||||||
|
Command line arguments can be either options or file names. |
||||||
|
If an argument is a file name, the file will be opened as assembly and added to the current assembly list. |
||||||
|
|
||||||
|
Available options: |
||||||
|
/singleInstance If ILSpy is already running, activates the existing instance |
||||||
|
and passes command line arguments to that instance. |
||||||
|
This is the default value if /list is not used. |
||||||
|
|
||||||
|
/separate Start up a separate ILSpy instance even if it is already running. |
||||||
|
|
||||||
|
/noActivate Do not activate the existing ILSpy instance. This option has no effec |
||||||
|
if a new ILSpy instance is being started. |
||||||
|
|
||||||
|
/list:listname Specifies the name of the assembly list that is loaded initially. |
||||||
|
When this option is not specified, ILSpy loads the previously opened list. |
||||||
|
Specify "/list" (without value) to open the default list. |
||||||
|
|
||||||
|
When this option is used, ILSpy will activate an existing instance |
||||||
|
only if it uses the same list as specified. |
||||||
|
|
||||||
|
[Note: Assembly Lists are not yet implemented] |
||||||
|
|
||||||
|
/clearList Clears the assembly list before loading the specified assemblies. |
||||||
|
[Note: Assembly Lists are not yet implemented] |
||||||
|
|
||||||
|
/navigateTo:tag Navigates to the member specified by the given XML documentation tag. |
||||||
|
The member is searched for only in the assemblies specified on the command line. |
||||||
|
Example: 'ILSpy ILSpy.exe /navigateTo:T:ICSharpCode.ILSpy.CommandLineArguments' |
||||||
|
|
||||||
|
/language:name Selects the specified language. |
||||||
|
Example: 'ILSpy /language:C#' or 'ILSpy /language:IL' |
||||||
|
|
||||||
|
WM_COPYDATA (SendMessage API): |
||||||
|
ILSpy can be controlled by other programs that send a WM_COPYDATA message to its main window. |
||||||
|
The message data must be an Unicode (UTF-16) string starting with "ILSpy:\r\n". |
||||||
|
All lines except the first ("ILSpy:") in that string are handled as command-line arguments. |
||||||
|
There must be exactly one argument per line. |
||||||
|
|
||||||
|
That is, by sending this message: |
||||||
|
ILSpy: |
||||||
|
C:\Assembly.dll |
||||||
|
/navigateTo T:Type |
||||||
|
The target ILSpy instance will open C:\Assembly.dll and navigate to the specified type. |
||||||
|
|
||||||
|
ILSpy will return TRUE (1) if it handles the message, and FALSE (0) otherwise. |
||||||
|
The /separate option will be ignored; WM_COPYDATA will never start up a new instance. |
||||||
|
The /noActivate option has no effect, sending WM_COPYDATA will never activate the window. |
||||||
|
Instead, the calling process should use SetForegroundWindow(). |
||||||
|
If you use /list with WM_COPYDATA, you need to specify /singleInstance as well, otherwise |
||||||
|
ILSpy will not handle the message if it has opened a different assembly list. |
Loading…
Reference in new issue