Skip to content

Commit

Permalink
Fix some NREs that could occur when working with deleted members
Browse files Browse the repository at this point in the history
  • Loading branch information
ElektroKill committed Nov 27, 2023
1 parent 67c374c commit f159533
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dnSpy/dnSpy.Decompiler/Utils/StateMachineHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public static bool TryGetKickoffMethod(MethodDef method, [NotNullWhen(true)] out
var declType = method.DeclaringType;

// Assume all state machine types are nested types
if (!declType.IsNested)
if (declType is null || !declType.IsNested)
return false;

if (ImplementsInterface(declType, System_Runtime_CompilerServices, IAsyncStateMachine)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ object Create(IDocumentViewerToolTipProviderContext context, GenericParam gp) {

provider.CreateNewOutput();
try {
var docProvider = XmlDocLoader.LoadDocumentation(gp.Module);
if (docProvider is not null) {
if (!provider.Output.WriteXmlDocGeneric(GetDocumentation(docProvider, gp.Owner), gp.Name) && gp.Owner is TypeDef) {
if (gp.Module is not null) {
var docProvider = XmlDocLoader.LoadDocumentation(gp.Module);
if (docProvider is not null && !provider.Output.WriteXmlDocGeneric(GetDocumentation(docProvider, gp.Owner), gp.Name) && gp.Owner is TypeDef def) {
// If there's no doc available, use the parent class' documentation if this
// is a generic type parameter (and not a generic method parameter).
var owner = ((TypeDef)gp.Owner).DeclaringType;
var owner = def.DeclaringType;
while (owner is not null) {
if (provider.Output.WriteXmlDocGeneric(GetDocumentation(docProvider, owner), gp.Name))
break;
Expand Down Expand Up @@ -149,7 +149,7 @@ object Create(IDocumentViewerToolTipProviderContext context, IMemberRef @ref) {
context.Decompiler.WriteToolTip(provider.Output, @ref, null);
provider.CreateNewOutput();
try {
if (resolvedRef is IMemberDef) {
if (resolvedRef is IMemberDef && resolvedRef.Module is not null) {
var docProvider = XmlDocLoader.LoadDocumentation(resolvedRef.Module);
if (docProvider is not null)
provider.Output.WriteXmlDoc(GetDocumentation(docProvider, resolvedRef));
Expand Down Expand Up @@ -177,9 +177,9 @@ object Create(IDocumentViewerToolTipProviderContext context, SourceParameter par
provider.CreateNewOutput();
var method = parameter.Parameter.Method;
try {
var docProvider = XmlDocLoader.LoadDocumentation(method.Module);
if (docProvider is not null) {
if (!provider.Output.WriteXmlDocParameter(GetDocumentation(docProvider, method), parameter.Name)) {
if (method.Module is not null) {
var docProvider = XmlDocLoader.LoadDocumentation(method.Module);
if (docProvider is not null && !provider.Output.WriteXmlDocParameter(GetDocumentation(docProvider, method), parameter.Name)) {
var owner = method.DeclaringType;
while (owner is not null) {
if (provider.Output.WriteXmlDocParameter(GetDocumentation(docProvider, owner), parameter.Name))
Expand Down
2 changes: 1 addition & 1 deletion dnSpy/dnSpy/Images/DotNetImageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ type.DeclaringType is null &&
type.Name == "Exception" &&
type.DefinitionAssembly.IsCorLib();
public ImageReference GetImageReference(FieldDef field) {
if (field.DeclaringType.IsEnum && !field.IsSpecialName) {
if (field.DeclaringType is not null && field.DeclaringType.IsEnum && !field.IsSpecialName) {
switch (field.Access) {
default:
case FieldAttributes.Public:
Expand Down

0 comments on commit f159533

Please sign in to comment.