/// <summary> /// Initializes a property with its parent model and the XML node is represents. /// </summary> /// <param name="model">The parent model containing this property.</param> /// <param name="node">The XML node represented by this property.</param> /// <exception cref="FormatException">The name attribute has an invalid format.</exception> public Property(XmlDocumentationModel model, XmlNode node) : base(model, node) { // ReSharper disable once PossibleNullReferenceException var name = node.Attributes["name"].Value; if (!name.StartsWith("P:")) { throw new FormatException($"Bad property name format: {name}"); } name = name.Substring(2); if (!name.StartsWith(Model.AssemblyName + ".")) { throw new FormatException($"Bad property name format: {name}"); } var parentheseIdx = name.IndexOf("("); if (parentheseIdx > 0) { name = name.Substring(0, parentheseIdx); } name = name.Substring(Model.AssemblyName.Length + 1); var parts = name.Split(new[] { "." }, StringSplitOptions.None); Name = parts[parts.Length - 1]; var containingTypeName = Model.AssemblyName + "." + string.Join(".", parts.Take(parts.Length - 1)); var containingTypeId = "T:" + containingTypeName; var containingType = (Type)Model.Members[containingTypeId]; ContainingType = containingType; var summary = node.SelectSingleNode("summary"); if (summary != null) { Documentation = new Documentation(summary); } }
/// <summary> /// Initializes a method with its parent model and the XML node is represents. /// </summary> /// <param name="model">The parent model containing this method.</param> /// <param name="node">The XML node represented by this method.</param> /// <exception cref="FormatException">The name attribute has an invalid format.</exception> public Method(XmlDocumentationModel model, XmlNode node) : base(model, node) { // ReSharper disable once PossibleNullReferenceException var name = node.Attributes["name"].Value; if (!name.StartsWith("M:")) { throw new FormatException($"Bad method name format: {name}"); } name = name.Substring(2); if (!name.StartsWith(Model.AssemblyName + ".")) { throw new FormatException($"Bad method name format: {name}"); } name = name.Substring(Model.AssemblyName.Length + 1); var parentheseIdx = name.IndexOf("("); if (parentheseIdx > 0) { var parametersPart = name.Substring(parentheseIdx + 1).TrimEnd(')'); ParseParameters(parametersPart); name = name.Substring(0, parentheseIdx); } var parts = name.Split(new[] { "." }, StringSplitOptions.None); Name = parts[parts.Length - 1]; var containingTypeName = Model.AssemblyName + "." + string.Join(".", parts.Take(parts.Length - 1)); var containingTypeId = "T:" + containingTypeName; var containingType = (Type)Model.Members[containingTypeId]; ContainingType = containingType; var summary = node.SelectSingleNode("summary"); if (summary != null) { Documentation = new Documentation(summary); } var paramNodes = node.SelectNodes("param"); if (paramNodes != null) { var i = 0; foreach (XmlNode paramNode in paramNodes) { if (i < Parameters.Count) { Parameters[i].Documentation = new Documentation(paramNode); Parameters[i].Name = paramNode.Attributes?["name"]?.Value; } i++; } } var paramTypes = node.SelectNodes("typeparam"); if (paramTypes != null) { foreach (XmlNode paramType in paramTypes) { TypeParameters.Add(new TypeParameter(paramType)); } } var thrownExceptionNodes = node.SelectNodes("exception"); if (thrownExceptionNodes != null) { foreach (XmlNode thrownExceptionNode in thrownExceptionNodes) { ThrownExceptions.Add(new ThrownException(thrownExceptionNode)); } } }