diff --git a/ICSharpCode.Decompiler/Documentation/XmlDocumentationElement.cs b/ICSharpCode.Decompiler/Documentation/XmlDocumentationElement.cs index 61948f6ca..ab1714e2a 100644 --- a/ICSharpCode.Decompiler/Documentation/XmlDocumentationElement.cs +++ b/ICSharpCode.Decompiler/Documentation/XmlDocumentationElement.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. +#nullable enable + using System; using System.Collections.Generic; using System.Linq; @@ -40,10 +42,10 @@ namespace ICSharpCode.Decompiler.Documentation return new XmlDocumentationElement(XElement.Parse(documentationComment), declaringEntity, null); } - readonly XElement element; - readonly IEntity declaringEntity; - readonly Func crefResolver; - volatile string textContent; + readonly XElement? element; + readonly IEntity? declaringEntity; + readonly Func? crefResolver; + volatile string? textContent; /// /// Inheritance level; used to prevent cyclic doc inheritance. @@ -53,7 +55,7 @@ namespace ICSharpCode.Decompiler.Documentation /// /// Creates a new documentation element. /// - public XmlDocumentationElement(XElement element, IEntity declaringEntity, Func crefResolver) + public XmlDocumentationElement(XElement element, IEntity? declaringEntity, Func? crefResolver) { if (element == null) throw new ArgumentNullException(nameof(element)); @@ -65,7 +67,7 @@ namespace ICSharpCode.Decompiler.Documentation /// /// Creates a new documentation element. /// - public XmlDocumentationElement(string text, IEntity declaringEntity) + public XmlDocumentationElement(string text, IEntity? declaringEntity) { if (text == null) throw new ArgumentNullException(nameof(text)); @@ -77,26 +79,26 @@ namespace ICSharpCode.Decompiler.Documentation /// Gets the entity on which this documentation was originally declared. /// May return null. /// - public IEntity DeclaringEntity { + public IEntity? DeclaringEntity { get { return declaringEntity; } } - IEntity referencedEntity; + IEntity? referencedEntity; volatile bool referencedEntityInitialized; /// /// Gets the entity referenced by the 'cref' attribute. /// May return null. /// - public IEntity ReferencedEntity { + public IEntity? ReferencedEntity { get { if (!referencedEntityInitialized) { - string cref = GetAttribute("cref"); + string? cref = GetAttribute("cref"); try { if (!string.IsNullOrEmpty(cref) && crefResolver != null) - referencedEntity = crefResolver(cref); + referencedEntity = crefResolver(cref!); } catch { @@ -120,7 +122,7 @@ namespace ICSharpCode.Decompiler.Documentation /// /// Gets the attribute value. /// - public string GetAttribute(string name) + public string? GetAttribute(string? name) { return element?.Attribute(name)?.Value; } @@ -148,7 +150,7 @@ namespace ICSharpCode.Decompiler.Documentation } } - IList children; + IList? children; /// /// Gets the child elements. @@ -159,7 +161,7 @@ namespace ICSharpCode.Decompiler.Documentation return EmptyList.Instance; return LazyInitializer.EnsureInitialized( ref this.children, - () => CreateElements(element.Nodes(), declaringEntity, crefResolver, nestingLevel)); + () => CreateElements(element.Nodes(), declaringEntity, crefResolver, nestingLevel))!; } } @@ -168,7 +170,7 @@ namespace ICSharpCode.Decompiler.Documentation "remarks", "returns", "threadsafety", "value" }; - static List CreateElements(IEnumerable childObjects, IEntity declaringEntity, Func crefResolver, int nestingLevel) + static List CreateElements(IEnumerable childObjects, IEntity? declaringEntity, Func? crefResolver, int nestingLevel) { List list = new List(); foreach (var child in childObjects) @@ -189,9 +191,9 @@ namespace ICSharpCode.Decompiler.Documentation if (nestingLevel < 5 && childElement.Name == "inheritdoc") { string cref = childElement.Attribute("cref").Value; - IEntity inheritedFrom = null; - string inheritedDocumentation = null; - if (cref != null) + IEntity? inheritedFrom = null; + string? inheritedDocumentation = null; + if (cref != null && crefResolver != null) { inheritedFrom = crefResolver(cref); if (inheritedFrom != null) @@ -225,7 +227,7 @@ namespace ICSharpCode.Decompiler.Documentation var inheritedChildren = doc.Nodes().Where( inheritedObject => { - XElement inheritedElement = inheritedObject as XElement; + XElement? inheritedElement = inheritedObject as XElement; return !(inheritedElement != null && doNotInherit.Contains(inheritedElement.Name.LocalName)); }); @@ -244,14 +246,14 @@ namespace ICSharpCode.Decompiler.Documentation if (string.IsNullOrWhiteSpace(list[0].textContent)) list.RemoveAt(0); else - list[0].textContent = list[0].textContent.TrimStart(); + list[0].textContent = list[0].textContent!.TrimStart(); } if (list.Count > 0 && list[list.Count - 1].IsTextNode) { if (string.IsNullOrWhiteSpace(list[list.Count - 1].textContent)) list.RemoveAt(list.Count - 1); else - list[list.Count - 1].textContent = list[list.Count - 1].textContent.TrimEnd(); + list[list.Count - 1].textContent = list[list.Count - 1].textContent!.TrimEnd(); } return list; }