Browse Source

Fix nullability warnings in AstNode and XmlDocumentationElement.

pull/2639/head
Siegfried Pammer 3 years ago
parent
commit
2e31427d56
  1. 4
      ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs
  2. 4
      ICSharpCode.Decompiler/Documentation/XmlDocumentationElement.cs

4
ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs

@ -358,9 +358,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
return Ancestors.OfType<T>().FirstOrDefault(); return Ancestors.OfType<T>().FirstOrDefault();
} }
public AstNode GetParent(Func<AstNode, bool>? pred) public AstNode? GetParent(Func<AstNode, bool>? pred)
{ {
return Ancestors.FirstOrDefault(pred); return pred != null ? Ancestors.FirstOrDefault(pred) : Ancestors.FirstOrDefault();
} }
public AstNodeCollection<T> GetChildrenByRole<T>(Role<T> role) where T : AstNode public AstNodeCollection<T> GetChildrenByRole<T>(Role<T> role) where T : AstNode

4
ICSharpCode.Decompiler/Documentation/XmlDocumentationElement.cs

@ -118,7 +118,7 @@ namespace ICSharpCode.Decompiler.Documentation
/// </summary> /// </summary>
public string? GetAttribute(string? name) public string? GetAttribute(string? name)
{ {
return element?.Attribute(name)?.Value; return name == null ? null : element?.Attribute(name)?.Value;
} }
/// <summary> /// <summary>
@ -212,7 +212,7 @@ namespace ICSharpCode.Decompiler.Documentation
var doc = XDocument.Parse(inheritedDocumentation).Element("doc"); var doc = XDocument.Parse(inheritedDocumentation).Element("doc");
// XPath filter not yet implemented // XPath filter not yet implemented
if (childElement.Parent?.Parent == null && childElement.Attribute("select")?.Value == null) if (doc != null && childElement.Parent?.Parent == null && childElement.Attribute("select")?.Value == null)
{ {
// Inheriting documentation at the root level // Inheriting documentation at the root level
List<string> doNotInherit = new List<string>(); List<string> doNotInherit = new List<string>();

Loading…
Cancel
Save