Skip to content

Commit

Permalink
Fix possible null de-reference
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-englert committed Sep 3, 2024
1 parent 067c56f commit 7ce273e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions ILSpy/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpyX;

using TomsToolbox.Essentials;

namespace ICSharpCode.ILSpy
{
/// <summary>
Expand Down Expand Up @@ -124,9 +126,9 @@ public static Point TransformFromDevice(this Point point, Visual visual)
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
if (child is T dependencyObject)
{
return (T)child;
return dependencyObject;
}

T? childItem = FindVisualChild<T>(child);
Expand Down Expand Up @@ -177,17 +179,18 @@ internal static bool FormatExceptions(this IList<App.ExceptionData> exceptions,
else
output.AppendLine("-------------------------------------------------");
output.AppendLine("Error(s) loading plugin: " + item.PluginName);
if (item.Exception is System.Reflection.ReflectionTypeLoadException)
if (item.Exception is System.Reflection.ReflectionTypeLoadException exception)
{
var e = (System.Reflection.ReflectionTypeLoadException)item.Exception;
foreach (var ex in e.LoaderExceptions)
foreach (var ex in exception.LoaderExceptions.ExceptNullItems())
{
output.AppendLine(ex.ToString());
output.AppendLine();
}
}
else
{
output.AppendLine(item.Exception.ToString());
}
}

return true;
Expand Down

0 comments on commit 7ce273e

Please sign in to comment.