diff --git a/ICSharpCode.BamlDecompiler/Baml/BamlContext.cs b/ICSharpCode.BamlDecompiler/Baml/BamlContext.cs index 21a2e733f..a310a2380 100644 --- a/ICSharpCode.BamlDecompiler/Baml/BamlContext.cs +++ b/ICSharpCode.BamlDecompiler/Baml/BamlContext.cs @@ -116,7 +116,7 @@ namespace ICSharpCode.BamlDecompiler.Baml private IModule FindMatchingReference(AssemblyNameReference name) { - IModule bestMatch = null; + IModule? bestMatch = null; foreach (var module in TypeSystem.ReferencedModules) { if (module.AssemblyName == name.Name) diff --git a/ICSharpCode.BamlDecompiler/Baml/BamlNode.cs b/ICSharpCode.BamlDecompiler/Baml/BamlNode.cs index c8049a668..89062e129 100644 --- a/ICSharpCode.BamlDecompiler/Baml/BamlNode.cs +++ b/ICSharpCode.BamlDecompiler/Baml/BamlNode.cs @@ -111,7 +111,7 @@ namespace ICSharpCode.BamlDecompiler.Baml { Debug.Assert(document.Count > 0 && document[0].Type == BamlRecordType.DocumentStart); - BamlBlockNode current = null; + BamlBlockNode? current = null; var stack = new Stack(); for (int i = 0; i < document.Count; i++) diff --git a/ICSharpCode.BamlDecompiler/Baml/BamlReader.cs b/ICSharpCode.BamlDecompiler/Baml/BamlReader.cs index bed8f934a..5137c2fce 100644 --- a/ICSharpCode.BamlDecompiler/Baml/BamlReader.cs +++ b/ICSharpCode.BamlDecompiler/Baml/BamlReader.cs @@ -91,7 +91,7 @@ namespace ICSharpCode.BamlDecompiler.Baml long pos = str.Position; var type = (BamlRecordType)reader.ReadByte(); - BamlRecord rec = null; + BamlRecord? rec = null; switch (type) { case BamlRecordType.AssemblyInfo: diff --git a/ICSharpCode.BamlDecompiler/Rewrite/ConnectionIdRewritePass.cs b/ICSharpCode.BamlDecompiler/Rewrite/ConnectionIdRewritePass.cs index 496080af1..4c7a518fc 100644 --- a/ICSharpCode.BamlDecompiler/Rewrite/ConnectionIdRewritePass.cs +++ b/ICSharpCode.BamlDecompiler/Rewrite/ConnectionIdRewritePass.cs @@ -127,7 +127,7 @@ namespace ICSharpCode.BamlDecompiler.Rewrite return; var connect = connectorInterface.GetMethods(m => m.Name == "Connect").SingleOrDefault(); - IMethod connectMethod = null; + IMethod? connectMethod = null; MethodDefinition connectMetadataEntry = default; var module = ctx.TypeSystem.MainModule.MetadataFile; diff --git a/ICSharpCode.BamlDecompiler/Xaml/XamlType.cs b/ICSharpCode.BamlDecompiler/Xaml/XamlType.cs index f2f907572..709e18c04 100644 --- a/ICSharpCode.BamlDecompiler/Xaml/XamlType.cs +++ b/ICSharpCode.BamlDecompiler/Xaml/XamlType.cs @@ -62,7 +62,7 @@ namespace ICSharpCode.BamlDecompiler.Xaml // Since XmlnsProperty records are inside the element, // the namespace is resolved after processing the element body. - string xmlNs = null; + string? xmlNs = null; if (elem.Annotation() != null) xmlNs = elem.Annotation().LookupXmlns(FullAssemblyName, TypeNamespace); if (xmlNs == null) diff --git a/ICSharpCode.BamlDecompiler/XamlContext.cs b/ICSharpCode.BamlDecompiler/XamlContext.cs index bd24cbeaf..4558b13b3 100644 --- a/ICSharpCode.BamlDecompiler/XamlContext.cs +++ b/ICSharpCode.BamlDecompiler/XamlContext.cs @@ -143,7 +143,7 @@ namespace ICSharpCode.BamlDecompiler XamlType type; string name; - IMember member; + IMember? member; if (id > 0x7fff) { diff --git a/ICSharpCode.Decompiler/CSharp/OutputVisitor/TextWriterTokenWriter.cs b/ICSharpCode.Decompiler/CSharp/OutputVisitor/TextWriterTokenWriter.cs index 477ba3a6f..1862be080 100644 --- a/ICSharpCode.Decompiler/CSharp/OutputVisitor/TextWriterTokenWriter.cs +++ b/ICSharpCode.Decompiler/CSharp/OutputVisitor/TextWriterTokenWriter.cs @@ -499,7 +499,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor StringBuilder sb = new StringBuilder(); foreach (char ch in str) { - string s = ch == '"' ? "\\\"" : ConvertChar(ch); + string? s = ch == '"' ? "\\\"" : ConvertChar(ch); if (s != null) sb.Append(s); else diff --git a/ICSharpCode.Decompiler/Util/CSharpPrimitiveCast.cs b/ICSharpCode.Decompiler/Util/CSharpPrimitiveCast.cs index ee940d9d8..015251fe9 100644 --- a/ICSharpCode.Decompiler/Util/CSharpPrimitiveCast.cs +++ b/ICSharpCode.Decompiler/Util/CSharpPrimitiveCast.cs @@ -17,6 +17,7 @@ // DEALINGS IN THE SOFTWARE. using System; +using System.Diagnostics.CodeAnalysis; namespace ICSharpCode.Decompiler.Util { @@ -34,7 +35,9 @@ namespace ICSharpCode.Decompiler.Util /// /// Overflow checking is enabled and an overflow occurred. /// The cast is invalid, e.g. casting a boolean to an integer. - public static object? Cast(TypeCode targetType, object input, bool checkForOverflow) + //[return: MaybeNull] + //[return: NotNullIfNotNull(nameof(input))] + public static object Cast(TypeCode targetType, [MaybeNull] object input, bool checkForOverflow) { if (input == null) return null; diff --git a/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs b/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs index 57e08d5e3..8cc359925 100644 --- a/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs +++ b/ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs @@ -122,7 +122,7 @@ Examples: private async Task OnExecuteAsync(CommandLineApplication app) { - Task updateCheckTask = null; + Task? updateCheckTask = null; if (!DisableUpdateCheck) { updateCheckTask = DotNetToolUpdateChecker.CheckForPackageUpdateAsync("ilspycmd"); @@ -214,7 +214,7 @@ Examples: } else if (CreateDebugInfoFlag) { - string pdbFileName = null; + string? pdbFileName = null; if (outputDirectory != null) { string outputName = Path.GetFileNameWithoutExtension(fileName); diff --git a/ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs b/ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs index 970618e8e..3a94ffcae 100644 --- a/ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs +++ b/ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs @@ -205,11 +205,11 @@ namespace ILSpy.BamlDecompiler.Tests return line.Trim(); } - Stream LoadBaml(Resource res, string name) + Stream? LoadBaml(Resource res, string name) { if (res.ResourceType != ResourceType.Embedded) return null; - Stream s = res.TryOpenStream(); + Stream? s = res.TryOpenStream(); if (s == null) return null; s.Position = 0; diff --git a/ILSpy.ReadyToRun/ReadyToRunDisassembler.cs b/ILSpy.ReadyToRun/ReadyToRunDisassembler.cs index 0b7d0ee6c..6cd03c558 100644 --- a/ILSpy.ReadyToRun/ReadyToRunDisassembler.cs +++ b/ILSpy.ReadyToRun/ReadyToRunDisassembler.cs @@ -67,14 +67,14 @@ namespace ICSharpCode.ILSpy.ReadyToRun } } - Dictionary unwindInfo = null; + Dictionary? unwindInfo = null; if (ReadyToRunOptions.GetIsShowUnwindInfo(null) && bitness == 64) { unwindInfo = WriteUnwindInfo(); } bool isShowDebugInfo = ReadyToRunOptions.GetIsShowDebugInfo(null); - DebugInfoHelper debugInfo = null; + DebugInfoHelper? debugInfo = null; if (isShowDebugInfo) { debugInfo = WriteDebugInfo(); @@ -98,7 +98,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun } string disassemblyFormat = ReadyToRunOptions.GetDisassemblyFormat(null); - Formatter formatter = null; + Formatter? formatter = null; if (disassemblyFormat.Equals(ReadyToRunOptions.intel)) { formatter = new NasmFormatter(); diff --git a/ILSpy.ReadyToRun/ReadyToRunLanguage.cs b/ILSpy.ReadyToRun/ReadyToRunLanguage.cs index b086bd54c..a963dee76 100644 --- a/ILSpy.ReadyToRun/ReadyToRunLanguage.cs +++ b/ILSpy.ReadyToRun/ReadyToRunLanguage.cs @@ -114,7 +114,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun public override ProjectId DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options) { - PEFile module = assembly.GetMetadataFileAsync().GetAwaiter().GetResult() as PEFile; + PEFile? module = assembly.GetMetadataFileAsync().GetAwaiter().GetResult() as PEFile; ReadyToRunReaderCacheEntry cacheEntry = GetReader(assembly, module); if (cacheEntry.readyToRunReader == null) { @@ -137,7 +137,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options) { - PEFile module = method.ParentModule.MetadataFile as PEFile; + PEFile? module = method.ParentModule.MetadataFile as PEFile; ReadyToRunReaderCacheEntry cacheEntry = GetReader(module.GetLoadedAssembly(), module); if (cacheEntry.readyToRunReader == null) { @@ -158,7 +158,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun } if (cacheEntry.methodMap == null) { - IEnumerable readyToRunMethods = null; + IEnumerable? readyToRunMethods = null; if (cacheEntry.compositeReadyToRunReader == null) { readyToRunMethods = reader.Methods; @@ -192,8 +192,8 @@ namespace ICSharpCode.ILSpy.ReadyToRun #endif foreach (RuntimeFunction runtimeFunction in readyToRunMethod.RuntimeFunctions) { - PEFile file = null; - ReadyToRunReader disassemblingReader = null; + PEFile? file = null; + ReadyToRunReader? disassemblingReader = null; if (cacheEntry.compositeReadyToRunReader == null) { disassemblingReader = reader; diff --git a/ILSpy/AboutPage.cs b/ILSpy/AboutPage.cs index 0fbaa89ba..f9f969eda 100644 --- a/ILSpy/AboutPage.cs +++ b/ILSpy/AboutPage.cs @@ -90,11 +90,11 @@ namespace ICSharpCode.ILSpy plugin.Write(output); output.WriteLine(); output.Address = new Uri("resource://AboutPage"); - using (Stream s = typeof(AboutPage).Assembly.GetManifestResourceStream(typeof(AboutPage), Resources.ILSpyAboutPageTxt)) + using (Stream? s = typeof(AboutPage).Assembly.GetManifestResourceStream(typeof(AboutPage), Resources.ILSpyAboutPageTxt)) { using (StreamReader r = new StreamReader(s)) { - string line; + string? line; while ((line = r.ReadLine()) != null) { output.WriteLine(line); diff --git a/ILSpy/Analyzers/AnalyzerEntityTreeNode.cs b/ILSpy/Analyzers/AnalyzerEntityTreeNode.cs index d0917a982..3dfab8c06 100644 --- a/ILSpy/Analyzers/AnalyzerEntityTreeNode.cs +++ b/ILSpy/Analyzers/AnalyzerEntityTreeNode.cs @@ -54,7 +54,7 @@ namespace ICSharpCode.ILSpy.Analyzers } this.Children.RemoveAll( delegate (SharpTreeNode n) { - AnalyzerTreeNode an = n as AnalyzerTreeNode; + AnalyzerTreeNode? an = n as AnalyzerTreeNode; return an == null || !an.HandleAssemblyListChanged(removedAssemblies, addedAssemblies); }); return true; diff --git a/ILSpy/Analyzers/AnalyzerRootNode.cs b/ILSpy/Analyzers/AnalyzerRootNode.cs index 17709687f..c47fbe27c 100644 --- a/ILSpy/Analyzers/AnalyzerRootNode.cs +++ b/ILSpy/Analyzers/AnalyzerRootNode.cs @@ -15,7 +15,7 @@ public sealed class AnalyzerRootNode : AnalyzerTreeNode MessageBus.Subscribers += (sender, e) => CurrentAssemblyList_Changed(sender, e); } - void CurrentAssemblyList_Changed(object sender, NotifyCollectionChangedEventArgs e) + void CurrentAssemblyList_Changed(object? sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Reset) { @@ -34,7 +34,7 @@ public sealed class AnalyzerRootNode : AnalyzerTreeNode { this.Children.RemoveAll( delegate (SharpTreeNode n) { - AnalyzerTreeNode an = n as AnalyzerTreeNode; + AnalyzerTreeNode? an = n as AnalyzerTreeNode; return an == null || !an.HandleAssemblyListChanged(removedAssemblies, addedAssemblies); }); return true; diff --git a/ILSpy/Analyzers/AnalyzerTreeViewModel.cs b/ILSpy/Analyzers/AnalyzerTreeViewModel.cs index fc7def755..a9034f59b 100644 --- a/ILSpy/Analyzers/AnalyzerTreeViewModel.cs +++ b/ILSpy/Analyzers/AnalyzerTreeViewModel.cs @@ -73,7 +73,7 @@ namespace ICSharpCode.ILSpy.Analyzers { Show(); - AnalyzerTreeNode target = default; + AnalyzerTreeNode? target = default; if (node is AnalyzerEntityTreeNode { Member: { } member }) { diff --git a/ILSpy/App.xaml.cs b/ILSpy/App.xaml.cs index b1d6e3254..fa45bd234 100644 --- a/ILSpy/App.xaml.cs +++ b/ILSpy/App.xaml.cs @@ -224,7 +224,7 @@ namespace ICSharpCode.ILSpy static void ShowErrorBox(object sender, UnhandledExceptionEventArgs e) { - Exception ex = e.ExceptionObject as Exception; + Exception? ex = e.ExceptionObject as Exception; if (ex != null) { UnhandledException(ex); @@ -237,13 +237,13 @@ namespace ICSharpCode.ILSpy internal static void UnhandledException(Exception exception) { Debug.WriteLine(exception.ToString()); - for (Exception ex = exception; ex != null; ex = ex.InnerException) + for (Exception? ex = exception; ex != null; ex = ex.InnerException) { - ReflectionTypeLoadException rtle = ex as ReflectionTypeLoadException; + ReflectionTypeLoadException? rtle = ex as ReflectionTypeLoadException; if (rtle != null && rtle.LoaderExceptions.Length > 0) { exception = rtle.LoaderExceptions[0]; - Debug.WriteLine(exception.ToString()); + Debug.WriteLine(exception?.ToString()); break; } } diff --git a/ILSpy/AvalonEdit/TextMarkerService.cs b/ILSpy/AvalonEdit/TextMarkerService.cs index 5abf534f5..ae5e0dc86 100644 --- a/ILSpy/AvalonEdit/TextMarkerService.cs +++ b/ILSpy/AvalonEdit/TextMarkerService.cs @@ -102,7 +102,7 @@ namespace ICSharpCode.ILSpy.AvalonEdit { if (marker == null) throw new ArgumentNullException(nameof(marker)); - TextMarker m = marker as TextMarker; + TextMarker? m = marker as TextMarker; if (markers != null && markers.Remove(m)) { Redraw(m); @@ -131,7 +131,7 @@ namespace ICSharpCode.ILSpy.AvalonEdit int lineEnd = lineStart + line.Length; foreach (TextMarker marker in markers.FindOverlappingSegments(lineStart, line.Length)) { - Brush foregroundBrush = null; + Brush? foregroundBrush = null; if (marker.ForegroundColor != null) { foregroundBrush = new SolidColorBrush(marker.ForegroundColor.Value); diff --git a/ILSpy/Commands/CommandWrapper.cs b/ILSpy/Commands/CommandWrapper.cs index 15e2d0592..30bd37599 100644 --- a/ILSpy/Commands/CommandWrapper.cs +++ b/ILSpy/Commands/CommandWrapper.cs @@ -32,7 +32,7 @@ namespace ICSharpCode.ILSpy public static ICommand Unwrap(ICommand command) { - CommandWrapper w = command as CommandWrapper; + CommandWrapper? w = command as CommandWrapper; if (w != null) return w.wrappedCommand; else diff --git a/ILSpy/Commands/DecompileAllCommand.cs b/ILSpy/Commands/DecompileAllCommand.cs index 84d53a41f..b86693760 100644 --- a/ILSpy/Commands/DecompileAllCommand.cs +++ b/ILSpy/Commands/DecompileAllCommand.cs @@ -55,7 +55,7 @@ namespace ICSharpCode.ILSpy if (!asm.HasLoadError) { Stopwatch w = Stopwatch.StartNew(); - Exception exception = null; + Exception? exception = null; using (var writer = new System.IO.StreamWriter("c:\\temp\\decompiled\\" + asm.ShortName + ".cs")) { try diff --git a/ILSpy/Commands/DecompileCommand.cs b/ILSpy/Commands/DecompileCommand.cs index 0a7d1a385..07ce981fb 100644 --- a/ILSpy/Commands/DecompileCommand.cs +++ b/ILSpy/Commands/DecompileCommand.cs @@ -56,7 +56,7 @@ namespace ICSharpCode.ILSpy.Commands public void Execute(TextViewContext context) { - IEntity selection = null; + IEntity? selection = null; if (context.SelectedTreeNodes?[0] is IMemberTreeNode node) { selection = node.Member; diff --git a/ILSpy/Commands/DisassembleAllCommand.cs b/ILSpy/Commands/DisassembleAllCommand.cs index 42f1089e2..8907dba99 100644 --- a/ILSpy/Commands/DisassembleAllCommand.cs +++ b/ILSpy/Commands/DisassembleAllCommand.cs @@ -50,7 +50,7 @@ namespace ICSharpCode.ILSpy if (!asm.HasLoadError) { Stopwatch w = Stopwatch.StartNew(); - Exception exception = null; + Exception? exception = null; using (var writer = new System.IO.StreamWriter("c:\\temp\\disassembled\\" + asm.Text.Replace("(", "").Replace(")", "").Replace(' ', '_') + ".il")) { try diff --git a/ILSpy/Commands/ExtractPackageEntryContextMenuEntry.cs b/ILSpy/Commands/ExtractPackageEntryContextMenuEntry.cs index 3f22fa1cd..8dfc5aae6 100644 --- a/ILSpy/Commands/ExtractPackageEntryContextMenuEntry.cs +++ b/ILSpy/Commands/ExtractPackageEntryContextMenuEntry.cs @@ -57,7 +57,7 @@ namespace ICSharpCode.ILSpy return; string fileName = dlg.FileName; - string outputFolderOrFileName = fileName; + string? outputFolderOrFileName = fileName; if (selectedNodes.Length > 1) outputFolderOrFileName = Path.GetDirectoryName(outputFolderOrFileName); @@ -89,7 +89,7 @@ namespace ICSharpCode.ILSpy void SaveEntry(ITextOutput output, PackageEntry entry, string targetFileName) { output.Write(entry.Name + ": "); - using Stream stream = entry.TryOpenStream(); + using Stream? stream = entry.TryOpenStream(); if (stream == null) { output.WriteLine("Could not open stream!"); diff --git a/ILSpy/Commands/SaveCodeContextMenuEntry.cs b/ILSpy/Commands/SaveCodeContextMenuEntry.cs index ada78fcba..d68ad1c7f 100644 --- a/ILSpy/Commands/SaveCodeContextMenuEntry.cs +++ b/ILSpy/Commands/SaveCodeContextMenuEntry.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel.Composition; using System.IO; using System.Linq; using System.Windows; @@ -26,13 +27,11 @@ using ICSharpCode.Decompiler.IL; using ICSharpCode.ILSpy.Options; using ICSharpCode.ILSpy.Properties; using ICSharpCode.ILSpy.TreeNodes; +using ICSharpCode.ILSpy.Util; using ICSharpCode.ILSpy.ViewModels; - -using Microsoft.Win32; using ICSharpCode.ILSpyX.TreeView; -using System.ComponentModel.Composition; -using ICSharpCode.ILSpy.Util; +using Microsoft.Win32; namespace ICSharpCode.ILSpy.TextView { @@ -112,7 +111,7 @@ namespace ICSharpCode.ILSpy.TextView return null; } - string selectedPath = Path.GetDirectoryName(dlg.FileName); + string? selectedPath = Path.GetDirectoryName(dlg.FileName); bool directoryNotEmpty; try { diff --git a/ILSpy/Commands/ScopeSearchToNamespace.cs b/ILSpy/Commands/ScopeSearchToNamespace.cs index 83dceb002..b75c2d140 100644 --- a/ILSpy/Commands/ScopeSearchToNamespace.cs +++ b/ILSpy/Commands/ScopeSearchToNamespace.cs @@ -41,7 +41,7 @@ namespace ICSharpCode.ILSpy public void Execute(TextViewContext context) { string ns = GetNamespace(context); - string searchTerm = searchPane.SearchTerm; + string? searchTerm = searchPane.SearchTerm; string[] args = CommandLineTools.CommandLineToArgumentArray(searchTerm); bool replaced = false; for (int i = 0; i < args.Length; i++) diff --git a/ILSpy/Commands/SelectPdbContextMenuEntry.cs b/ILSpy/Commands/SelectPdbContextMenuEntry.cs index 061ff7e6b..46fa62625 100644 --- a/ILSpy/Commands/SelectPdbContextMenuEntry.cs +++ b/ILSpy/Commands/SelectPdbContextMenuEntry.cs @@ -48,7 +48,7 @@ namespace ICSharpCode.ILSpy await assembly.LoadDebugInfo(dlg.FileName); } - var node = (AssemblyTreeNode)MainWindow.Instance.FindNodeByPath(new[] { assembly.FileName }, true); + var node = (AssemblyTreeNode?)MainWindow.Instance.FindNodeByPath(new[] { assembly.FileName }, true); node.UpdateToolTip(); MainWindow.Instance.SelectNode(node); MainWindow.Instance.RefreshDecompiledView(); diff --git a/ILSpy/ContextMenuEntry.cs b/ILSpy/ContextMenuEntry.cs index fcbdb1bae..27c7c1b24 100644 --- a/ILSpy/ContextMenuEntry.cs +++ b/ILSpy/ContextMenuEntry.cs @@ -26,9 +26,9 @@ using System.Windows.Input; using System.Windows.Media; using ICSharpCode.AvalonEdit; +using ICSharpCode.ILSpy.Controls.TreeView; using ICSharpCode.ILSpy.TextView; using ICSharpCode.ILSpyX.Search; -using ICSharpCode.ILSpy.Controls.TreeView; using ICSharpCode.ILSpyX.TreeView; using TomsToolbox.Composition; @@ -48,37 +48,37 @@ namespace ICSharpCode.ILSpy /// Returns the selected nodes in the tree view. /// Returns null, if context menu does not belong to a tree view. /// - public SharpTreeNode[] SelectedTreeNodes { get; private set; } + public SharpTreeNode[]? SelectedTreeNodes { get; private set; } /// /// Returns the tree view the context menu is assigned to. /// Returns null, if context menu is not assigned to a tree view. /// - public SharpTreeView TreeView { get; private set; } + public SharpTreeView? TreeView { get; private set; } /// /// Returns the text view the context menu is assigned to. /// Returns null, if context menu is not assigned to a text view. /// - public DecompilerTextView TextView { get; private set; } + public DecompilerTextView? TextView { get; private set; } /// /// Returns the list box the context menu is assigned to. /// Returns null, if context menu is not assigned to a list box. /// - public ListBox ListBox { get; private set; } + public ListBox? ListBox { get; private set; } /// /// Returns the data grid the context menu is assigned to. /// Returns null, if context menu is not assigned to a data grid. /// - public DataGrid DataGrid { get; private set; } + public DataGrid? DataGrid { get; private set; } /// /// Returns the reference the mouse cursor is currently hovering above. /// Returns null, if there was no reference found. /// - public ReferenceSegment Reference { get; private set; } + public ReferenceSegment? Reference { get; private set; } /// /// Returns the position in TextView the mouse cursor is currently hovering above. @@ -88,9 +88,9 @@ namespace ICSharpCode.ILSpy public Point MousePosition { get; private set; } - public static TextViewContext Create(SharpTreeView treeView = null, DecompilerTextView textView = null, ListBox listBox = null, DataGrid dataGrid = null) + public static TextViewContext Create(SharpTreeView? treeView = null, DecompilerTextView? textView = null, ListBox? listBox = null, DataGrid? dataGrid = null) { - ReferenceSegment reference; + ReferenceSegment? reference; if (textView != null) reference = textView.GetReferenceSegmentAtMousePosition(); else if (listBox?.SelectedItem is SearchResult result) @@ -115,7 +115,7 @@ namespace ICSharpCode.ILSpy TextView = textView, Reference = reference, Position = position, - MousePosition = ((Visual)textView ?? treeView ?? (Visual)listBox ?? dataGrid).PointToScreen(Mouse.GetPosition((IInputElement)textView ?? treeView ?? (IInputElement)listBox ?? dataGrid)) + MousePosition = ((Visual?)textView ?? treeView ?? (Visual?)listBox ?? dataGrid).PointToScreen(Mouse.GetPosition((IInputElement?)textView ?? treeView ?? (IInputElement?)listBox ?? dataGrid)) }; } } @@ -291,7 +291,7 @@ namespace ICSharpCode.ILSpy { menu = new ContextMenu(); var menuGroups = new Dictionary[]>(); - IExport[] topLevelGroup = null; + IExport[]? topLevelGroup = null; foreach (var group in entries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.ParentMenuID)) { if (group.Key == null) @@ -313,7 +313,7 @@ namespace ICSharpCode.ILSpy bool needSeparatorForCategory = parent.Count > 0; foreach (var entryPair in category) { - IContextMenuEntry entry = entryPair.Value; + IContextMenuEntry? entry = entryPair.Value; if (entry.IsVisible(context)) { if (needSeparatorForCategory) diff --git a/ILSpy/Controls/GridViewColumnAutoSize.cs b/ILSpy/Controls/GridViewColumnAutoSize.cs index 5c833b1cf..0d8f6edf3 100644 --- a/ILSpy/Controls/GridViewColumnAutoSize.cs +++ b/ILSpy/Controls/GridViewColumnAutoSize.cs @@ -52,25 +52,25 @@ namespace ICSharpCode.ILSpy.Controls static void AutoWidthPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) { - ListView grid = sender as ListView; + ListView? grid = sender as ListView; if (grid == null) return; grid.SizeChanged += delegate (object listView, SizeChangedEventArgs e) { - ListView lv = listView as ListView; + ListView? lv = listView as ListView; if (lv == null) return; - GridView v = lv.View as GridView; + GridView? v = lv.View as GridView; if (v == null) return; CalculateSizes(v, GetAutoWidth(lv), e.NewSize.Width); }; - GridView view = grid.View as GridView; + GridView? view = grid.View as GridView; if (view == null) return; CalculateSizes(view, args.NewValue as string, grid.ActualWidth); } - static void CalculateSizes(GridView view, string sizeValue, double fullWidth) + static void CalculateSizes(GridView view, string? sizeValue, double fullWidth) { string[] sizes = (sizeValue ?? "").Split(';'); diff --git a/ILSpy/Controls/SearchBox.cs b/ILSpy/Controls/SearchBox.cs index e7ec45df3..f07dc24c1 100644 --- a/ILSpy/Controls/SearchBox.cs +++ b/ILSpy/Controls/SearchBox.cs @@ -137,7 +137,7 @@ namespace ICSharpCode.ILSpy.Controls { base.OnApplyTemplate(); - Border iconBorder = GetTemplateChild("PART_IconBorder") as Border; + Border? iconBorder = GetTemplateChild("PART_IconBorder") as Border; if (iconBorder != null) { iconBorder.MouseLeftButtonUp += IconBorder_MouseLeftButtonUp; diff --git a/ILSpy/Controls/SortableGridViewColumn.cs b/ILSpy/Controls/SortableGridViewColumn.cs index 336f5442c..7fe23d447 100644 --- a/ILSpy/Controls/SortableGridViewColumn.cs +++ b/ILSpy/Controls/SortableGridViewColumn.cs @@ -73,7 +73,7 @@ namespace ICSharpCode.ILSpy.Controls static void OnSortDirectionChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) { - ListView grid = sender as ListView; + ListView? grid = sender as ListView; if (grid != null) { SortableGridViewColumn col = GetCurrentSortColumn(grid); @@ -101,7 +101,7 @@ namespace ICSharpCode.ILSpy.Controls static void OnCurrentSortColumnChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) { - ListView grid = sender as ListView; + ListView? grid = sender as ListView; if (grid != null) { SortableGridViewColumn oldColumn = (SortableGridViewColumn)args.OldValue; @@ -134,7 +134,7 @@ namespace ICSharpCode.ILSpy.Controls static void OnSortModeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) { - ListView grid = sender as ListView; + ListView? grid = sender as ListView; if (grid != null) { if ((ListViewSortMode)args.NewValue != ListViewSortMode.None) @@ -146,8 +146,8 @@ namespace ICSharpCode.ILSpy.Controls static void GridViewColumnHeaderClickHandler(object sender, RoutedEventArgs e) { - ListView grid = sender as ListView; - GridViewColumnHeader headerClicked = e.OriginalSource as GridViewColumnHeader; + ListView? grid = sender as ListView; + GridViewColumnHeader? headerClicked = e.OriginalSource as GridViewColumnHeader; if (grid != null && headerClicked != null && headerClicked.Role != GridViewColumnHeaderRole.Padding) { if (headerClicked.Column == GetCurrentSortColumn(grid)) @@ -188,7 +188,7 @@ namespace ICSharpCode.ILSpy.Controls string sortBy = column.SortBy; if (sortBy == null) { - Binding binding = column.DisplayMemberBinding as Binding; + Binding? binding = column.DisplayMemberBinding as Binding; if (binding != null && binding.Path != null) { sortBy = binding.Path.Path; diff --git a/ILSpy/Controls/TreeView/SharpTreeView.cs b/ILSpy/Controls/TreeView/SharpTreeView.cs index 845ba297c..e8a76208c 100644 --- a/ILSpy/Controls/TreeView/SharpTreeView.cs +++ b/ILSpy/Controls/TreeView/SharpTreeView.cs @@ -176,8 +176,8 @@ namespace ICSharpCode.ILSpy.Controls.TreeView // Deselect nodes that are being hidden, if any remain in the tree if (e.Action == NotifyCollectionChangedAction.Remove && Items.Count > 0) { - List selectedOldItems = null; - foreach (SharpTreeNode node in e.OldItems) + List? selectedOldItems = null; + foreach (SharpTreeNode node in e.OldItems!) { if (node.IsSelected) { @@ -194,7 +194,7 @@ namespace ICSharpCode.ILSpy.Controls.TreeView } } - void UpdateFocusedNode(List newSelection, int topSelectedIndex) + void UpdateFocusedNode(List? newSelection, int topSelectedIndex) { if (updatesLocked) return; @@ -222,7 +222,7 @@ namespace ICSharpCode.ILSpy.Controls.TreeView protected override void PrepareContainerForItemOverride(DependencyObject element, object item) { base.PrepareContainerForItemOverride(element, item); - SharpTreeViewItem container = element as SharpTreeViewItem; + SharpTreeViewItem? container = element as SharpTreeViewItem; container.ParentTreeView = this; // Make sure that the line renderer takes into account the new bound data if (container.NodeView != null) @@ -244,7 +244,7 @@ namespace ICSharpCode.ILSpy.Controls.TreeView SharpTreeNode lastVisibleChild = node; while (true) { - SharpTreeNode tmp = lastVisibleChild.Children.LastOrDefault(c => c.IsVisible); + SharpTreeNode? tmp = lastVisibleChild.Children.LastOrDefault(c => c.IsVisible); if (tmp != null) { lastVisibleChild = tmp; @@ -269,7 +269,7 @@ namespace ICSharpCode.ILSpy.Controls.TreeView protected override void OnKeyDown(KeyEventArgs e) { - SharpTreeViewItem container = e.OriginalSource as SharpTreeViewItem; + SharpTreeViewItem? container = e.OriginalSource as SharpTreeViewItem; switch (e.Key) { case Key.Left: @@ -422,7 +422,7 @@ namespace ICSharpCode.ILSpy.Controls.TreeView object? OnFocusItem(object item) { - FrameworkElement element = this.ItemContainerGenerator.ContainerFromItem(item) as FrameworkElement; + FrameworkElement? element = this.ItemContainerGenerator.ContainerFromItem(item) as FrameworkElement; if (element != null) { element.Focus(); @@ -606,7 +606,7 @@ namespace ICSharpCode.ILSpy.Controls.TreeView void TryAddDropTarget(List targets, SharpTreeViewItem item, DropPlace place, DragEventArgs e) { - SharpTreeNode node; + SharpTreeNode? node; int index; GetNodeAndIndex(item, place, out node, out index); @@ -627,7 +627,7 @@ namespace ICSharpCode.ILSpy.Controls.TreeView } } - void GetNodeAndIndex(SharpTreeViewItem item, DropPlace place, out SharpTreeNode node, out int index) + void GetNodeAndIndex(SharpTreeViewItem item, DropPlace place, out SharpTreeNode? node, out int index) { node = null; index = 0; @@ -697,7 +697,7 @@ namespace ICSharpCode.ILSpy.Controls.TreeView insertMarker.Margin = new Thickness(p.X, p.Y, 0, 0); - SharpTreeNodeView secondNodeView = null; + SharpTreeNodeView? secondNodeView = null; var index = flattener.IndexOf(item.Node); if (place == DropPlace.Before) diff --git a/ILSpy/Controls/TreeView/SharpTreeViewTextSearch.cs b/ILSpy/Controls/TreeView/SharpTreeViewTextSearch.cs index 731744c14..5b14ebc6f 100644 --- a/ILSpy/Controls/TreeView/SharpTreeViewTextSearch.cs +++ b/ILSpy/Controls/TreeView/SharpTreeViewTextSearch.cs @@ -116,7 +116,7 @@ namespace ICSharpCode.ILSpy.Controls.TreeView var item = (SharpTreeNode)treeView.Items[i]; if (item != null && item.Text != null) { - string text = item.Text.ToString(); + string text = item.Text.ToString() ?? ""; if (text.StartsWith(needle, comparisonType)) { charWasUsed = true; diff --git a/ILSpy/Controls/ZoomScrollViewer.cs b/ILSpy/Controls/ZoomScrollViewer.cs index 21e258963..a6373fcc4 100644 --- a/ILSpy/Controls/ZoomScrollViewer.cs +++ b/ILSpy/Controls/ZoomScrollViewer.cs @@ -103,7 +103,7 @@ namespace ICSharpCode.ILSpy.Controls static void CalculateZoomButtonCollapsed(DependencyObject d, DependencyPropertyChangedEventArgs e) { - ZoomScrollViewer z = d as ZoomScrollViewer; + ZoomScrollViewer? z = d as ZoomScrollViewer; if (z != null) z.ComputedZoomButtonCollapsed = (z.AlwaysShowZoomButtons == false) && (z.CurrentZoom == 1.0); } @@ -117,7 +117,7 @@ namespace ICSharpCode.ILSpy.Controls newZoom = Math.Max(this.MinimumZoom, Math.Min(this.MaximumZoom, newZoom)); // adjust scroll position so that mouse stays over the same virtual coordinate - ContentPresenter presenter = Template.FindName("PART_Presenter", this) as ContentPresenter; + ContentPresenter? presenter = Template.FindName("PART_Presenter", this) as ContentPresenter; Vector relMousePos; if (presenter != null) { diff --git a/ILSpy/Docking/DockWorkspace.cs b/ILSpy/Docking/DockWorkspace.cs index eb8323adc..adc8497a7 100644 --- a/ILSpy/Docking/DockWorkspace.cs +++ b/ILSpy/Docking/DockWorkspace.cs @@ -84,7 +84,7 @@ namespace ICSharpCode.ILSpy.Docking private void Documents_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) { - var collection = (PaneCollection)sender; + var collection = (PaneCollection?)sender; if (e.Action == NotifyCollectionChangedAction.Add) { ActiveTabPage = e.NewItems?[0] as TabPageModel; @@ -246,7 +246,7 @@ namespace ICSharpCode.ILSpy.Docking { var anchorable = layout.Descendents().OfType().FirstOrDefault(x => x.Content is T) ?? layout.Hidden.First(x => x.Content is T); - return (LayoutAnchorablePane)previousContainerProperty.GetValue(anchorable) ?? (LayoutAnchorablePane)anchorable.Parent; + return (LayoutAnchorablePane?)previousContainerProperty.GetValue(anchorable) ?? (LayoutAnchorablePane)anchorable.Parent; } } diff --git a/ILSpy/ISmartTextOutput.cs b/ILSpy/ISmartTextOutput.cs index 1cee54e59..3bb46afe3 100644 --- a/ILSpy/ISmartTextOutput.cs +++ b/ILSpy/ISmartTextOutput.cs @@ -52,7 +52,7 @@ namespace ICSharpCode.ILSpy /// /// Creates a button. /// - public static void AddButton(this ISmartTextOutput output, ImageSource icon, string text, RoutedEventHandler click) + public static void AddButton(this ISmartTextOutput output, ImageSource? icon, string text, RoutedEventHandler click) { output.AddUIElement( delegate { diff --git a/ILSpy/Images/Images.cs b/ILSpy/Images/Images.cs index 49dfde0fd..d605e4be7 100644 --- a/ILSpy/Images/Images.cs +++ b/ILSpy/Images/Images.cs @@ -150,12 +150,12 @@ namespace ICSharpCode.ILSpy return image; } - public static Drawing LoadDrawingGroup(object part, string icon) + public static Drawing LoadDrawingGroup(object? part, string icon) { return (Drawing)Application.LoadComponent(GetUri(part, icon + ".xaml", absolute: false)); } - private static Uri GetUri(object part, string icon, bool absolute = true) + private static Uri GetUri(object? part, string icon, bool absolute = true) { Uri uri; var assembly = part?.GetType().Assembly; @@ -212,15 +212,15 @@ namespace ICSharpCode.ILSpy return memberIconCache.GetIcon(icon, overlay, isStatic); } - private static ImageSource GetIcon(string baseImage, string overlay = null, bool isStatic = false) + private static ImageSource GetIcon(string baseImage, string? overlay = null, bool isStatic = false) { ImageSource baseImageSource = Load(baseImage); - ImageSource overlayImageSource = overlay != null ? Load(overlay) : null; + ImageSource? overlayImageSource = overlay != null ? Load(overlay) : null; return CreateOverlayImage(baseImageSource, overlayImageSource, isStatic); } - private static ImageSource CreateOverlayImage(ImageSource baseImage, ImageSource overlay, bool isStatic) + private static ImageSource CreateOverlayImage(ImageSource baseImage, ImageSource? overlay, bool isStatic) { var group = new DrawingGroup(); @@ -391,16 +391,16 @@ namespace ICSharpCode.ILSpy private ImageSource BuildMemberIcon(T icon, AccessOverlayIcon overlay, bool isStatic) { ImageSource baseImage = GetBaseImage(icon); - ImageSource overlayImage = GetOverlayImage(overlay); + ImageSource? overlayImage = GetOverlayImage(overlay); return CreateOverlayImage(baseImage, overlayImage, isStatic); } protected abstract ImageSource GetBaseImage(T icon); - private static ImageSource GetOverlayImage(AccessOverlayIcon overlay) + private static ImageSource? GetOverlayImage(AccessOverlayIcon overlay) { - ImageSource overlayImage; + ImageSource? overlayImage; switch (overlay) { case AccessOverlayIcon.Public: diff --git a/ILSpy/Languages/CSharpHighlightingTokenWriter.cs b/ILSpy/Languages/CSharpHighlightingTokenWriter.cs index c6edcfd4b..4128dd486 100644 --- a/ILSpy/Languages/CSharpHighlightingTokenWriter.cs +++ b/ILSpy/Languages/CSharpHighlightingTokenWriter.cs @@ -122,7 +122,7 @@ namespace ICSharpCode.ILSpy public override void WriteKeyword(Role role, string keyword) { - HighlightingColor color = null; + HighlightingColor? color = null; switch (keyword) { case "namespace": @@ -299,7 +299,7 @@ namespace ICSharpCode.ILSpy public override void WritePrimitiveType(string type) { - HighlightingColor color = null; + HighlightingColor? color = null; switch (type) { case "new": @@ -348,7 +348,7 @@ namespace ICSharpCode.ILSpy public override void WriteIdentifier(Identifier identifier) { - HighlightingColor color = null; + HighlightingColor? color = null; if (identifier.Parent?.GetResolveResult() is ILVariableResolveResult rr) { if (rr.Variable.Kind == VariableKind.Parameter) @@ -454,7 +454,7 @@ namespace ICSharpCode.ILSpy public override void WritePrimitiveValue(object value, Decompiler.CSharp.Syntax.LiteralFormat format) { - HighlightingColor color = null; + HighlightingColor? color = null; if (value is null) { color = valueKeywordColor; diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs index c62222a0b..4ec839456 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -95,7 +95,7 @@ namespace ICSharpCode.ILSpy get { return ".csproj"; } } - IReadOnlyList versions; + IReadOnlyList? versions; public override IReadOnlyList LanguageVersions { get { @@ -151,7 +151,7 @@ namespace ICSharpCode.ILSpy public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options) { - MetadataFile assembly = method.ParentModule.MetadataFile; + MetadataFile? assembly = method.ParentModule.MetadataFile; CSharpDecompiler decompiler = CreateDecompiler(assembly, options); AddReferenceAssemblyWarningMessage(assembly, output); AddReferenceWarningMessage(assembly, output); @@ -182,7 +182,7 @@ namespace ICSharpCode.ILSpy public void Run(AstNode rootNode, TransformContext context) { - ConstructorDeclaration ctorDecl = null; + ConstructorDeclaration? ctorDecl = null; foreach (var node in rootNode.Children) { switch (node) @@ -247,7 +247,7 @@ namespace ICSharpCode.ILSpy public override void DecompileProperty(IProperty property, ITextOutput output, DecompilationOptions options) { - MetadataFile assembly = property.ParentModule.MetadataFile; + MetadataFile? assembly = property.ParentModule.MetadataFile; CSharpDecompiler decompiler = CreateDecompiler(assembly, options); AddReferenceAssemblyWarningMessage(assembly, output); AddReferenceWarningMessage(assembly, output); @@ -258,7 +258,7 @@ namespace ICSharpCode.ILSpy public override void DecompileField(IField field, ITextOutput output, DecompilationOptions options) { - MetadataFile assembly = field.ParentModule.MetadataFile; + MetadataFile? assembly = field.ParentModule.MetadataFile; CSharpDecompiler decompiler = CreateDecompiler(assembly, options); AddReferenceAssemblyWarningMessage(assembly, output); AddReferenceWarningMessage(assembly, output); @@ -348,7 +348,7 @@ namespace ICSharpCode.ILSpy public override void DecompileType(ITypeDefinition type, ITextOutput output, DecompilationOptions options) { - MetadataFile assembly = type.ParentModule.MetadataFile; + MetadataFile? assembly = type.ParentModule.MetadataFile; CSharpDecompiler decompiler = CreateDecompiler(assembly, options); AddReferenceAssemblyWarningMessage(assembly, output); AddReferenceWarningMessage(assembly, output); @@ -380,8 +380,8 @@ namespace ICSharpCode.ILSpy AddWarningMessage(module, output, line1); } - void AddWarningMessage(MetadataFile module, ITextOutput output, string line1, string line2 = null, - string buttonText = null, System.Windows.Media.ImageSource buttonImage = null, RoutedEventHandler buttonClickHandler = null) + void AddWarningMessage(MetadataFile module, ITextOutput output, string line1, string? line2 = null, + string? buttonText = null, System.Windows.Media.ImageSource? buttonImage = null, RoutedEventHandler? buttonClickHandler = null) { if (output is ISmartTextOutput fancyOutput) { @@ -775,7 +775,7 @@ namespace ICSharpCode.ILSpy public override bool ShowMember(IEntity member) { - MetadataFile assembly = member.ParentModule.MetadataFile; + MetadataFile? assembly = member.ParentModule?.MetadataFile; return showAllMembers || !CSharpDecompiler.MemberIsHidden(assembly, member.MetadataToken, SettingsService.Instance.DecompilerSettings); } diff --git a/ILSpy/Languages/ILLanguage.cs b/ILSpy/Languages/ILLanguage.cs index 29681b982..01d032495 100644 --- a/ILSpy/Languages/ILLanguage.cs +++ b/ILSpy/Languages/ILLanguage.cs @@ -73,7 +73,7 @@ namespace ICSharpCode.ILSpy public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options) { var dis = CreateDisassembler(output, options); - MetadataFile module = method.ParentModule.MetadataFile; + MetadataFile? module = method.ParentModule?.MetadataFile; dis.AssemblyResolver = module.GetAssemblyResolver(); dis.DebugInfo = module.GetDebugInfoOrNull(); dis.DisassembleMethod(module, (MethodDefinitionHandle)method.MetadataToken); @@ -82,7 +82,7 @@ namespace ICSharpCode.ILSpy public override void DecompileField(IField field, ITextOutput output, DecompilationOptions options) { var dis = CreateDisassembler(output, options); - MetadataFile module = field.ParentModule.MetadataFile; + MetadataFile? module = field.ParentModule?.MetadataFile; dis.AssemblyResolver = module.GetAssemblyResolver(); dis.DebugInfo = module.GetDebugInfoOrNull(); dis.DisassembleField(module, (FieldDefinitionHandle)field.MetadataToken); @@ -91,7 +91,7 @@ namespace ICSharpCode.ILSpy public override void DecompileProperty(IProperty property, ITextOutput output, DecompilationOptions options) { var dis = CreateDisassembler(output, options); - MetadataFile module = property.ParentModule.MetadataFile; + MetadataFile? module = property.ParentModule?.MetadataFile; dis.AssemblyResolver = module.GetAssemblyResolver(); dis.DebugInfo = module.GetDebugInfoOrNull(); dis.DisassembleProperty(module, (PropertyDefinitionHandle)property.MetadataToken); @@ -117,7 +117,7 @@ namespace ICSharpCode.ILSpy public override void DecompileEvent(IEvent ev, ITextOutput output, DecompilationOptions options) { var dis = CreateDisassembler(output, options); - MetadataFile module = ev.ParentModule.MetadataFile; + MetadataFile? module = ev.ParentModule?.MetadataFile; dis.AssemblyResolver = module.GetAssemblyResolver(); dis.DebugInfo = module.GetDebugInfoOrNull(); dis.DisassembleEvent(module, (EventDefinitionHandle)ev.MetadataToken); @@ -148,7 +148,7 @@ namespace ICSharpCode.ILSpy public override void DecompileType(ITypeDefinition type, ITextOutput output, DecompilationOptions options) { var dis = CreateDisassembler(output, options); - MetadataFile module = type.ParentModule.MetadataFile; + MetadataFile? module = type.ParentModule?.MetadataFile; dis.AssemblyResolver = module.GetAssemblyResolver(); dis.DebugInfo = module.GetDebugInfoOrNull(); dis.DisassembleType(module, (TypeDefinitionHandle)type.MetadataToken); @@ -157,7 +157,7 @@ namespace ICSharpCode.ILSpy public override void DecompileNamespace(string nameSpace, IEnumerable types, ITextOutput output, DecompilationOptions options) { var dis = CreateDisassembler(output, options); - MetadataFile module = types.FirstOrDefault()?.ParentModule.MetadataFile; + MetadataFile? module = types.FirstOrDefault()?.ParentModule?.MetadataFile; dis.AssemblyResolver = module.GetAssemblyResolver(); dis.DebugInfo = module.GetDebugInfoOrNull(); dis.DisassembleNamespace(nameSpace, module, types.Select(t => (TypeDefinitionHandle)t.MetadataToken)); @@ -199,7 +199,7 @@ namespace ICSharpCode.ILSpy { var output = new AvalonEditTextOutput() { IgnoreNewLineAndIndent = true }; var disasm = CreateDisassembler(output, MainWindow.Instance.CreateDecompilationOptions()); - MetadataFile module = entity.ParentModule?.MetadataFile; + MetadataFile? module = entity.ParentModule?.MetadataFile; if (module == null) { return null; diff --git a/ILSpy/Languages/Language.cs b/ILSpy/Languages/Language.cs index b556c04ff..28af50d6a 100644 --- a/ILSpy/Languages/Language.cs +++ b/ILSpy/Languages/Language.cs @@ -125,7 +125,7 @@ namespace ICSharpCode.ILSpy { WriteCommentLine(output, metadata.GetString(name.Name) + " [WinRT]"); } - else if (metadata.TryGetFullAssemblyName(out string assemblyName)) + else if (metadata.TryGetFullAssemblyName(out string? assemblyName)) { WriteCommentLine(output, assemblyName); } diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs index b17691b11..dbd581601 100644 --- a/ILSpy/MainWindow.xaml.cs +++ b/ILSpy/MainWindow.xaml.cs @@ -318,7 +318,7 @@ namespace ICSharpCode.ILSpy { return null; } - string value = Properties.Resources.ResourceManager.GetString(key); + string? value = Properties.Resources.ResourceManager.GetString(key); if (!string.IsNullOrEmpty(value)) { return value; @@ -659,13 +659,13 @@ namespace ICSharpCode.ILSpy string namespaceName = navigateTo.Substring(2); foreach (LoadedAssembly asm in relevantAssemblies) { - AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(asm); + AssemblyTreeNode? asmNode = assemblyListTreeNode.FindAssemblyNode(asm); if (asmNode != null) { // FindNamespaceNode() blocks the UI if the assembly is not yet loaded, // so use an async wait instead. await asm.GetMetadataFileAsync().Catch(ex => { }); - NamespaceTreeNode nsNode = asmNode.FindNamespaceNode(namespaceName); + NamespaceTreeNode? nsNode = asmNode.FindNamespaceNode(namespaceName); if (nsNode != null) { found = true; @@ -686,7 +686,7 @@ namespace ICSharpCode.ILSpy } else { - IEntity mr = await Task.Run(() => FindEntityInRelevantAssemblies(navigateTo, relevantAssemblies)); + IEntity? mr = await Task.Run(() => FindEntityInRelevantAssemblies(navigateTo, relevantAssemblies)); // Make sure we wait for assemblies being loaded... // BeginInvoke in LoadedAssembly.LookupReferencedAssemblyInternal await Dispatcher.InvokeAsync(delegate { }, DispatcherPriority.Normal); @@ -710,7 +710,7 @@ namespace ICSharpCode.ILSpy { // NavigateTo == null and an assembly was given on the command-line: // Select the newly loaded assembly - AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(relevantAssemblies[0]); + AssemblyTreeNode? asmNode = assemblyListTreeNode.FindAssemblyNode(relevantAssemblies[0]); if (asmNode != null && AssemblyTreeView.SelectedItem == initialSelection) { SelectNode(asmNode); @@ -718,7 +718,7 @@ namespace ICSharpCode.ILSpy } else if (spySettings != null) { - SharpTreeNode node = null; + SharpTreeNode? node = null; if (activeTreeViewPath?.Length > 0) { foreach (var asm in CurrentAssemblyList.GetAssemblies()) @@ -772,7 +772,7 @@ namespace ICSharpCode.ILSpy : new SimpleCompilation((PEFile)module, MinimalCorlib.Instance); return memberRef == null ? typeRef.Resolve(new SimpleTypeResolveContext(compilation)) as ITypeDefinition - : (IEntity)memberRef.Resolve(new SimpleTypeResolveContext(compilation)); + : (IEntity?)memberRef.Resolve(new SimpleTypeResolveContext(compilation)); } } return null; @@ -875,7 +875,7 @@ namespace ICSharpCode.ILSpy public async Task ShowMessageIfUpdatesAvailableAsync(ILSpySettings spySettings, bool forceCheck = false) { - string downloadUrl; + string? downloadUrl; if (forceCheck) { downloadUrl = await NotifyOfUpdatesStrategy.CheckForUpdatesAsync(spySettings); @@ -903,12 +903,12 @@ namespace ICSharpCode.ILSpy else { updatePanel.Visibility = Visibility.Collapsed; - string downloadUrl = await NotifyOfUpdatesStrategy.CheckForUpdatesAsync(ILSpySettings.Load()); + string? downloadUrl = await NotifyOfUpdatesStrategy.CheckForUpdatesAsync(ILSpySettings.Load()); AdjustUpdateUIAfterCheck(downloadUrl, true); } } - void AdjustUpdateUIAfterCheck(string downloadUrl, bool displayMessage) + void AdjustUpdateUIAfterCheck(string? downloadUrl, bool displayMessage) { updateAvailableDownloadUrl = downloadUrl; updatePanel.Visibility = displayMessage ? Visibility.Visible : Visibility.Collapsed; @@ -1113,8 +1113,8 @@ namespace ICSharpCode.ILSpy { if (path == null) return null; - SharpTreeNode node = AssemblyTreeView.Root; - SharpTreeNode bestMatch = node; + SharpTreeNode? node = AssemblyTreeView.Root; + SharpTreeNode? bestMatch = node; foreach (var element in path) { if (node == null) @@ -1237,7 +1237,7 @@ namespace ICSharpCode.ILSpy } break; default: - ILSpyTreeNode treeNode = FindTreeNode(reference); + ILSpyTreeNode? treeNode = FindTreeNode(reference); if (treeNode != null) SelectNode(treeNode, inNewTabPage); break; @@ -1301,9 +1301,9 @@ namespace ICSharpCode.ILSpy LoadAssemblies(fileNames, focusNode: focusNode); } - void LoadAssemblies(IEnumerable fileNames, List loadedAssemblies = null, bool focusNode = true) + void LoadAssemblies(IEnumerable fileNames, List? loadedAssemblies = null, bool focusNode = true) { - SharpTreeNode lastNode = null; + SharpTreeNode? lastNode = null; foreach (string file in fileNames) { var asm = assemblyList.OpenAssembly(file); @@ -1367,7 +1367,7 @@ namespace ICSharpCode.ILSpy void TreeView_SelectionChanged(object sender, SelectionChangedEventArgs e) { - DecompilerTextViewState state = null; + DecompilerTextViewState? state = null; if (refreshInProgress || changingActiveTab) { state = DockWorkspace.Instance.ActiveTabPage.GetState() as DecompilerTextViewState; @@ -1385,7 +1385,7 @@ namespace ICSharpCode.ILSpy Task decompilationTask; bool ignoreDecompilationRequests; - void DecompileSelectedNodes(DecompilerTextViewState newState = null, bool recordHistory = true) + void DecompileSelectedNodes(DecompilerTextViewState? newState = null, bool recordHistory = true) { if (ignoreDecompilationRequests) return; @@ -1406,7 +1406,7 @@ namespace ICSharpCode.ILSpy if (AssemblyTreeView.SelectedItems.Count == 1) { - ILSpyTreeNode node = AssemblyTreeView.SelectedItem as ILSpyTreeNode; + ILSpyTreeNode? node = AssemblyTreeView.SelectedItem as ILSpyTreeNode; if (node != null && node.View(DockWorkspace.Instance.ActiveTabPage)) return; } @@ -1533,11 +1533,11 @@ namespace ICSharpCode.ILSpy Title = e.Uri.AbsolutePath, EnableHyperlinks = true }; - using (Stream s = typeof(App).Assembly.GetManifestResourceStream(typeof(App), e.Uri.AbsolutePath)) + using (Stream? s = typeof(App).Assembly.GetManifestResourceStream(typeof(App), e.Uri.AbsolutePath)) { using (StreamReader r = new StreamReader(s)) { - string line; + string? line; while ((line = r.ReadLine()) != null) { output.Write(line); diff --git a/ILSpy/Metadata/CorTables/EventTableTreeNode.cs b/ILSpy/Metadata/CorTables/EventTableTreeNode.cs index 7e3c95ca5..20f7003d3 100644 --- a/ILSpy/Metadata/CorTables/EventTableTreeNode.cs +++ b/ILSpy/Metadata/CorTables/EventTableTreeNode.cs @@ -92,7 +92,7 @@ namespace ICSharpCode.ILSpy.Metadata public string Name => metadataFile.Metadata.GetString(eventDef.Name); - IEntity IMemberTreeNode.Member { + IEntity? IMemberTreeNode.Member { get { return ((MetadataModule)metadataFile.GetTypeSystemWithCurrentOptionsOrNull()?.MainModule)?.GetDefinition(handle); } diff --git a/ILSpy/Metadata/CorTables/FieldTableTreeNode.cs b/ILSpy/Metadata/CorTables/FieldTableTreeNode.cs index c8e8e310d..c200cba3c 100644 --- a/ILSpy/Metadata/CorTables/FieldTableTreeNode.cs +++ b/ILSpy/Metadata/CorTables/FieldTableTreeNode.cs @@ -95,7 +95,7 @@ namespace ICSharpCode.ILSpy.Metadata public string NameTooltip => $"{MetadataTokens.GetHeapOffset(fieldDef.Name):X} \"{Name}\""; - IEntity IMemberTreeNode.Member => ((MetadataModule)metadataFile.GetTypeSystemWithCurrentOptionsOrNull()?.MainModule)?.GetDefinition(handle); + IEntity? IMemberTreeNode.Member => ((MetadataModule)metadataFile.GetTypeSystemWithCurrentOptionsOrNull()?.MainModule)?.GetDefinition(handle); [ColumnInfo("X8", Kind = ColumnKind.HeapOffset)] public int Signature => MetadataTokens.GetHeapOffset(fieldDef.Signature); diff --git a/ILSpy/Metadata/CorTables/MethodTableTreeNode.cs b/ILSpy/Metadata/CorTables/MethodTableTreeNode.cs index fe5cb173c..f92db4da8 100644 --- a/ILSpy/Metadata/CorTables/MethodTableTreeNode.cs +++ b/ILSpy/Metadata/CorTables/MethodTableTreeNode.cs @@ -131,7 +131,7 @@ namespace ICSharpCode.ILSpy.Metadata } } - IEntity IMemberTreeNode.Member => ((MetadataModule)metadataFile.GetTypeSystemWithCurrentOptionsOrNull()?.MainModule)?.GetDefinition(handle); + IEntity? IMemberTreeNode.Member => ((MetadataModule)metadataFile.GetTypeSystemWithCurrentOptionsOrNull()?.MainModule)?.GetDefinition(handle); public MethodDefEntry(MetadataFile metadataFile, MethodDefinitionHandle handle) { diff --git a/ILSpy/Metadata/CorTables/PropertyTableTreeNode.cs b/ILSpy/Metadata/CorTables/PropertyTableTreeNode.cs index 05ff38b71..fe1d1eb72 100644 --- a/ILSpy/Metadata/CorTables/PropertyTableTreeNode.cs +++ b/ILSpy/Metadata/CorTables/PropertyTableTreeNode.cs @@ -92,7 +92,7 @@ namespace ICSharpCode.ILSpy.Metadata public string NameTooltip => $"{MetadataTokens.GetHeapOffset(propertyDef.Name):X} \"{Name}\""; - IEntity IMemberTreeNode.Member => ((MetadataModule)metadataFile.GetTypeSystemWithCurrentOptionsOrNull()?.MainModule).GetDefinition(handle); + IEntity? IMemberTreeNode.Member => ((MetadataModule)metadataFile.GetTypeSystemWithCurrentOptionsOrNull()?.MainModule).GetDefinition(handle); [ColumnInfo("X8", Kind = ColumnKind.HeapOffset)] public int Signature => MetadataTokens.GetHeapOffset(propertyDef.Signature); diff --git a/ILSpy/Metadata/CorTables/TypeDefTableTreeNode.cs b/ILSpy/Metadata/CorTables/TypeDefTableTreeNode.cs index 1ae59f107..cdcb57555 100644 --- a/ILSpy/Metadata/CorTables/TypeDefTableTreeNode.cs +++ b/ILSpy/Metadata/CorTables/TypeDefTableTreeNode.cs @@ -173,7 +173,7 @@ namespace ICSharpCode.ILSpy.Metadata } } - IEntity IMemberTreeNode.Member => ((MetadataModule)metadataFile.GetTypeSystemWithCurrentOptionsOrNull()?.MainModule).GetDefinition(handle); + IEntity? IMemberTreeNode.Member => ((MetadataModule)metadataFile.GetTypeSystemWithCurrentOptionsOrNull()?.MainModule).GetDefinition(handle); public TypeDefEntry(MetadataFile metadataFile, TypeDefinitionHandle handle) { diff --git a/ILSpy/Metadata/DebugTables/CustomDebugInformationTableTreeNode.cs b/ILSpy/Metadata/DebugTables/CustomDebugInformationTableTreeNode.cs index 9dcbe2f01..8715c2f0e 100644 --- a/ILSpy/Metadata/DebugTables/CustomDebugInformationTableTreeNode.cs +++ b/ILSpy/Metadata/DebugTables/CustomDebugInformationTableTreeNode.cs @@ -47,7 +47,7 @@ namespace ICSharpCode.ILSpy.Metadata view.RowDetailsTemplateSelector = new CustomDebugInformationDetailsTemplateSelector(); var list = new List(); - CustomDebugInformationEntry scrollTargetEntry = default; + CustomDebugInformationEntry? scrollTargetEntry = default; foreach (var row in metadataFile.Metadata.CustomDebugInformation) { diff --git a/ILSpy/Metadata/GoToTokenCommand.cs b/ILSpy/Metadata/GoToTokenCommand.cs index 9a57de525..51b3ab038 100644 --- a/ILSpy/Metadata/GoToTokenCommand.cs +++ b/ILSpy/Metadata/GoToTokenCommand.cs @@ -51,7 +51,7 @@ namespace ICSharpCode.ILSpy.Commands return context.DataGrid?.Name == "MetadataView" && GetSelectedToken(context.DataGrid, out _) != null; } - private int? GetSelectedToken(DataGrid grid, out MetadataFile module) + private int? GetSelectedToken(DataGrid grid, out MetadataFile? module) { module = null; if (grid == null) @@ -75,7 +75,7 @@ namespace ICSharpCode.ILSpy.Commands { public void Execute(TextViewContext context) { - string content = GetSelectedCellContent(context.DataGrid, context.MousePosition); + string? content = GetSelectedCellContent(context.DataGrid, context.MousePosition); Clipboard.SetText(content); } diff --git a/ILSpy/NavigationState.cs b/ILSpy/NavigationState.cs index e30ee7f63..1d72b66b7 100644 --- a/ILSpy/NavigationState.cs +++ b/ILSpy/NavigationState.cs @@ -38,7 +38,7 @@ namespace ICSharpCode.ILSpy public NavigationState(TabPageModel tabPage, ViewState viewState) { this.TabPage = tabPage; - this.treeNodes = new HashSet((IEnumerable)viewState.DecompiledNodes ?? Array.Empty()); + this.treeNodes = new HashSet((IEnumerable?)viewState.DecompiledNodes ?? Array.Empty()); ViewState = viewState; } diff --git a/ILSpy/Options/DisplaySettingsPanel.xaml.cs b/ILSpy/Options/DisplaySettingsPanel.xaml.cs index 9645dacc7..7101665c7 100644 --- a/ILSpy/Options/DisplaySettingsPanel.xaml.cs +++ b/ILSpy/Options/DisplaySettingsPanel.xaml.cs @@ -99,11 +99,11 @@ namespace ICSharpCode.ILSpy.Options select ff).ToArray(); } - public static DisplaySettings LoadDisplaySettings(ILSpySettings settings, SessionSettings sessionSettings = null) + public static DisplaySettings LoadDisplaySettings(ILSpySettings settings, SessionSettings? sessionSettings = null) { XElement e = settings["DisplaySettings"]; var s = new DisplaySettings(); - s.SelectedFont = new FontFamily((string)e.Attribute("Font") ?? "Consolas"); + s.SelectedFont = new FontFamily((string?)e.Attribute("Font") ?? "Consolas"); s.SelectedFontSize = (double?)e.Attribute("FontSize") ?? 10.0 * 4 / 3; s.ShowLineNumbers = (bool?)e.Attribute("ShowLineNumbers") ?? false; s.ShowMetadataTokens = (bool?)e.Attribute("ShowMetadataTokens") ?? false; diff --git a/ILSpy/Options/OptionsDialog.xaml.cs b/ILSpy/Options/OptionsDialog.xaml.cs index c9226fdef..184dc9b1c 100644 --- a/ILSpy/Options/OptionsDialog.xaml.cs +++ b/ILSpy/Options/OptionsDialog.xaml.cs @@ -63,7 +63,7 @@ namespace ICSharpCode.ILSpy.Options tabControl.Items.Add(tabItem); - IOptionPage page = optionPage.Value as IOptionPage; + IOptionPage? page = optionPage.Value as IOptionPage; if (page != null) page.Load(settings); } @@ -75,7 +75,7 @@ namespace ICSharpCode.ILSpy.Options delegate (XElement root) { foreach (var optionPage in optionPages) { - IOptionPage page = optionPage.Value as IOptionPage; + IOptionPage? page = optionPage.Value as IOptionPage; if (page != null) page.Save(root); } diff --git a/ILSpy/Search/SearchPane.xaml.cs b/ILSpy/Search/SearchPane.xaml.cs index 028fcb8b8..c9ae39930 100644 --- a/ILSpy/Search/SearchPane.xaml.cs +++ b/ILSpy/Search/SearchPane.xaml.cs @@ -53,7 +53,7 @@ namespace ICSharpCode.ILSpy.Search { const int MAX_RESULTS = 1000; const int MAX_REFRESH_TIME_MS = 10; // More means quicker forward of data, fewer means better responsibility - RunningSearch currentSearch; + RunningSearch? currentSearch; bool runSearchOnNextShow; IComparer resultsComparer; @@ -231,7 +231,7 @@ namespace ICSharpCode.ILSpy.Search currentSearch.Cancel(); } - async void StartSearch(string searchTerm) + async void StartSearch(string? searchTerm) { if (currentSearch != null) { @@ -245,7 +245,7 @@ namespace ICSharpCode.ILSpy.Search SearchResult.ComparerByName; Results.Clear(); - RunningSearch startedSearch = null; + RunningSearch? startedSearch = null; if (!string.IsNullOrEmpty(searchTerm)) { @@ -299,7 +299,7 @@ namespace ICSharpCode.ILSpy.Search SearchRequest request = new(); List keywords = new(); - Regex regex = null; + Regex? regex = null; request.Mode = searchMode; foreach (string part in parts) @@ -325,7 +325,7 @@ namespace ICSharpCode.ILSpy.Search prefixLength = part.IndexOf(':', 0, prefixLength); delimiterLength = 1; } - string prefix; + string? prefix; if (prefixLength <= 0) { prefix = null; diff --git a/ILSpy/SessionSettings.cs b/ILSpy/SessionSettings.cs index 1053603e0..74aaaa177 100644 --- a/ILSpy/SessionSettings.cs +++ b/ILSpy/SessionSettings.cs @@ -44,7 +44,7 @@ namespace ICSharpCode.ILSpy { XElement doc = spySettings["SessionSettings"]; - XElement filterSettings = doc.Element("FilterSettings"); + XElement? filterSettings = doc.Element("FilterSettings"); if (filterSettings == null) filterSettings = new XElement("FilterSettings"); @@ -52,7 +52,7 @@ namespace ICSharpCode.ILSpy this.ActiveAssemblyList = (string)doc.Element("ActiveAssemblyList"); - XElement activeTreeViewPath = doc.Element("ActiveTreeViewPath"); + XElement? activeTreeViewPath = doc.Element("ActiveTreeViewPath"); if (activeTreeViewPath != null) { this.ActiveTreeViewPath = activeTreeViewPath.Elements().Select(e => Unescape((string)e)).ToArray(); @@ -63,7 +63,7 @@ namespace ICSharpCode.ILSpy this.WindowBounds = FromString((string)doc.Element("WindowBounds"), DefaultWindowBounds); this.SelectedSearchMode = FromString((string)doc.Element("SelectedSearchMode"), SearchMode.TypeAndMember); this.Theme = FromString((string)doc.Element(nameof(Theme)), ThemeManager.Current.DefaultTheme); - string currentCulture = (string)doc.Element(nameof(CurrentCulture)); + string? currentCulture = (string)doc.Element(nameof(CurrentCulture)); this.CurrentCulture = string.IsNullOrEmpty(currentCulture) ? null : currentCulture; this.DockLayout = new DockLayoutSettings(doc.Element("DockLayout")); @@ -108,7 +108,7 @@ namespace ICSharpCode.ILSpy } } - public string ActiveAssemblyList { + public string? ActiveAssemblyList { get => activeAssemblyList; set { if (value != null && value != activeAssemblyList) @@ -166,7 +166,7 @@ namespace ICSharpCode.ILSpy } static Regex regex = new Regex("\\\\x(?[0-9A-f]{4})"); - private string activeAssemblyList; + private string? activeAssemblyList; static string Escape(string p) { @@ -186,7 +186,7 @@ namespace ICSharpCode.ILSpy return regex.Replace(p, m => ((char)int.Parse(m.Groups["num"].Value, NumberStyles.HexNumber)).ToString()); } - static T FromString(string s, T defaultValue) + static T FromString(string? s, T defaultValue) { if (s == null) return defaultValue; diff --git a/ILSpy/TaskHelper.cs b/ILSpy/TaskHelper.cs index e26eaf062..21bfd56e4 100644 --- a/ILSpy/TaskHelper.cs +++ b/ILSpy/TaskHelper.cs @@ -174,7 +174,7 @@ namespace ICSharpCode.ILSpy return task.ContinueWith(t => { if (t.IsFaulted) { - Exception ex = t.Exception; + Exception? ex = t.Exception; while (ex is AggregateException) ex = ex.InnerException; if (ex is TException) diff --git a/ILSpy/TextView/AvalonEditTextOutput.cs b/ILSpy/TextView/AvalonEditTextOutput.cs index da62890a0..6517a1783 100644 --- a/ILSpy/TextView/AvalonEditTextOutput.cs +++ b/ILSpy/TextView/AvalonEditTextOutput.cs @@ -40,7 +40,7 @@ namespace ICSharpCode.ILSpy.TextView /// public sealed class ReferenceSegment : TextSegment { - public object Reference; + public object? Reference; public bool IsLocal; public bool IsDefinition; } diff --git a/ILSpy/TextView/DecompilerTextView.cs b/ILSpy/TextView/DecompilerTextView.cs index 1124a73e5..f500fd374 100644 --- a/ILSpy/TextView/DecompilerTextView.cs +++ b/ILSpy/TextView/DecompilerTextView.cs @@ -392,7 +392,7 @@ namespace ICSharpCode.ILSpy.TextView { if (segment.Reference is ICSharpCode.Decompiler.Disassembler.OpCodeInfo code) { - XmlDocumentationProvider docProvider = XmlDocLoader.MscorlibDocumentation; + XmlDocumentationProvider? docProvider = XmlDocLoader.MscorlibDocumentation; DocumentationUIBuilder renderer = new DocumentationUIBuilder(new CSharpAmbience(), SettingsService.Instance.SessionSettings.LanguageSettings.Language.SyntaxHighlighting); renderer.AddSignatureBlock($"{code.Name} (0x{code.Code:x})"); if (docProvider != null) @@ -425,7 +425,7 @@ namespace ICSharpCode.ILSpy.TextView Handle handle = unresolvedEntity.Handle; if (!handle.IsEntityHandle()) return null; - IEntity resolved = typeSystem.MainModule.ResolveEntity((EntityHandle)handle); + IEntity? resolved = typeSystem.MainModule.ResolveEntity((EntityHandle)handle); if (resolved == null) return null; var document = CreateTooltipForEntity(resolved); @@ -445,7 +445,7 @@ namespace ICSharpCode.ILSpy.TextView { Language currentLanguage = SettingsService.Instance.SessionSettings.LanguageSettings.Language; DocumentationUIBuilder renderer = new DocumentationUIBuilder(new CSharpAmbience(), currentLanguage.SyntaxHighlighting); - RichText richText = currentLanguage.GetRichTextTooltip(resolved); + RichText? richText = currentLanguage.GetRichTextTooltip(resolved); if (richText == null) { return null; diff --git a/ILSpy/TextView/DocumentationUIBuilder.cs b/ILSpy/TextView/DocumentationUIBuilder.cs index e8527c858..d6d655021 100644 --- a/ILSpy/TextView/DocumentationUIBuilder.cs +++ b/ILSpy/TextView/DocumentationUIBuilder.cs @@ -128,7 +128,7 @@ namespace ICSharpCode.ILSpy.TextView AddBlock(block); } - public void AddXmlDocumentation(string xmlDocumentation, IEntity declaringEntity, Func resolver) + public void AddXmlDocumentation(string xmlDocumentation, IEntity? declaringEntity, Func? resolver) { if (xmlDocumentation == null) return; @@ -375,7 +375,7 @@ namespace ICSharpCode.ILSpy.TextView void AddSee(XmlDocumentationElement element) { - IEntity referencedEntity = element.ReferencedEntity; + IEntity? referencedEntity = element.ReferencedEntity; if (referencedEntity != null) { if (element.Children.Any()) @@ -397,7 +397,7 @@ namespace ICSharpCode.ILSpy.TextView } else if (element.GetAttribute("href") != null) { - Uri uri; + Uri? uri; if (Uri.TryCreate(element.GetAttribute("href"), UriKind.Absolute, out uri)) { if (element.Children.Any()) diff --git a/ILSpy/TextView/FoldingCommands.cs b/ILSpy/TextView/FoldingCommands.cs index c061c543e..4fceb1176 100644 --- a/ILSpy/TextView/FoldingCommands.cs +++ b/ILSpy/TextView/FoldingCommands.cs @@ -43,7 +43,7 @@ namespace ICSharpCode.ILSpy.TextView { if (null == context.TextView) return; - FoldingManager foldingManager = context.TextView.FoldingManager; + FoldingManager? foldingManager = context.TextView.FoldingManager; if (null == foldingManager) return; bool doFold = true; @@ -82,7 +82,7 @@ namespace ICSharpCode.ILSpy.TextView if (null == textView) return; var editor = textView.textEditor; - FoldingManager foldingManager = context.TextView.FoldingManager; + FoldingManager? foldingManager = context.TextView.FoldingManager; if (null == foldingManager) return; // TODO: or use Caret if position is not given? @@ -91,7 +91,7 @@ namespace ICSharpCode.ILSpy.TextView return; TextViewPosition pos = posBox.Value; // look for folding on this line: - FoldingSection folding = foldingManager.GetNextFolding(editor.Document.GetOffset(pos.Line, 1)); + FoldingSection? folding = foldingManager.GetNextFolding(editor.Document.GetOffset(pos.Line, 1)); if (folding == null || editor.Document.GetLineByOffset(folding.StartOffset).LineNumber != pos.Line) { // no folding found on current line: find innermost folding containing the mouse position diff --git a/ILSpy/TreeNodes/AssemblyListTreeNode.cs b/ILSpy/TreeNodes/AssemblyListTreeNode.cs index 9ffe3fdf0..218771aa7 100644 --- a/ILSpy/TreeNodes/AssemblyListTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyListTreeNode.cs @@ -98,7 +98,7 @@ namespace ICSharpCode.ILSpy.TreeNodes public override void Drop(IPlatformDragEventArgs e, int index) { - string[] files = e.Data.GetData(AssemblyTreeNode.DataFormat) as string[]; + string[]? files = e.Data.GetData(AssemblyTreeNode.DataFormat) as string[]; if (files == null) files = e.Data.GetData(DataFormats.FileDrop) as string[]; if (files != null) @@ -225,7 +225,7 @@ namespace ICSharpCode.ILSpy.TreeNodes var declaringType = def.DeclaringTypeDefinition; if (declaringType != null) { - TypeTreeNode decl = FindTypeNode(declaringType); + TypeTreeNode? decl = FindTypeNode(declaringType); if (decl != null) { decl.EnsureLazyChildren(); @@ -249,12 +249,12 @@ namespace ICSharpCode.ILSpy.TreeNodes /// public ILSpyTreeNode? FindMethodNode(IMethod def) { - TypeTreeNode typeNode = FindTypeNode(def.DeclaringTypeDefinition); + TypeTreeNode? typeNode = FindTypeNode(def.DeclaringTypeDefinition); if (typeNode == null) return null; // method might be an accessor, must look for parent node - ILSpyTreeNode parentNode = typeNode; - MethodTreeNode methodNode; + ILSpyTreeNode? parentNode = typeNode; + MethodTreeNode? methodNode; parentNode.EnsureLazyChildren(); switch (def.AccessorOwner) { @@ -290,7 +290,7 @@ namespace ICSharpCode.ILSpy.TreeNodes /// public FieldTreeNode? FindFieldNode(IField def) { - TypeTreeNode typeNode = FindTypeNode(def.DeclaringTypeDefinition); + TypeTreeNode? typeNode = FindTypeNode(def.DeclaringTypeDefinition); if (typeNode == null) return null; typeNode.EnsureLazyChildren(); @@ -303,7 +303,7 @@ namespace ICSharpCode.ILSpy.TreeNodes /// public PropertyTreeNode? FindPropertyNode(IProperty def) { - TypeTreeNode typeNode = FindTypeNode(def.DeclaringTypeDefinition); + TypeTreeNode? typeNode = FindTypeNode(def.DeclaringTypeDefinition); if (typeNode == null) return null; typeNode.EnsureLazyChildren(); @@ -316,7 +316,7 @@ namespace ICSharpCode.ILSpy.TreeNodes /// public EventTreeNode? FindEventNode(IEvent def) { - TypeTreeNode typeNode = FindTypeNode(def.DeclaringTypeDefinition); + TypeTreeNode? typeNode = FindTypeNode(def.DeclaringTypeDefinition); if (typeNode == null) return null; typeNode.EnsureLazyChildren(); diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index 1f4c0b794..fb108dfaa 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -248,7 +248,7 @@ namespace ICSharpCode.ILSpy.TreeNodes typeSystem = LoadedAssembly.GetTypeSystemOrNull(); var assembly = (MetadataModule)typeSystem.MainModule; this.Children.Add(new MetadataTreeNode(module, Resources.Metadata)); - Decompiler.DebugInfo.IDebugInfoProvider debugInfo = LoadedAssembly.GetDebugInfoOrNull(); + Decompiler.DebugInfo.IDebugInfoProvider? debugInfo = LoadedAssembly.GetDebugInfoOrNull(); if (debugInfo is PortableDebugInfoProvider ppdb && ppdb.GetMetadataReader() is System.Reflection.Metadata.MetadataReader reader) { @@ -280,7 +280,7 @@ namespace ICSharpCode.ILSpy.TreeNodes NamespaceTreeNode GetOrCreateNamespaceTreeNode(string @namespace) { - if (!namespaces.TryGetValue(@namespace, out NamespaceTreeNode ns)) + if (!namespaces.TryGetValue(@namespace, out NamespaceTreeNode? ns)) { if (useNestedStructure) { @@ -346,7 +346,7 @@ namespace ICSharpCode.ILSpy.TreeNodes NamespaceTreeNode GetOrCreateNamespaceTreeNode(string @namespace) { - if (!namespaces.TryGetValue(@namespace, out NamespaceTreeNode ns)) + if (!namespaces.TryGetValue(@namespace, out NamespaceTreeNode? ns)) { if (useNestedStructure) { @@ -392,7 +392,7 @@ namespace ICSharpCode.ILSpy.TreeNodes if (type == null) return null; EnsureLazyChildren(); - TypeTreeNode node; + TypeTreeNode? node; if (typeDict.TryGetValue((TypeDefinitionHandle)type.MetadataToken, out node)) return node; else diff --git a/ILSpy/TreeNodes/ResourceNodes/ResourceTreeNode.cs b/ILSpy/TreeNodes/ResourceNodes/ResourceTreeNode.cs index 69502149f..04dccc7b9 100644 --- a/ILSpy/TreeNodes/ResourceNodes/ResourceTreeNode.cs +++ b/ILSpy/TreeNodes/ResourceNodes/ResourceTreeNode.cs @@ -71,7 +71,7 @@ namespace ICSharpCode.ILSpy.TreeNodes var sizeInBytesText = sizeInBytes == null ? "" : ", " + sizeInBytes + " bytes"; language.WriteCommentLine(output, $"{Resource.Name} ({Resource.ResourceType}, {Resource.Attributes}{sizeInBytesText})"); - ISmartTextOutput smartOutput = output as ISmartTextOutput; + ISmartTextOutput? smartOutput = output as ISmartTextOutput; if (smartOutput != null) { smartOutput.AddButton(Images.Save, Resources.Save, delegate { Save(Docking.DockWorkspace.Instance.ActiveTabPage); }); @@ -81,7 +81,7 @@ namespace ICSharpCode.ILSpy.TreeNodes public override bool View(TabPageModel tabPage) { - Stream s = Resource.TryOpenStream(); + Stream? s = Resource.TryOpenStream(); if (s != null && s.Length < DecompilerTextView.DefaultOutputLengthLimit) { s.Position = 0; @@ -107,7 +107,7 @@ namespace ICSharpCode.ILSpy.TreeNodes public override bool Save(TabPageModel tabPage) { - Stream s = Resource.TryOpenStream(); + Stream? s = Resource.TryOpenStream(); if (s == null) return false; SaveFileDialog dlg = new SaveFileDialog(); diff --git a/ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs b/ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs index eb3ab6e17..0b1ce8d85 100644 --- a/ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs +++ b/ILSpy/TreeNodes/ResourceNodes/ResourcesFileTreeNode.cs @@ -71,7 +71,7 @@ namespace ICSharpCode.ILSpy.TreeNodes protected override void LoadChildren() { - Stream s = Resource.TryOpenStream(); + Stream? s = Resource.TryOpenStream(); if (s == null) return; s.Position = 0; @@ -128,7 +128,7 @@ namespace ICSharpCode.ILSpy.TreeNodes public override bool Save(TabPageModel tabPage) { - Stream s = Resource.TryOpenStream(); + Stream? s = Resource.TryOpenStream(); if (s == null) return false; SaveFileDialog dlg = new SaveFileDialog(); @@ -179,7 +179,7 @@ namespace ICSharpCode.ILSpy.TreeNodes var textView = (DecompilerTextView)Docking.DockWorkspace.Instance.ActiveTabPage.Content; if (stringTableEntries.Count != 0) { - ISmartTextOutput smartOutput = output as ISmartTextOutput; + ISmartTextOutput? smartOutput = output as ISmartTextOutput; if (null != smartOutput) { smartOutput.AddUIElement( @@ -193,7 +193,7 @@ namespace ICSharpCode.ILSpy.TreeNodes } if (otherEntries.Count != 0) { - ISmartTextOutput smartOutput = output as ISmartTextOutput; + ISmartTextOutput? smartOutput = output as ISmartTextOutput; if (null != smartOutput) { smartOutput.AddUIElement( diff --git a/ILSpy/TreeNodes/ResourceNodes/XamlResourceNode.cs b/ILSpy/TreeNodes/ResourceNodes/XamlResourceNode.cs index a582b43b5..cd2b796b8 100644 --- a/ILSpy/TreeNodes/ResourceNodes/XamlResourceNode.cs +++ b/ILSpy/TreeNodes/ResourceNodes/XamlResourceNode.cs @@ -54,7 +54,7 @@ namespace ICSharpCode.ILSpy.Xaml public override bool View(TabPageModel tabPage) { AvalonEditTextOutput output = new AvalonEditTextOutput(); - IHighlightingDefinition highlighting = null; + IHighlightingDefinition? highlighting = null; tabPage.ShowTextView(textView => textView.RunWithCancellation( token => Task.Factory.StartNew( diff --git a/ILSpy/TreeNodes/ThreadingSupport.cs b/ILSpy/TreeNodes/ThreadingSupport.cs index ce1d87515..a1d66245a 100644 --- a/ILSpy/TreeNodes/ThreadingSupport.cs +++ b/ILSpy/TreeNodes/ThreadingSupport.cs @@ -67,7 +67,7 @@ namespace ICSharpCode.ILSpy.TreeNodes CancellationToken ct = cancellationTokenSource.Token; var fetchChildrenEnumerable = fetchChildren(ct); - Task> thisTask = null; + Task>? thisTask = null; thisTask = new Task>( delegate { List result = new List(); diff --git a/ILSpy/Updates/NotifyOfUpdatesStrategy.cs b/ILSpy/Updates/NotifyOfUpdatesStrategy.cs index 01c6e1ae8..d02565784 100644 --- a/ILSpy/Updates/NotifyOfUpdatesStrategy.cs +++ b/ILSpy/Updates/NotifyOfUpdatesStrategy.cs @@ -46,7 +46,7 @@ namespace ICSharpCode.ILSpy.Updates var bands = doc.Root.Elements("band"); var currentBand = bands.FirstOrDefault(b => (string)b.Attribute("id") == band) ?? bands.First(); Version version = new Version((string)currentBand.Element("latestVersion")); - string url = (string)currentBand.Element("downloadUrl"); + string? url = (string)currentBand.Element("downloadUrl"); if (!(url.StartsWith("http://", StringComparison.Ordinal) || url.StartsWith("https://", StringComparison.Ordinal))) url = null; // don't accept non-urls diff --git a/TestPlugin/CustomLanguage.cs b/TestPlugin/CustomLanguage.cs index 7e38fdffe..bfd2ac285 100644 --- a/TestPlugin/CustomLanguage.cs +++ b/TestPlugin/CustomLanguage.cs @@ -41,7 +41,7 @@ namespace TestPlugin var methodBody = module.GetMethodBody(methodDef.RelativeVirtualAddress); output.WriteLine("Size of method: {0} bytes", methodBody.GetCodeSize()); - ISmartTextOutput smartOutput = output as ISmartTextOutput; + ISmartTextOutput? smartOutput = output as ISmartTextOutput; if (smartOutput != null) { // when writing to the text view (but not when writing to a file), we can even add UI elements such as buttons: diff --git a/TestPlugin/CustomOptionPage.xaml.cs b/TestPlugin/CustomOptionPage.xaml.cs index 1c16be47f..b4d607917 100644 --- a/TestPlugin/CustomOptionPage.xaml.cs +++ b/TestPlugin/CustomOptionPage.xaml.cs @@ -50,7 +50,7 @@ namespace TestPlugin // Replace the existing section in the settings file, or add a new section, // if required. - XElement existingElement = root.Element(ns + "CustomOptions"); + XElement? existingElement = root.Element(ns + "CustomOptions"); if (existingElement != null) existingElement.ReplaceWith(section); else