From 8acd117f91f5b6206222466052f36c04232da3fa Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Fri, 29 Mar 2024 09:59:37 +0100 Subject: [PATCH 1/2] Move non-UI analyzer code to ILSpyX --- Directory.Packages.props | 1 + ICSharpCode.ILSpyX/Abstractions/ILanguage.cs | 3 +++ .../Analyzers/AnalyzerContext.cs | 6 ++--- .../Analyzers/AnalyzerHelpers.cs | 2 +- .../Analyzers/AnalyzerScope.cs | 2 +- .../Builtin/AttributeAppliedToAnalyzer.cs | 2 +- .../Builtin/EventImplementedByAnalyzer.cs | 2 +- .../Builtin/EventOverriddenByAnalyzer.cs | 2 +- .../Analyzers/Builtin/FieldAccessAnalyzer.cs | 2 +- .../Builtin/FindTypeInAttributeDecoder.cs | 2 +- .../MemberImplementsInterfaceAnalyzer.cs | 2 +- .../Builtin/MethodImplementedByAnalyzer.cs | 2 +- .../Builtin/MethodOverriddenByAnalyzer.cs | 2 +- .../Analyzers/Builtin/MethodUsedByAnalyzer.cs | 2 +- .../Analyzers/Builtin/MethodUsesAnalyzer.cs | 2 +- .../Builtin/MethodVirtualUsedByAnalyzer.cs | 2 +- .../Builtin/PropertyImplementedByAnalyzer.cs | 2 +- .../Builtin/PropertyOverriddenByAnalyzer.cs | 2 +- .../Builtin/TypeExposedByAnalyzer.cs | 2 +- .../Builtin/TypeExtensionMethodsAnalyzer.cs | 22 +++++++++++++++++-- .../Builtin/TypeInstantiatedByAnalyzer.cs | 2 +- .../Analyzers/Builtin/TypeUsedByAnalyzer.cs | 2 +- .../Analyzers/ExportAnalyzerAttribute.cs | 2 +- .../Analyzers/IAnalyzer.cs | 2 +- ICSharpCode.ILSpyX/ICSharpCode.ILSpyX.csproj | 1 + ILSpy.Tests/Analyzers/AnalyzerScopeTests.cs | 2 +- .../MemberImplementsInterfaceAnalyzerTests.cs | 4 ++-- .../Analyzers/MethodUsesAnalyzerTests.cs | 4 ++-- .../Analyzers/TypeUsedByAnalyzerTests.cs | 4 ++-- ILSpy/Analyzers/AnalyzerSearchTreeNode.cs | 1 + .../TreeNodes/AnalyzedEventTreeNode.cs | 1 + .../TreeNodes/AnalyzedFieldTreeNode.cs | 1 + .../TreeNodes/AnalyzedMethodTreeNode.cs | 1 + .../TreeNodes/AnalyzedModuleTreeNode.cs | 1 + .../TreeNodes/AnalyzedPropertyTreeNode.cs | 1 + .../TreeNodes/AnalyzedTypeTreeNode.cs | 1 + ILSpy/App.xaml.cs | 7 +++++- 37 files changed, 68 insertions(+), 33 deletions(-) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/AnalyzerContext.cs (95%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/AnalyzerHelpers.cs (98%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/AnalyzerScope.cs (99%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/Builtin/AttributeAppliedToAnalyzer.cs (99%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/Builtin/EventImplementedByAnalyzer.cs (98%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/Builtin/EventOverriddenByAnalyzer.cs (98%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/Builtin/FieldAccessAnalyzer.cs (99%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/Builtin/FindTypeInAttributeDecoder.cs (99%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/Builtin/MemberImplementsInterfaceAnalyzer.cs (98%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/Builtin/MethodImplementedByAnalyzer.cs (98%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs (98%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/Builtin/MethodUsedByAnalyzer.cs (99%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/Builtin/MethodUsesAnalyzer.cs (98%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs (99%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/Builtin/PropertyImplementedByAnalyzer.cs (98%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs (98%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/Builtin/TypeExposedByAnalyzer.cs (98%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/Builtin/TypeExtensionMethodsAnalyzer.cs (53%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs (99%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/Builtin/TypeUsedByAnalyzer.cs (99%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/ExportAnalyzerAttribute.cs (97%) rename {ILSpy => ICSharpCode.ILSpyX}/Analyzers/IAnalyzer.cs (97%) diff --git a/Directory.Packages.props b/Directory.Packages.props index 2492143b7c..b77822de6b 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -35,6 +35,7 @@ + diff --git a/ICSharpCode.ILSpyX/Abstractions/ILanguage.cs b/ICSharpCode.ILSpyX/Abstractions/ILanguage.cs index c5c4879aa9..f05c6ded3a 100644 --- a/ICSharpCode.ILSpyX/Abstractions/ILanguage.cs +++ b/ICSharpCode.ILSpyX/Abstractions/ILanguage.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +using System.Reflection.Metadata; + using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; @@ -24,6 +26,7 @@ namespace ICSharpCode.ILSpyX.Abstractions public interface ILanguage { bool ShowMember(IEntity member); + CodeMappingInfo GetCodeMappingInfo(MetadataFile module, EntityHandle member); string GetEntityName(MetadataFile module, System.Reflection.Metadata.EntityHandle handle, bool fullName, bool omitGenerics); string GetTooltip(IEntity entity); diff --git a/ILSpy/Analyzers/AnalyzerContext.cs b/ICSharpCode.ILSpyX/Analyzers/AnalyzerContext.cs similarity index 95% rename from ILSpy/Analyzers/AnalyzerContext.cs rename to ICSharpCode.ILSpyX/Analyzers/AnalyzerContext.cs index 6c7510554d..cfb324a879 100644 --- a/ILSpy/Analyzers/AnalyzerContext.cs +++ b/ICSharpCode.ILSpyX/Analyzers/AnalyzerContext.cs @@ -23,9 +23,9 @@ using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; -using ICSharpCode.ILSpyX; +using ICSharpCode.ILSpyX.Abstractions; -namespace ICSharpCode.ILSpy.Analyzers +namespace ICSharpCode.ILSpyX.Analyzers { /// /// Provides additional context for analyzers. @@ -42,7 +42,7 @@ public class AnalyzerContext /// /// Currently used language. /// - public Language Language { get; internal set; } + public ILanguage Language { get; internal set; } /// /// Allows the analyzer to control whether the tree nodes will be sorted. diff --git a/ILSpy/Analyzers/AnalyzerHelpers.cs b/ICSharpCode.ILSpyX/Analyzers/AnalyzerHelpers.cs similarity index 98% rename from ILSpy/Analyzers/AnalyzerHelpers.cs rename to ICSharpCode.ILSpyX/Analyzers/AnalyzerHelpers.cs index b7070dedbb..ca51e7d31b 100644 --- a/ILSpy/Analyzers/AnalyzerHelpers.cs +++ b/ICSharpCode.ILSpyX/Analyzers/AnalyzerHelpers.cs @@ -21,7 +21,7 @@ using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; -namespace ICSharpCode.ILSpy.Analyzers +namespace ICSharpCode.ILSpyX.Analyzers { internal static class AnalyzerHelpers { diff --git a/ILSpy/Analyzers/AnalyzerScope.cs b/ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs similarity index 99% rename from ILSpy/Analyzers/AnalyzerScope.cs rename to ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs index 1116e408c1..b9b8e10f98 100644 --- a/ILSpy/Analyzers/AnalyzerScope.cs +++ b/ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs @@ -26,7 +26,7 @@ using ICSharpCode.Decompiler.Util; using ICSharpCode.ILSpyX; -namespace ICSharpCode.ILSpy.Analyzers +namespace ICSharpCode.ILSpyX.Analyzers { using ICSharpCode.Decompiler.TypeSystem; diff --git a/ILSpy/Analyzers/Builtin/AttributeAppliedToAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/AttributeAppliedToAnalyzer.cs similarity index 99% rename from ILSpy/Analyzers/Builtin/AttributeAppliedToAnalyzer.cs rename to ICSharpCode.ILSpyX/Analyzers/Builtin/AttributeAppliedToAnalyzer.cs index 6007253a60..fa925c9b43 100644 --- a/ILSpy/Analyzers/Builtin/AttributeAppliedToAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/AttributeAppliedToAnalyzer.cs @@ -26,7 +26,7 @@ using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.Util; -namespace ICSharpCode.ILSpy.Analyzers.Builtin +namespace ICSharpCode.ILSpyX.Analyzers.Builtin { [ExportAnalyzer(Header = "Applied To", Order = 10)] class AttributeAppliedToAnalyzer : IAnalyzer diff --git a/ILSpy/Analyzers/Builtin/EventImplementedByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/EventImplementedByAnalyzer.cs similarity index 98% rename from ILSpy/Analyzers/Builtin/EventImplementedByAnalyzer.cs rename to ICSharpCode.ILSpyX/Analyzers/Builtin/EventImplementedByAnalyzer.cs index 5afde05256..94988b50b3 100644 --- a/ILSpy/Analyzers/Builtin/EventImplementedByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/EventImplementedByAnalyzer.cs @@ -23,7 +23,7 @@ using ICSharpCode.Decompiler.TypeSystem; -namespace ICSharpCode.ILSpy.Analyzers.Builtin +namespace ICSharpCode.ILSpyX.Analyzers.Builtin { /// /// Shows events that implement an interface event. diff --git a/ILSpy/Analyzers/Builtin/EventOverriddenByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/EventOverriddenByAnalyzer.cs similarity index 98% rename from ILSpy/Analyzers/Builtin/EventOverriddenByAnalyzer.cs rename to ICSharpCode.ILSpyX/Analyzers/Builtin/EventOverriddenByAnalyzer.cs index d4f8cdda62..ec45c5bb7a 100644 --- a/ILSpy/Analyzers/Builtin/EventOverriddenByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/EventOverriddenByAnalyzer.cs @@ -23,7 +23,7 @@ using ICSharpCode.Decompiler.TypeSystem; -namespace ICSharpCode.ILSpy.Analyzers.Builtin +namespace ICSharpCode.ILSpyX.Analyzers.Builtin { /// /// Shows events that override an event. diff --git a/ILSpy/Analyzers/Builtin/FieldAccessAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/FieldAccessAnalyzer.cs similarity index 99% rename from ILSpy/Analyzers/Builtin/FieldAccessAnalyzer.cs rename to ICSharpCode.ILSpyX/Analyzers/Builtin/FieldAccessAnalyzer.cs index c392bc1d23..0065e13f5c 100644 --- a/ILSpy/Analyzers/Builtin/FieldAccessAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/FieldAccessAnalyzer.cs @@ -29,7 +29,7 @@ using ILOpCode = System.Reflection.Metadata.ILOpCode; -namespace ICSharpCode.ILSpy.Analyzers.Builtin +namespace ICSharpCode.ILSpyX.Analyzers.Builtin { /// /// Finds methods where this field is read. diff --git a/ILSpy/Analyzers/Builtin/FindTypeInAttributeDecoder.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/FindTypeInAttributeDecoder.cs similarity index 99% rename from ILSpy/Analyzers/Builtin/FindTypeInAttributeDecoder.cs rename to ICSharpCode.ILSpyX/Analyzers/Builtin/FindTypeInAttributeDecoder.cs index 45c1e73ee0..0b7e0f0275 100644 --- a/ILSpy/Analyzers/Builtin/FindTypeInAttributeDecoder.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/FindTypeInAttributeDecoder.cs @@ -25,7 +25,7 @@ using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; -namespace ICSharpCode.ILSpy.Analyzers.Builtin +namespace ICSharpCode.ILSpyX.Analyzers.Builtin { public enum TokenSearchResult : byte { diff --git a/ILSpy/Analyzers/Builtin/MemberImplementsInterfaceAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/MemberImplementsInterfaceAnalyzer.cs similarity index 98% rename from ILSpy/Analyzers/Builtin/MemberImplementsInterfaceAnalyzer.cs rename to ICSharpCode.ILSpyX/Analyzers/Builtin/MemberImplementsInterfaceAnalyzer.cs index d4c87ced58..3f77265ac8 100644 --- a/ILSpy/Analyzers/Builtin/MemberImplementsInterfaceAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/MemberImplementsInterfaceAnalyzer.cs @@ -22,7 +22,7 @@ using ICSharpCode.Decompiler.TypeSystem; -namespace ICSharpCode.ILSpy.Analyzers.Builtin +namespace ICSharpCode.ILSpyX.Analyzers.Builtin { /// /// Shows members from all corresponding interfaces the selected member implements. diff --git a/ILSpy/Analyzers/Builtin/MethodImplementedByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodImplementedByAnalyzer.cs similarity index 98% rename from ILSpy/Analyzers/Builtin/MethodImplementedByAnalyzer.cs rename to ICSharpCode.ILSpyX/Analyzers/Builtin/MethodImplementedByAnalyzer.cs index 4105e185ce..e0d0768025 100644 --- a/ILSpy/Analyzers/Builtin/MethodImplementedByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodImplementedByAnalyzer.cs @@ -26,7 +26,7 @@ using ICSharpCode.Decompiler.TypeSystem; -namespace ICSharpCode.ILSpy.Analyzers.Builtin +namespace ICSharpCode.ILSpyX.Analyzers.Builtin { /// /// Shows methods that implement an interface method. diff --git a/ILSpy/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs similarity index 98% rename from ILSpy/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs rename to ICSharpCode.ILSpyX/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs index 2fe6677fad..5c6e4bd10a 100644 --- a/ILSpy/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs @@ -23,7 +23,7 @@ using ICSharpCode.Decompiler.TypeSystem; -namespace ICSharpCode.ILSpy.Analyzers.Builtin +namespace ICSharpCode.ILSpyX.Analyzers.Builtin { /// /// Shows methods that override a method. diff --git a/ILSpy/Analyzers/Builtin/MethodUsedByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsedByAnalyzer.cs similarity index 99% rename from ILSpy/Analyzers/Builtin/MethodUsedByAnalyzer.cs rename to ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsedByAnalyzer.cs index 290c9e5e96..da5f747d35 100644 --- a/ILSpy/Analyzers/Builtin/MethodUsedByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsedByAnalyzer.cs @@ -28,7 +28,7 @@ using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; -namespace ICSharpCode.ILSpy.Analyzers.Builtin +namespace ICSharpCode.ILSpyX.Analyzers.Builtin { /// /// Shows entities that are used by a method. diff --git a/ILSpy/Analyzers/Builtin/MethodUsesAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsesAnalyzer.cs similarity index 98% rename from ILSpy/Analyzers/Builtin/MethodUsesAnalyzer.cs rename to ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsesAnalyzer.cs index c35593d693..6bfe94ea8b 100644 --- a/ILSpy/Analyzers/Builtin/MethodUsesAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsesAnalyzer.cs @@ -26,7 +26,7 @@ using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; -namespace ICSharpCode.ILSpy.Analyzers.Builtin +namespace ICSharpCode.ILSpyX.Analyzers.Builtin { /// /// Shows entities that are used by a method. diff --git a/ILSpy/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs similarity index 99% rename from ILSpy/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs rename to ICSharpCode.ILSpyX/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs index b3102de193..0d74e068ea 100644 --- a/ILSpy/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs @@ -25,7 +25,7 @@ using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; -namespace ICSharpCode.ILSpy.Analyzers.Builtin +namespace ICSharpCode.ILSpyX.Analyzers.Builtin { /// /// Shows entities that are used by a method. diff --git a/ILSpy/Analyzers/Builtin/PropertyImplementedByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyImplementedByAnalyzer.cs similarity index 98% rename from ILSpy/Analyzers/Builtin/PropertyImplementedByAnalyzer.cs rename to ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyImplementedByAnalyzer.cs index 241e26b888..0b4e7affd6 100644 --- a/ILSpy/Analyzers/Builtin/PropertyImplementedByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyImplementedByAnalyzer.cs @@ -23,7 +23,7 @@ using ICSharpCode.Decompiler.TypeSystem; -namespace ICSharpCode.ILSpy.Analyzers.Builtin +namespace ICSharpCode.ILSpyX.Analyzers.Builtin { /// /// Shows properties that implement an interface property. diff --git a/ILSpy/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs similarity index 98% rename from ILSpy/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs rename to ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs index 475628ce56..7652252170 100644 --- a/ILSpy/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs @@ -26,7 +26,7 @@ using ICSharpCode.Decompiler.TypeSystem; -namespace ICSharpCode.ILSpy.Analyzers.Builtin +namespace ICSharpCode.ILSpyX.Analyzers.Builtin { /// /// Shows properties that override a property. diff --git a/ILSpy/Analyzers/Builtin/TypeExposedByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExposedByAnalyzer.cs similarity index 98% rename from ILSpy/Analyzers/Builtin/TypeExposedByAnalyzer.cs rename to ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExposedByAnalyzer.cs index 54828654e6..6174e2d8c3 100644 --- a/ILSpy/Analyzers/Builtin/TypeExposedByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExposedByAnalyzer.cs @@ -25,7 +25,7 @@ using System.Threading.Tasks; -namespace ICSharpCode.ILSpy.Analyzers.Builtin +namespace ICSharpCode.ILSpyX.Analyzers.Builtin { using ICSharpCode.Decompiler.TypeSystem; diff --git a/ILSpy/Analyzers/Builtin/TypeExtensionMethodsAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExtensionMethodsAnalyzer.cs similarity index 53% rename from ILSpy/Analyzers/Builtin/TypeExtensionMethodsAnalyzer.cs rename to ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExtensionMethodsAnalyzer.cs index 2bd75dfb78..11f1d7bd67 100644 --- a/ILSpy/Analyzers/Builtin/TypeExtensionMethodsAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExtensionMethodsAnalyzer.cs @@ -1,10 +1,28 @@ -using System.Collections.Generic; +// Copyright (c) 2018 Siegfried Pammer +// +// 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. + +using System.Collections.Generic; using System.ComponentModel.Composition; using System.Diagnostics; using ICSharpCode.Decompiler.TypeSystem; -namespace ICSharpCode.ILSpy.Analyzers.Builtin +namespace ICSharpCode.ILSpyX.Analyzers.Builtin { /// /// Finds all extension methods defined for a type. diff --git a/ILSpy/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs similarity index 99% rename from ILSpy/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs rename to ICSharpCode.ILSpyX/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs index 500923bc6f..4f5c82e5ea 100644 --- a/ILSpy/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs @@ -30,7 +30,7 @@ using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; -namespace ICSharpCode.ILSpy.Analyzers.Builtin +namespace ICSharpCode.ILSpyX.Analyzers.Builtin { /// /// Shows methods that instantiate a type. diff --git a/ILSpy/Analyzers/Builtin/TypeUsedByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeUsedByAnalyzer.cs similarity index 99% rename from ILSpy/Analyzers/Builtin/TypeUsedByAnalyzer.cs rename to ICSharpCode.ILSpyX/Analyzers/Builtin/TypeUsedByAnalyzer.cs index 0f79267664..cfbe5d665e 100644 --- a/ILSpy/Analyzers/Builtin/TypeUsedByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeUsedByAnalyzer.cs @@ -28,7 +28,7 @@ using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; -namespace ICSharpCode.ILSpy.Analyzers.Builtin +namespace ICSharpCode.ILSpyX.Analyzers.Builtin { /// /// Shows entities that use a type. diff --git a/ILSpy/Analyzers/ExportAnalyzerAttribute.cs b/ICSharpCode.ILSpyX/Analyzers/ExportAnalyzerAttribute.cs similarity index 97% rename from ILSpy/Analyzers/ExportAnalyzerAttribute.cs rename to ICSharpCode.ILSpyX/Analyzers/ExportAnalyzerAttribute.cs index e17f6585e4..e4da690f15 100644 --- a/ILSpy/Analyzers/ExportAnalyzerAttribute.cs +++ b/ICSharpCode.ILSpyX/Analyzers/ExportAnalyzerAttribute.cs @@ -19,7 +19,7 @@ using System; using System.ComponentModel.Composition; -namespace ICSharpCode.ILSpy.Analyzers +namespace ICSharpCode.ILSpyX.Analyzers { [MetadataAttribute] [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] diff --git a/ILSpy/Analyzers/IAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/IAnalyzer.cs similarity index 97% rename from ILSpy/Analyzers/IAnalyzer.cs rename to ICSharpCode.ILSpyX/Analyzers/IAnalyzer.cs index ca9d417600..d21a871837 100644 --- a/ILSpy/Analyzers/IAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/IAnalyzer.cs @@ -20,7 +20,7 @@ using ICSharpCode.Decompiler.TypeSystem; -namespace ICSharpCode.ILSpy.Analyzers +namespace ICSharpCode.ILSpyX.Analyzers { /// /// Base interface for all analyzers. You can register an analyzer for any by implementing diff --git a/ICSharpCode.ILSpyX/ICSharpCode.ILSpyX.csproj b/ICSharpCode.ILSpyX/ICSharpCode.ILSpyX.csproj index a788e3659d..bde8d593a7 100644 --- a/ICSharpCode.ILSpyX/ICSharpCode.ILSpyX.csproj +++ b/ICSharpCode.ILSpyX/ICSharpCode.ILSpyX.csproj @@ -62,6 +62,7 @@ + diff --git a/ILSpy.Tests/Analyzers/AnalyzerScopeTests.cs b/ILSpy.Tests/Analyzers/AnalyzerScopeTests.cs index 54ccbebd0d..43c74ce85d 100644 --- a/ILSpy.Tests/Analyzers/AnalyzerScopeTests.cs +++ b/ILSpy.Tests/Analyzers/AnalyzerScopeTests.cs @@ -23,7 +23,7 @@ using ICSharpCode.Decompiler.CSharp.Resolver; using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; -using ICSharpCode.ILSpy.Analyzers; +using ICSharpCode.ILSpyX.Analyzers; using NUnit.Framework; diff --git a/ILSpy.Tests/Analyzers/MemberImplementsInterfaceAnalyzerTests.cs b/ILSpy.Tests/Analyzers/MemberImplementsInterfaceAnalyzerTests.cs index f3d2f3c933..d27b985ee2 100644 --- a/ILSpy.Tests/Analyzers/MemberImplementsInterfaceAnalyzerTests.cs +++ b/ILSpy.Tests/Analyzers/MemberImplementsInterfaceAnalyzerTests.cs @@ -25,8 +25,8 @@ using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem.Implementation; -using ICSharpCode.ILSpy.Analyzers; -using ICSharpCode.ILSpy.Analyzers.Builtin; +using ICSharpCode.ILSpyX.Analyzers; +using ICSharpCode.ILSpyX.Analyzers.Builtin; using NSubstitute; diff --git a/ILSpy.Tests/Analyzers/MethodUsesAnalyzerTests.cs b/ILSpy.Tests/Analyzers/MethodUsesAnalyzerTests.cs index 9cd7726d65..033deaa1d1 100644 --- a/ILSpy.Tests/Analyzers/MethodUsesAnalyzerTests.cs +++ b/ILSpy.Tests/Analyzers/MethodUsesAnalyzerTests.cs @@ -6,9 +6,9 @@ using System.Windows; using ICSharpCode.Decompiler.TypeSystem; -using ICSharpCode.ILSpy.Analyzers; -using ICSharpCode.ILSpy.Analyzers.Builtin; using ICSharpCode.ILSpyX; +using ICSharpCode.ILSpyX.Analyzers; +using ICSharpCode.ILSpyX.Analyzers.Builtin; using NUnit.Framework; diff --git a/ILSpy.Tests/Analyzers/TypeUsedByAnalyzerTests.cs b/ILSpy.Tests/Analyzers/TypeUsedByAnalyzerTests.cs index 79a5eb5584..972cb6fc7c 100644 --- a/ILSpy.Tests/Analyzers/TypeUsedByAnalyzerTests.cs +++ b/ILSpy.Tests/Analyzers/TypeUsedByAnalyzerTests.cs @@ -19,9 +19,9 @@ using System.Linq; using ICSharpCode.Decompiler.TypeSystem; -using ICSharpCode.ILSpy.Analyzers; -using ICSharpCode.ILSpy.Analyzers.Builtin; using ICSharpCode.ILSpyX; +using ICSharpCode.ILSpyX.Analyzers; +using ICSharpCode.ILSpyX.Analyzers.Builtin; using NUnit.Framework; diff --git a/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs b/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs index 6b908d1ffe..490bf5ec2a 100644 --- a/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs +++ b/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs @@ -25,6 +25,7 @@ using ICSharpCode.ILSpy.Analyzers.TreeNodes; using ICSharpCode.ILSpy.TreeNodes; using ICSharpCode.ILSpyX; +using ICSharpCode.ILSpyX.Analyzers; namespace ICSharpCode.ILSpy.Analyzers { diff --git a/ILSpy/Analyzers/TreeNodes/AnalyzedEventTreeNode.cs b/ILSpy/Analyzers/TreeNodes/AnalyzedEventTreeNode.cs index 923ba56028..8b6ff6f033 100644 --- a/ILSpy/Analyzers/TreeNodes/AnalyzedEventTreeNode.cs +++ b/ILSpy/Analyzers/TreeNodes/AnalyzedEventTreeNode.cs @@ -24,6 +24,7 @@ namespace ICSharpCode.ILSpy.Analyzers.TreeNodes { using ICSharpCode.Decompiler.TypeSystem; + using ICSharpCode.ILSpyX.Analyzers; internal sealed class AnalyzedEventTreeNode : AnalyzerEntityTreeNode { diff --git a/ILSpy/Analyzers/TreeNodes/AnalyzedFieldTreeNode.cs b/ILSpy/Analyzers/TreeNodes/AnalyzedFieldTreeNode.cs index a3619b7bf8..1f2b9b9a3f 100644 --- a/ILSpy/Analyzers/TreeNodes/AnalyzedFieldTreeNode.cs +++ b/ILSpy/Analyzers/TreeNodes/AnalyzedFieldTreeNode.cs @@ -21,6 +21,7 @@ using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.ILSpy.TreeNodes; +using ICSharpCode.ILSpyX.Analyzers; namespace ICSharpCode.ILSpy.Analyzers.TreeNodes { diff --git a/ILSpy/Analyzers/TreeNodes/AnalyzedMethodTreeNode.cs b/ILSpy/Analyzers/TreeNodes/AnalyzedMethodTreeNode.cs index 19ce7fa8e8..b7cee8ede4 100644 --- a/ILSpy/Analyzers/TreeNodes/AnalyzedMethodTreeNode.cs +++ b/ILSpy/Analyzers/TreeNodes/AnalyzedMethodTreeNode.cs @@ -21,6 +21,7 @@ using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.ILSpy.TreeNodes; +using ICSharpCode.ILSpyX.Analyzers; namespace ICSharpCode.ILSpy.Analyzers.TreeNodes { diff --git a/ILSpy/Analyzers/TreeNodes/AnalyzedModuleTreeNode.cs b/ILSpy/Analyzers/TreeNodes/AnalyzedModuleTreeNode.cs index 1879c7e044..9a8558e4cc 100644 --- a/ILSpy/Analyzers/TreeNodes/AnalyzedModuleTreeNode.cs +++ b/ILSpy/Analyzers/TreeNodes/AnalyzedModuleTreeNode.cs @@ -21,6 +21,7 @@ using System.Windows; using ICSharpCode.Decompiler.TypeSystem; +using ICSharpCode.ILSpyX.Analyzers; namespace ICSharpCode.ILSpy.Analyzers.TreeNodes { diff --git a/ILSpy/Analyzers/TreeNodes/AnalyzedPropertyTreeNode.cs b/ILSpy/Analyzers/TreeNodes/AnalyzedPropertyTreeNode.cs index d6504f6b97..d19bc3e730 100644 --- a/ILSpy/Analyzers/TreeNodes/AnalyzedPropertyTreeNode.cs +++ b/ILSpy/Analyzers/TreeNodes/AnalyzedPropertyTreeNode.cs @@ -21,6 +21,7 @@ using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.ILSpy.TreeNodes; +using ICSharpCode.ILSpyX.Analyzers; namespace ICSharpCode.ILSpy.Analyzers.TreeNodes { diff --git a/ILSpy/Analyzers/TreeNodes/AnalyzedTypeTreeNode.cs b/ILSpy/Analyzers/TreeNodes/AnalyzedTypeTreeNode.cs index 52757d1347..6836944eb2 100644 --- a/ILSpy/Analyzers/TreeNodes/AnalyzedTypeTreeNode.cs +++ b/ILSpy/Analyzers/TreeNodes/AnalyzedTypeTreeNode.cs @@ -21,6 +21,7 @@ using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.ILSpy.TreeNodes; +using ICSharpCode.ILSpyX.Analyzers; namespace ICSharpCode.ILSpy.Analyzers.TreeNodes { diff --git a/ILSpy/App.xaml.cs b/ILSpy/App.xaml.cs index d04697de41..0e88f19caa 100644 --- a/ILSpy/App.xaml.cs +++ b/ILSpy/App.xaml.cs @@ -31,6 +31,7 @@ using System.Windows.Threading; using ICSharpCode.ILSpy.Options; +using ICSharpCode.ILSpyX.Analyzers; using ICSharpCode.ILSpyX.Settings; using Microsoft.VisualStudio.Composition; @@ -131,9 +132,13 @@ private static async Task InitializeMef() } } } - // Add the built-in parts + // Add the built-in parts: First, from ILSpyX + var xParts = await discovery.CreatePartsAsync(typeof(IAnalyzer).Assembly); + catalog = catalog.AddParts(xParts); + // Then from ILSpy itself var createdParts = await discovery.CreatePartsAsync(Assembly.GetExecutingAssembly()); catalog = catalog.AddParts(createdParts); + // If/When the project switches to .NET Standard/Core, this will be needed to allow metadata interfaces (as opposed // to metadata classes). When running on .NET Framework, it's automatic. // catalog.WithDesktopSupport(); From 7e69247f3f5de3e70235b4cb253c9229c3e65192 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 29 Mar 2024 12:30:17 +0100 Subject: [PATCH 2/2] Add nullability annotations --- .../Analyzers/AnalyzerContext.cs | 78 +++++++++---------- .../Analyzers/AnalyzerHelpers.cs | 4 +- ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs | 20 ++--- .../Builtin/EventImplementedByAnalyzer.cs | 7 +- .../Builtin/EventOverriddenByAnalyzer.cs | 7 +- .../Analyzers/Builtin/FieldAccessAnalyzer.cs | 10 ++- .../MemberImplementsInterfaceAnalyzer.cs | 2 +- .../Builtin/MethodImplementedByAnalyzer.cs | 10 +-- .../Builtin/MethodOverriddenByAnalyzer.cs | 7 +- .../Analyzers/Builtin/MethodUsedByAnalyzer.cs | 16 ++-- .../Analyzers/Builtin/MethodUsesAnalyzer.cs | 6 +- .../Builtin/MethodVirtualUsedByAnalyzer.cs | 19 +++-- .../Builtin/PropertyImplementedByAnalyzer.cs | 7 +- .../Builtin/PropertyOverriddenByAnalyzer.cs | 10 +-- .../Builtin/TypeExposedByAnalyzer.cs | 7 +- .../Builtin/TypeExtensionMethodsAnalyzer.cs | 6 +- .../Builtin/TypeInstantiatedByAnalyzer.cs | 11 ++- .../Analyzers/Builtin/TypeUsedByAnalyzer.cs | 6 +- .../Analyzers/ExportAnalyzerAttribute.cs | 2 +- ICSharpCode.ILSpyX/Search/SearchResult.cs | 16 ++-- .../MemberImplementsInterfaceAnalyzerTests.cs | 2 +- ILSpy/Search/SearchPane.cs | 9 ++- 22 files changed, 137 insertions(+), 125 deletions(-) diff --git a/ICSharpCode.ILSpyX/Analyzers/AnalyzerContext.cs b/ICSharpCode.ILSpyX/Analyzers/AnalyzerContext.cs index cfb324a879..09112056f4 100644 --- a/ICSharpCode.ILSpyX/Analyzers/AnalyzerContext.cs +++ b/ICSharpCode.ILSpyX/Analyzers/AnalyzerContext.cs @@ -32,51 +32,51 @@ namespace ICSharpCode.ILSpyX.Analyzers /// public class AnalyzerContext { - public AssemblyList AssemblyList { get; internal set; } + public required AssemblyList AssemblyList { get; init; } - /// - /// CancellationToken. Currently Analyzers do not support cancellation from the UI, but it should be checked nonetheless. - /// - public CancellationToken CancellationToken { get; internal set; } + /// + /// CancellationToken. Currently Analyzers do not support cancellation from the UI, but it should be checked nonetheless. + /// + public CancellationToken CancellationToken { get; init; } - /// - /// Currently used language. - /// - public ILanguage Language { get; internal set; } + /// + /// Currently used language. + /// + public required ILanguage Language { get; init; } - /// - /// Allows the analyzer to control whether the tree nodes will be sorted. - /// Must be set within - /// before the results are enumerated. - /// - public bool SortResults { get; set; } +/// +/// Allows the analyzer to control whether the tree nodes will be sorted. +/// Must be set within +/// before the results are enumerated. +/// +public bool SortResults { get; set; } - public MethodBodyBlock GetMethodBody(IMethod method) - { - if (!method.HasBody || method.MetadataToken.IsNil) - return null; - var module = method.ParentModule.MetadataFile; - var md = module.Metadata.GetMethodDefinition((MethodDefinitionHandle)method.MetadataToken); - try - { - return module.GetMethodBody(md.RelativeVirtualAddress); - } - catch (BadImageFormatException) - { - return null; - } - } +public MethodBodyBlock? GetMethodBody(IMethod method) +{ + if (!method.HasBody || method.MetadataToken.IsNil || method.ParentModule?.MetadataFile == null) + return null; + var module = method.ParentModule.MetadataFile; + var md = module.Metadata.GetMethodDefinition((MethodDefinitionHandle)method.MetadataToken); + try + { + return module.GetMethodBody(md.RelativeVirtualAddress); + } + catch (BadImageFormatException) + { + return null; + } +} - public AnalyzerScope GetScopeOf(IEntity entity) - { - return new AnalyzerScope(AssemblyList, entity); - } +public AnalyzerScope GetScopeOf(IEntity entity) +{ + return new AnalyzerScope(AssemblyList, entity); +} - readonly ConcurrentDictionary typeSystemCache = new(); +readonly ConcurrentDictionary typeSystemCache = new(); - public DecompilerTypeSystem GetOrCreateTypeSystem(MetadataFile module) - { - return typeSystemCache.GetOrAdd(module, m => new DecompilerTypeSystem(m, m.GetAssemblyResolver())); - } +public DecompilerTypeSystem GetOrCreateTypeSystem(MetadataFile module) +{ + return typeSystemCache.GetOrAdd(module, m => new DecompilerTypeSystem(m, m.GetAssemblyResolver())); +} } } diff --git a/ICSharpCode.ILSpyX/Analyzers/AnalyzerHelpers.cs b/ICSharpCode.ILSpyX/Analyzers/AnalyzerHelpers.cs index ca51e7d31b..4c5217ef6a 100644 --- a/ICSharpCode.ILSpyX/Analyzers/AnalyzerHelpers.cs +++ b/ICSharpCode.ILSpyX/Analyzers/AnalyzerHelpers.cs @@ -34,7 +34,7 @@ public static bool IsPossibleReferenceTo(EntityHandle member, MetadataFile modul { case HandleKind.MethodDefinition: return member == analyzedMethod.MetadataToken - && module == analyzedMethod.ParentModule.MetadataFile; + && module == analyzedMethod.ParentModule?.MetadataFile; case HandleKind.MemberReference: var mr = metadata.GetMemberReference((MemberReferenceHandle)member); if (mr.GetKind() != MemberReferenceKind.Method) @@ -48,7 +48,7 @@ public static bool IsPossibleReferenceTo(EntityHandle member, MetadataFile modul } } - public static ISymbol GetParentEntity(DecompilerTypeSystem ts, CustomAttribute customAttribute) + public static ISymbol? GetParentEntity(DecompilerTypeSystem ts, CustomAttribute customAttribute) { var metadata = ts.MainModule.MetadataFile.Metadata; switch (customAttribute.Parent.Kind) diff --git a/ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs b/ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs index b9b8e10f98..8f01faf0f7 100644 --- a/ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs +++ b/ICSharpCode.ILSpyX/Analyzers/AnalyzerScope.cs @@ -24,7 +24,6 @@ using ICSharpCode.Decompiler; using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.Util; -using ICSharpCode.ILSpyX; namespace ICSharpCode.ILSpyX.Analyzers { @@ -61,19 +60,19 @@ public AnalyzerScope(AssemblyList assemblyList, IEntity entity) public IEnumerable GetModulesInScope(CancellationToken ct) { if (IsLocal) - return new[] { TypeScope.ParentModule.MetadataFile }; + return new[] { TypeScope.ParentModule!.MetadataFile! }; if (effectiveAccessibility.LessThanOrEqual(Accessibility.Internal)) return GetModuleAndAnyFriends(TypeScope, ct); - return GetReferencingModules(TypeScope.ParentModule.MetadataFile, ct); + return GetReferencingModules(TypeScope.ParentModule!.MetadataFile!, ct); } public IEnumerable GetAllModules() { return assemblyListSnapshot.GetAllAssembliesAsync().GetAwaiter().GetResult() .Select(asm => asm.GetMetadataFileOrNull()) - .Where(x => x != null); + .Where(x => x != null)!; } public DecompilerTypeSystem ConstructTypeSystem(MetadataFile module) @@ -113,7 +112,7 @@ static void DetermineEffectiveAccessibility(IEntity input, out ITypeDefinition t else { accessibility = input.Accessibility; - typeScope = input.DeclaringTypeDefinition; + typeScope = input.DeclaringTypeDefinition!; } // Once we reach a private entity, we leave the loop with typeScope set to the class that // contains the private entity = the scope that needs to be searched. @@ -123,7 +122,7 @@ static void DetermineEffectiveAccessibility(IEntity input, out ITypeDefinition t { accessibility = accessibility.Intersect(typeScope.Accessibility); prevTypeScope = typeScope; - typeScope = prevTypeScope.DeclaringTypeDefinition; + typeScope = prevTypeScope.DeclaringTypeDefinition!; } if (typeScope == null) { @@ -181,7 +180,7 @@ IEnumerable GetReferencingModules(MetadataFile self, CancellationT IEnumerable GetModuleAndAnyFriends(ITypeDefinition typeScope, CancellationToken ct) { - var self = typeScope.ParentModule.MetadataFile; + var self = typeScope.ParentModule!.MetadataFile!; yield return self; @@ -191,9 +190,10 @@ IEnumerable GetModuleAndAnyFriends(ITypeDefinition typeScope, Canc var friendAssemblies = new HashSet(); foreach (var attribute in attributes) { - string assemblyName = attribute.DecodeValue(typeProvider).FixedArguments[0].Value as string; - assemblyName = assemblyName.Split(',')[0]; // strip off any public key info - friendAssemblies.Add(assemblyName); + string? assemblyName = attribute.DecodeValue(typeProvider).FixedArguments[0].Value as string; + assemblyName = assemblyName?.Split(',')[0]; // strip off any public key info + if (assemblyName != null) + friendAssemblies.Add(assemblyName); } if (friendAssemblies.Count > 0) diff --git a/ICSharpCode.ILSpyX/Analyzers/Builtin/EventImplementedByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/EventImplementedByAnalyzer.cs index 94988b50b3..e928f531a5 100644 --- a/ICSharpCode.ILSpyX/Analyzers/Builtin/EventImplementedByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/EventImplementedByAnalyzer.cs @@ -17,7 +17,6 @@ // DEALINGS IN THE SOFTWARE. using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Diagnostics; using System.Linq; @@ -44,17 +43,19 @@ public IEnumerable Analyze(ISymbol analyzedSymbol, AnalyzerContext cont IEnumerable AnalyzeType(IEvent analyzedEntity, ITypeDefinition type) { + if (analyzedEntity.DeclaringTypeDefinition?.ParentModule?.MetadataFile == null) + yield break; var token = analyzedEntity.MetadataToken; var declaringTypeToken = analyzedEntity.DeclaringTypeDefinition.MetadataToken; var module = analyzedEntity.DeclaringTypeDefinition.ParentModule.MetadataFile; var allTypes = type.GetAllBaseTypeDefinitions(); - if (!allTypes.Any(t => t.MetadataToken == declaringTypeToken && t.ParentModule.MetadataFile == module)) + if (!allTypes.Any(t => t.MetadataToken == declaringTypeToken && t.ParentModule?.MetadataFile == module)) yield break; foreach (var @event in type.Events) { var baseMembers = InheritanceHelper.GetBaseMembers(@event, true); - if (baseMembers.Any(m => m.MetadataToken == token && m.ParentModule.MetadataFile == module)) + if (baseMembers.Any(m => m.MetadataToken == token && m.ParentModule?.MetadataFile == module)) yield return @event; } } diff --git a/ICSharpCode.ILSpyX/Analyzers/Builtin/EventOverriddenByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/EventOverriddenByAnalyzer.cs index ec45c5bb7a..5db8f0841b 100644 --- a/ICSharpCode.ILSpyX/Analyzers/Builtin/EventOverriddenByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/EventOverriddenByAnalyzer.cs @@ -17,7 +17,6 @@ // DEALINGS IN THE SOFTWARE. using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Diagnostics; using System.Linq; @@ -44,11 +43,13 @@ public IEnumerable Analyze(ISymbol analyzedSymbol, AnalyzerContext cont IEnumerable AnalyzeType(IEvent analyzedEntity, ITypeDefinition type) { + if (analyzedEntity.DeclaringTypeDefinition?.ParentModule?.MetadataFile == null) + yield break; var token = analyzedEntity.MetadataToken; var declaringTypeToken = analyzedEntity.DeclaringTypeDefinition.MetadataToken; var module = analyzedEntity.DeclaringTypeDefinition.ParentModule.MetadataFile; var allTypes = type.GetAllBaseTypeDefinitions(); - if (!allTypes.Any(t => t.MetadataToken == declaringTypeToken && t.ParentModule.MetadataFile == module)) + if (!allTypes.Any(t => t.MetadataToken == declaringTypeToken && t.ParentModule?.MetadataFile == module)) yield break; foreach (var @event in type.Events) @@ -56,7 +57,7 @@ IEnumerable AnalyzeType(IEvent analyzedEntity, ITypeDefinition type) if (!@event.IsOverride) continue; var baseMembers = InheritanceHelper.GetBaseMembers(@event, false); - if (baseMembers.Any(p => p.MetadataToken == token && p.ParentModule.MetadataFile == module)) + if (baseMembers.Any(p => p.MetadataToken == token && p.ParentModule?.MetadataFile == module)) { yield return @event; } diff --git a/ICSharpCode.ILSpyX/Analyzers/Builtin/FieldAccessAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/FieldAccessAnalyzer.cs index 0065e13f5c..ba829b0fc2 100644 --- a/ICSharpCode.ILSpyX/Analyzers/Builtin/FieldAccessAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/FieldAccessAnalyzer.cs @@ -74,6 +74,8 @@ public IEnumerable Analyze(ISymbol analyzedSymbol, AnalyzerContext cont var scope = context.GetScopeOf((IEntity)analyzedSymbol); foreach (var type in scope.GetTypesInScope(context.CancellationToken)) { + if (type.ParentModule?.MetadataFile == null) + continue; var mappingInfo = context.Language.GetCodeMappingInfo(type.ParentModule.MetadataFile, type.MetadataToken); var methods = type.GetMembers(m => m is IMethod, Options).OfType(); foreach (var method in methods) @@ -119,7 +121,7 @@ public IEnumerable Analyze(ISymbol analyzedSymbol, AnalyzerContext cont bool IsUsedInMethod(IField analyzedField, IMethod method, CodeMappingInfo mappingInfo, AnalyzerContext context) { - if (method.MetadataToken.IsNil) + if (method.MetadataToken.IsNil || method.ParentModule?.MetadataFile == null) return false; var module = method.ParentModule.MetadataFile; foreach (var part in mappingInfo.GetMethodParts((MethodDefinitionHandle)method.MetadataToken)) @@ -144,7 +146,7 @@ bool IsUsedInMethod(IField analyzedField, IMethod method, CodeMappingInfo mappin bool ScanMethodBody(IField analyzedField, IMethod method, MethodBodyBlock methodBody) { - if (methodBody == null) + if (methodBody == null || method.ParentModule?.MetadataFile == null) return false; var mainModule = (MetadataModule)method.ParentModule; @@ -170,7 +172,7 @@ bool ScanMethodBody(IField analyzedField, IMethod method, MethodBodyBlock method EntityHandle fieldHandle = MetadataTokenHelpers.EntityHandleOrNil(blob.ReadInt32()); if (!fieldHandle.Kind.IsMemberKind()) continue; - IField field; + IField? field; try { field = mainModule.ResolveEntity(fieldHandle, genericContext) as IField; @@ -183,7 +185,7 @@ bool ScanMethodBody(IField analyzedField, IMethod method, MethodBodyBlock method continue; if (field.MetadataToken == analyzedField.MetadataToken - && field.ParentModule.MetadataFile == analyzedField.ParentModule.MetadataFile) + && field.ParentModule?.MetadataFile == analyzedField.ParentModule!.MetadataFile) return true; } diff --git a/ICSharpCode.ILSpyX/Analyzers/Builtin/MemberImplementsInterfaceAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/MemberImplementsInterfaceAnalyzer.cs index 3f77265ac8..a25d48d86c 100644 --- a/ICSharpCode.ILSpyX/Analyzers/Builtin/MemberImplementsInterfaceAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/MemberImplementsInterfaceAnalyzer.cs @@ -38,7 +38,7 @@ public IEnumerable Analyze(ISymbol analyzedSymbol, AnalyzerContext cont Debug.Assert(!member.IsStatic); var baseMembers = InheritanceHelper.GetBaseMembers(member, includeImplementedInterfaces: true); - return baseMembers.Where(m => m.DeclaringTypeDefinition.Kind == TypeKind.Interface); + return baseMembers.Where(m => m.DeclaringTypeDefinition?.Kind == TypeKind.Interface); } public bool Show(ISymbol symbol) diff --git a/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodImplementedByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodImplementedByAnalyzer.cs index e0d0768025..89da791ed6 100644 --- a/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodImplementedByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodImplementedByAnalyzer.cs @@ -16,13 +16,9 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Diagnostics; using System.Linq; -using System.Text; -using System.Threading.Tasks; using ICSharpCode.Decompiler.TypeSystem; @@ -47,17 +43,19 @@ public IEnumerable Analyze(ISymbol analyzedSymbol, AnalyzerContext cont IEnumerable AnalyzeType(IMethod analyzedEntity, ITypeDefinition type) { + if (analyzedEntity.DeclaringTypeDefinition?.ParentModule?.MetadataFile == null) + yield break; var token = analyzedEntity.MetadataToken; var declaringTypeToken = analyzedEntity.DeclaringTypeDefinition.MetadataToken; var module = analyzedEntity.DeclaringTypeDefinition.ParentModule.MetadataFile; var allTypes = type.GetAllBaseTypeDefinitions(); - if (!allTypes.Any(t => t.MetadataToken == declaringTypeToken && t.ParentModule.MetadataFile == module)) + if (!allTypes.Any(t => t.MetadataToken == declaringTypeToken && t.ParentModule?.MetadataFile == module)) yield break; foreach (var method in type.Methods) { var baseMembers = InheritanceHelper.GetBaseMembers(method, true); - if (baseMembers.Any(m => m.MetadataToken == token && m.ParentModule.MetadataFile == module)) + if (baseMembers.Any(m => m.MetadataToken == token && m.ParentModule?.MetadataFile == module)) yield return method; } } diff --git a/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs index 5c6e4bd10a..ab9c4fe71f 100644 --- a/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs @@ -17,7 +17,6 @@ // DEALINGS IN THE SOFTWARE. using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Diagnostics; using System.Linq; @@ -46,11 +45,13 @@ public IEnumerable Analyze(ISymbol analyzedSymbol, AnalyzerContext cont IEnumerable AnalyzeType(IMethod analyzedEntity, ITypeDefinition type) { + if (analyzedEntity.DeclaringTypeDefinition?.ParentModule?.MetadataFile == null) + yield break; var token = analyzedEntity.MetadataToken; var declaringTypeToken = analyzedEntity.DeclaringTypeDefinition.MetadataToken; var module = analyzedEntity.DeclaringTypeDefinition.ParentModule.MetadataFile; var allTypes = type.GetAllBaseTypeDefinitions(); - if (!allTypes.Any(t => t.MetadataToken == declaringTypeToken && t.ParentModule.MetadataFile == module)) + if (!allTypes.Any(t => t.MetadataToken == declaringTypeToken && t.ParentModule?.MetadataFile == module)) yield break; foreach (var method in type.Methods) @@ -58,7 +59,7 @@ IEnumerable AnalyzeType(IMethod analyzedEntity, ITypeDefinition type) if (!method.IsOverride) continue; var baseMembers = InheritanceHelper.GetBaseMembers(method, false); - if (baseMembers.Any(p => p.MetadataToken == token && p.ParentModule.MetadataFile == module)) + if (baseMembers.Any(p => p.MetadataToken == token && p.ParentModule?.MetadataFile == module)) { yield return method; } diff --git a/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsedByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsedByAnalyzer.cs index da5f747d35..702d77a7d9 100644 --- a/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsedByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsedByAnalyzer.cs @@ -18,12 +18,10 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Diagnostics; using System.Linq; using System.Reflection.Metadata; -using ICSharpCode.Decompiler; using ICSharpCode.Decompiler.Disassembler; using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; @@ -46,9 +44,11 @@ public IEnumerable Analyze(ISymbol analyzedSymbol, AnalyzerContext cont var analyzedMethod = (IMethod)analyzedSymbol; var analyzedBaseMethod = (IMethod)InheritanceHelper.GetBaseMember(analyzedMethod); + if (analyzedMethod.ParentModule?.MetadataFile == null) + yield break; var mapping = context.Language .GetCodeMappingInfo(analyzedMethod.ParentModule.MetadataFile, - analyzedMethod.DeclaringTypeDefinition.MetadataToken); + analyzedMethod.DeclaringTypeDefinition!.MetadataToken); var parentMethod = mapping.GetParentMethod((MethodDefinitionHandle)analyzedMethod.MetadataToken); if (parentMethod != analyzedMethod.MetadataToken) @@ -57,6 +57,8 @@ public IEnumerable Analyze(ISymbol analyzedSymbol, AnalyzerContext cont var scope = context.GetScopeOf(analyzedMethod); foreach (var type in scope.GetTypesInScope(context.CancellationToken)) { + if (type.ParentModule?.MetadataFile == null) + continue; var parentModule = (MetadataModule)type.ParentModule; mapping = null; var methods = type.GetMembers(m => m is IMethod, Options).OfType(); @@ -110,9 +112,9 @@ bool IsUsedInMethod(IMethod analyzedEntity, IMethod analyzedBaseMethod, IMethod return ScanMethodBody(analyzedEntity, method, analyzedBaseMethod, context.GetMethodBody(method)); } - static bool ScanMethodBody(IMethod analyzedMethod, IMethod method, IMethod analyzedBaseMethod, MethodBodyBlock methodBody) + static bool ScanMethodBody(IMethod analyzedMethod, IMethod method, IMethod analyzedBaseMethod, MethodBodyBlock? methodBody) { - if (methodBody == null) + if (methodBody == null || method.ParentModule?.MetadataFile == null) return false; var mainModule = (MetadataModule)method.ParentModule; @@ -145,7 +147,7 @@ static bool ScanMethodBody(IMethod analyzedMethod, IMethod method, IMethod analy } } - IMember m; + IMember? m; try { m = (mainModule.ResolveEntity(member, genericContext) as IMember)?.MemberDefinition; @@ -192,7 +194,7 @@ static bool IsSupportedOpCode(ILOpCode opCode) static bool IsSameMember(IMember analyzedMethod, IMember m) { return m.MetadataToken == analyzedMethod.MetadataToken - && m.ParentModule.MetadataFile == analyzedMethod.ParentModule.MetadataFile; + && m.ParentModule?.MetadataFile == analyzedMethod.ParentModule!.MetadataFile; } } } diff --git a/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsesAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsesAnalyzer.cs index 6bfe94ea8b..2b361ec000 100644 --- a/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsesAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodUsesAnalyzer.cs @@ -38,7 +38,7 @@ class MethodUsesAnalyzer : IAnalyzer public IEnumerable Analyze(ISymbol symbol, AnalyzerContext context) { - if (symbol is IMethod method && method.ParentModule.MetadataFile is MetadataFile corFile) + if (symbol is IMethod method && method.ParentModule?.MetadataFile is MetadataFile corFile) { var typeSystem = context.GetOrCreateTypeSystem(corFile); return context.Language.GetCodeMappingInfo(corFile, method.MetadataToken) @@ -95,7 +95,7 @@ IEnumerable ScanMethod(MethodDefinitionHandle handle, DecompilerTypeSys case HandleKind.TypeDefinition: case HandleKind.TypeReference: case HandleKind.TypeSpecification: - IType ty; + IType? ty; try { ty = module.ResolveType(member, genericContext); @@ -110,7 +110,7 @@ IEnumerable ScanMethod(MethodDefinitionHandle handle, DecompilerTypeSys case HandleKind.MethodSpecification: case HandleKind.MemberReference: case HandleKind.FieldDefinition: - IEntity m; + IEntity? m; try { m = module.ResolveEntity(member, genericContext); diff --git a/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs index 0d74e068ea..a24787a880 100644 --- a/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs @@ -41,9 +41,16 @@ public IEnumerable Analyze(ISymbol analyzedSymbol, AnalyzerContext cont { Debug.Assert(analyzedSymbol is IMethod); var analyzedMethod = (IMethod)analyzedSymbol; + + if (analyzedMethod.ParentModule?.MetadataFile == null) + yield break; + + if (analyzedMethod.DeclaringTypeDefinition?.MetadataToken.IsNil != true) + yield break; + var mapping = context.Language .GetCodeMappingInfo(analyzedMethod.ParentModule.MetadataFile, - analyzedMethod.DeclaringTypeDefinition.MetadataToken); + analyzedMethod.DeclaringTypeDefinition?.MetadataToken ?? default); var parentMethod = mapping.GetParentMethod((MethodDefinitionHandle)analyzedMethod.MetadataToken); if (parentMethod != analyzedMethod.MetadataToken) @@ -52,7 +59,9 @@ public IEnumerable Analyze(ISymbol analyzedSymbol, AnalyzerContext cont var scope = context.GetScopeOf(analyzedMethod); foreach (var type in scope.GetTypesInScope(context.CancellationToken)) { - var parentModule = (MetadataModule)type.ParentModule; + var parentModule = (MetadataModule?)type.ParentModule; + if (parentModule?.MetadataFile == null) + continue; mapping = context.Language.GetCodeMappingInfo(parentModule.MetadataFile, type.MetadataToken); var methods = type.GetMembers(m => m is IMethod, Options).OfType(); foreach (var method in methods) @@ -105,9 +114,9 @@ bool IsUsedInMethod(IMethod analyzedEntity, IMethod method, AnalyzerContext cont return ScanMethodBody(analyzedEntity, method, context.GetMethodBody(method)); } - static bool ScanMethodBody(IMethod analyzedMethod, IMethod method, MethodBodyBlock methodBody) + static bool ScanMethodBody(IMethod analyzedMethod, IMethod method, MethodBodyBlock? methodBody) { - if (methodBody == null) + if (methodBody == null || method.ParentModule?.MetadataFile == null) return false; var mainModule = (MetadataModule)method.ParentModule; var blob = methodBody.GetILReader(); @@ -131,7 +140,7 @@ static bool ScanMethodBody(IMethod analyzedMethod, IMethod method, MethodBodyBlo case HandleKind.MethodSpecification: case HandleKind.MemberReference: var m = (mainModule.ResolveEntity(member, genericContext) as IMember)?.MemberDefinition; - if (m != null && m.MetadataToken == analyzedMethod.MetadataToken && m.ParentModule.MetadataFile == analyzedMethod.ParentModule.MetadataFile) + if (m != null && m.MetadataToken == analyzedMethod.MetadataToken && m.ParentModule?.MetadataFile == analyzedMethod.ParentModule!.MetadataFile) { return true; } diff --git a/ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyImplementedByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyImplementedByAnalyzer.cs index 0b4e7affd6..4188822f40 100644 --- a/ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyImplementedByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyImplementedByAnalyzer.cs @@ -17,7 +17,6 @@ // DEALINGS IN THE SOFTWARE. using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Diagnostics; using System.Linq; @@ -44,17 +43,19 @@ public IEnumerable Analyze(ISymbol analyzedSymbol, AnalyzerContext cont IEnumerable AnalyzeType(IProperty analyzedEntity, ITypeDefinition type) { + if (analyzedEntity.DeclaringTypeDefinition?.ParentModule?.MetadataFile == null) + yield break; var token = analyzedEntity.MetadataToken; var declaringTypeToken = analyzedEntity.DeclaringTypeDefinition.MetadataToken; var module = analyzedEntity.DeclaringTypeDefinition.ParentModule.MetadataFile; var allTypes = type.GetAllBaseTypeDefinitions(); - if (!allTypes.Any(t => t.MetadataToken == declaringTypeToken && t.ParentModule.MetadataFile == module)) + if (!allTypes.Any(t => t.MetadataToken == declaringTypeToken && t.ParentModule?.MetadataFile == module)) yield break; foreach (var property in type.Properties) { var baseMembers = InheritanceHelper.GetBaseMembers(property, true); - if (baseMembers.Any(m => m.MetadataToken == token && m.ParentModule.MetadataFile == module)) + if (baseMembers.Any(m => m.MetadataToken == token && m.ParentModule?.MetadataFile == module)) yield return property; } } diff --git a/ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs index 7652252170..1eb0d4a004 100644 --- a/ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs @@ -16,13 +16,9 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Diagnostics; using System.Linq; -using System.Text; -using System.Threading.Tasks; using ICSharpCode.Decompiler.TypeSystem; @@ -47,11 +43,13 @@ public IEnumerable Analyze(ISymbol analyzedSymbol, AnalyzerContext cont IEnumerable AnalyzeType(IProperty analyzedEntity, ITypeDefinition type) { + if (analyzedEntity.DeclaringTypeDefinition?.ParentModule?.MetadataFile == null) + yield break; var token = analyzedEntity.MetadataToken; var declaringTypeToken = analyzedEntity.DeclaringTypeDefinition.MetadataToken; var module = analyzedEntity.DeclaringTypeDefinition.ParentModule.MetadataFile; var allTypes = type.GetAllBaseTypeDefinitions(); - if (!allTypes.Any(t => t.MetadataToken == declaringTypeToken && t.ParentModule.MetadataFile == module)) + if (!allTypes.Any(t => t.MetadataToken == declaringTypeToken && t.ParentModule?.MetadataFile == module)) yield break; foreach (var property in type.Properties) @@ -59,7 +57,7 @@ IEnumerable AnalyzeType(IProperty analyzedEntity, ITypeDefinition type) if (!property.IsOverride) continue; var baseMembers = InheritanceHelper.GetBaseMembers(property, false); - if (baseMembers.Any(p => p.MetadataToken == token && p.ParentModule.MetadataFile == module)) + if (baseMembers.Any(p => p.MetadataToken == token && p.ParentModule?.MetadataFile == module)) { yield return property; } diff --git a/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExposedByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExposedByAnalyzer.cs index 6174e2d8c3..3f4fd59b21 100644 --- a/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExposedByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExposedByAnalyzer.cs @@ -16,13 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ICSharpCode.ILSpyX.Analyzers.Builtin @@ -52,7 +47,7 @@ IEnumerable ScanType(ITypeDefinition analyzedType, ITypeDefinition type { if (analyzedType.Kind == TypeKind.Enum && type.MetadataToken == analyzedType.MetadataToken - && type.ParentModule.MetadataFile == analyzedType.ParentModule.MetadataFile) + && type.ParentModule?.MetadataFile == analyzedType.ParentModule?.MetadataFile) yield break; if (!context.Language.ShowMember(type)) diff --git a/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExtensionMethodsAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExtensionMethodsAnalyzer.cs index 11f1d7bd67..b557110212 100644 --- a/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExtensionMethodsAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeExtensionMethodsAnalyzer.cs @@ -17,7 +17,6 @@ // DEALINGS IN THE SOFTWARE. using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Diagnostics; using ICSharpCode.Decompiler.TypeSystem; @@ -48,6 +47,9 @@ IEnumerable ScanType(ITypeDefinition analyzedType, ITypeDefinition type if (!type.HasExtensionMethods) yield break; + if (analyzedType.ParentModule?.MetadataFile == null) + yield break; + foreach (IMethod method in type.Methods) { if (!method.IsExtensionMethod) @@ -56,7 +58,7 @@ IEnumerable ScanType(ITypeDefinition analyzedType, ITypeDefinition type var firstParamType = method.Parameters[0].Type.GetDefinition(); if (firstParamType != null && firstParamType.MetadataToken == analyzedType.MetadataToken && - firstParamType.ParentModule.MetadataFile == analyzedType.ParentModule.MetadataFile) + firstParamType.ParentModule?.MetadataFile == analyzedType.ParentModule.MetadataFile) yield return method; } } diff --git a/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs index 4f5c82e5ea..603f3e5b0f 100644 --- a/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs @@ -18,12 +18,9 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Diagnostics; using System.Linq; using System.Reflection.Metadata; -using System.Text; -using System.Threading.Tasks; using ICSharpCode.Decompiler; using ICSharpCode.Decompiler.Disassembler; @@ -46,6 +43,8 @@ public IEnumerable Analyze(ISymbol analyzedSymbol, AnalyzerContext cont var scope = context.GetScopeOf((ITypeDefinition)analyzedSymbol); foreach (var type in scope.GetTypesInScope(context.CancellationToken)) { + if (type.ParentModule?.MetadataFile == null) + continue; var mappingInfo = context.Language.GetCodeMappingInfo(type.ParentModule.MetadataFile, type.MetadataToken); var methods = type.GetMembers(m => m is IMethod, Options).OfType(); foreach (var method in methods) @@ -94,9 +93,9 @@ bool IsUsedInMethod(ITypeDefinition analyzedEntity, IMethod method, CodeMappingI return ScanMethodBody(analyzedEntity, method, context.GetMethodBody(method)); } - bool ScanMethodBody(ITypeDefinition analyzedEntity, IMethod method, MethodBodyBlock methodBody) + bool ScanMethodBody(ITypeDefinition analyzedEntity, IMethod method, MethodBodyBlock? methodBody) { - if (methodBody == null) + if (methodBody == null || method.ParentModule?.MetadataFile == null) return false; var blob = methodBody.GetILReader(); var module = (MetadataModule)method.ParentModule; @@ -134,7 +133,7 @@ bool ScanMethodBody(ITypeDefinition analyzedEntity, IMethod method, MethodBodyBl continue; if (ctor.DeclaringTypeDefinition?.MetadataToken == analyzedEntity.MetadataToken - && ctor.ParentModule.MetadataFile == analyzedEntity.ParentModule.MetadataFile) + && ctor.ParentModule?.MetadataFile == analyzedEntity.ParentModule!.MetadataFile) return true; } diff --git a/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeUsedByAnalyzer.cs b/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeUsedByAnalyzer.cs index cfbe5d665e..e4a10801f2 100644 --- a/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeUsedByAnalyzer.cs +++ b/ICSharpCode.ILSpyX/Analyzers/Builtin/TypeUsedByAnalyzer.cs @@ -107,7 +107,7 @@ static IEnumerable AnalyzeModule(ITypeDefinition analyzedType, Analyzer if (found || ScanMethodBody(analyzedType, module, md, decoder)) { var method = typeSystem.MainModule.GetDefinition(h); - yield return method?.AccessorOwner ?? method; + yield return method.AccessorOwner ?? method; } } @@ -221,7 +221,7 @@ private static bool AnalyzeCustomAttributeValue(CustomAttributeValue 0 && Results.Count == MAX_RESULTS) { - Results.Add(new SearchResult { Name = Properties.Resources.SearchAbortedMoreThan1000ResultsFound }); + Results.Add(new SearchResult { + Name = Properties.Resources.SearchAbortedMoreThan1000ResultsFound, + Location = null!, + Assembly = null!, + Image = null!, + LocationImage = null!, + AssemblyImage = null!, + }); currentSearch.Cancel(); } }