diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/AddXmlDocumentationTransform.cs b/ICSharpCode.Decompiler/CSharp/Transforms/AddXmlDocumentationTransform.cs index 949bd9209..84ecf1b28 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/AddXmlDocumentationTransform.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/AddXmlDocumentationTransform.cs @@ -19,6 +19,7 @@ using System; using System.IO; using System.Linq; +using System.Reflection.Metadata; using System.Xml; using ICSharpCode.Decompiler.CSharp.Syntax; using ICSharpCode.Decompiler.Documentation; @@ -40,24 +41,13 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms if (xmldoc == null) return; foreach (var entity in rootNode.DescendantsAndSelf.OfType()) { - var symbol = entity.GetSymbol(); -#warning TODO : replace with SRM - /*switch (symbol) { - case IMember member: - mr = context.TypeSystem.GetCecil(member); - break; - case IType type: - mr = context.TypeSystem.GetCecil(type.GetDefinition()); - break; - default: - continue; - } - if (mr == null) + var handle = ((entity.GetSymbol() as IEntity)?.MetadataToken).Value; + if (handle.IsNil) continue; - string doc = xmldoc.GetDocumentation(XmlDocKeyProvider.GetKey(mr)); + string doc = xmldoc.GetDocumentation(XmlDocKeyProvider.GetKey(context.TypeSystem.GetMetadata(), handle)); if (doc != null) { InsertXmlDocumentation(entity, new StringReader(doc)); - }*/ + } } } catch (XmlException ex) { string[] msg = (" Exception while reading XmlDoc: " + ex).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); diff --git a/ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs b/ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs index 281b8518c..5620e2270 100644 --- a/ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs +++ b/ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs @@ -20,8 +20,7 @@ using System; using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; -using ICSharpCode.Decompiler.Documentation; -using Mono.Cecil; +using ICSharpCode.Decompiler.Metadata; namespace ICSharpCode.Decompiler.Documentation { @@ -31,7 +30,7 @@ namespace ICSharpCode.Decompiler.Documentation public static class XmlDocLoader { static readonly Lazy mscorlibDocumentation = new Lazy(LoadMscorlibDocumentation); - static readonly ConditionalWeakTable cache = new ConditionalWeakTable(); + static readonly ConditionalWeakTable cache = new ConditionalWeakTable(); static XmlDocumentationProvider LoadMscorlibDocumentation() { @@ -47,7 +46,7 @@ namespace ICSharpCode.Decompiler.Documentation get { return mscorlibDocumentation.Value; } } - public static XmlDocumentationProvider LoadDocumentation(ModuleDefinition module) + public static XmlDocumentationProvider LoadDocumentation(PEFile module) { if (module == null) throw new ArgumentNullException(nameof(module)); @@ -56,7 +55,7 @@ namespace ICSharpCode.Decompiler.Documentation if (!cache.TryGetValue(module, out xmlDoc)) { string xmlDocFile = LookupLocalizedXmlDoc(module.FileName); if (xmlDocFile == null) { - xmlDocFile = FindXmlDocumentation(Path.GetFileName(module.FileName), module.Runtime); + xmlDocFile = FindXmlDocumentation(Path.GetFileName(module.FileName), module.GetRuntime()); } if (xmlDocFile != null) { xmlDoc = new XmlDocumentationProvider(xmlDocFile); diff --git a/ICSharpCode.Decompiler/Metadata/Dom.cs b/ICSharpCode.Decompiler/Metadata/Dom.cs index dcfc5ba53..9bae8343f 100644 --- a/ICSharpCode.Decompiler/Metadata/Dom.cs +++ b/ICSharpCode.Decompiler/Metadata/Dom.cs @@ -74,9 +74,17 @@ namespace ICSharpCode.Decompiler.Metadata public interface IDebugInfoProvider { - IList GetSequencePoints(MethodDefinition method); - IList GetVariables(MethodDefinition method); - bool TryGetName(MethodDefinition method, int index, out string name); + IList GetSequencePoints(MethodDefinitionHandle method); + IList GetVariables(MethodDefinitionHandle method); + bool TryGetName(MethodDefinitionHandle method, int index, out string name); + } + + public enum TargetRuntime + { + Net_1_0, + Net_1_1, + Net_2_0, + Net_4_0 } public class PEFile @@ -98,6 +106,25 @@ namespace ICSharpCode.Decompiler.Metadata public string Name => GetName(); public string FullName => IsAssembly ? GetMetadataReader().GetFullAssemblyName() : Name; + public TargetRuntime GetRuntime() + { + string version = GetMetadataReader().MetadataVersion; + switch (version[1]) { + case '1': + if (version[3] == 1) + return TargetRuntime.Net_1_0; + else + return TargetRuntime.Net_1_1; + case '2': + return TargetRuntime.Net_2_0; + case '4': + return TargetRuntime.Net_4_0; + default: + throw new NotSupportedException($"metadata version {version} is not supported!"); + } + + } + public MetadataReader GetMetadataReader() => Reader.GetMetadataReader(); string GetName() @@ -497,12 +524,12 @@ namespace ICSharpCode.Decompiler.Metadata public IList GetSequencePoints() { - return Module.DebugInfo?.GetSequencePoints(this); + return Module.DebugInfo?.GetSequencePoints(Handle); } public IList GetVariables() { - return Module.DebugInfo?.GetVariables(this); + return Module.DebugInfo?.GetVariables(Handle); } }