Exemplo n.º 1
0
        /// <summary>
        /// Initializes a type with its parent model and the XML node is represents.
        /// </summary>
        /// <param name="model">The parent model containing this type.</param>
        /// <param name="node">The XML node represented by this type.</param>
        /// <exception cref="FormatException">The name attribute has an invalid format.</exception>
        public Type(XmlDocumentationModel model, XmlNode node) : base(model, node)
        {
            // ReSharper disable once PossibleNullReferenceException
            var name = node.Attributes["name"].Value;

            if (!name.StartsWith("T:"))
            {
                throw new FormatException($"Bad type name format: {name}");
            }
            name = name.Substring(2);
            if (name.StartsWith(Model.AssemblyName + "."))
            {
                name = name.Substring(Model.AssemblyName.Length + 1);
            }
            var parts = name.Split(new[] { "." }, StringSplitOptions.None);

            Name = parts[parts.Length - 1];
            var potentialContainingTypeName =
                $"T:{Model.AssemblyName}.{string.Join(".", parts.Take(parts.Length - 1))}";
            var potentialContainingTypeId = potentialContainingTypeName;

            if (Model.Members.ContainsKey(potentialContainingTypeId))
            {
                var containingType = (Type)Model.Members[potentialContainingTypeId];
                NamespaceStrings = containingType.NamespaceStrings;
                containingType.NestedTypes.Add(this);
                ContainingType = containingType;
            }
            else
            {
                NamespaceStrings = parts.Take(parts.Length - 1).Select(p => Regex.Replace(p, "`(\\d+)", "")).ToArray();
            }
            var summary = node.SelectSingleNode("summary");

            if (summary != null)
            {
                Documentation = new Documentation(summary);
            }
            var paramTypes = node.SelectNodes("typeparam");

            if (paramTypes != null)
            {
                foreach (XmlNode paramType in paramTypes)
                {
                    TypeParameters.Add(new TypeParameter(paramType));
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a member with its parent model and the XML node is represents.
        /// </summary>
        /// <param name="model">The parent model containing this member.</param>
        /// <param name="node">The XML node represented by this member.</param>
        /// <exception cref="ArgumentNullException">node is null.</exception>
        /// <exception cref="InvalidOperationException">Required XML attribute/element is missing.</exception>
        protected Member(XmlDocumentationModel model, XmlNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }
            Model = model;
            if (node.Attributes?["name"] == null)
            {
                throw new InvalidOperationException("Missing name attribute");
            }
            var name = node.Attributes["name"].Value;

            if (string.IsNullOrEmpty(name))
            {
                throw new InvalidOperationException("Missing name attribute");
            }
            Id = name;
        }
Exemplo n.º 3
0
        /// <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);
            }
        }
Exemplo n.º 4
0
        /// <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));
                }
            }
        }