Esempio n. 1
0
 public void Render(
     HtmlTextWriter writer,
     TypeSignature signature,
     TypeRenderOption options)
 {
     Render(writer, signature, options, false);
 }
Esempio n. 2
0
 public IHtmlString Render(
     TypeSignature signature,
     TypeRenderOption options)
 {
     var builder = new HtmlTextWriter(new StringWriter());
     Render(builder, signature, options, false);
     return MvcHtmlString.Create(builder.InnerWriter.ToString());
 }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MethodSignature" /> class.
 /// </summary>
 /// <param name="identity">The Identity.</param>
 /// <param name="name">The type name.</param>
 /// <param name="url">The url.</param>
 /// <param name="classification">The method classification.</param>
 /// <param name="operatorClassification">The operator classification.</param>
 /// <param name="declaringType">The declaring type.</param>
 /// <param name="returnType">The return type.</param>
 /// <param name="genericParameters">The method's generic parameters.</param>
 /// <param name="parameters">The parameters.</param>
 public MethodSignature(
     string identity,
     string name,
     string url,
     MethodClassification classification,
     OperatorClassification operatorClassification,
     TypeSignature declaringType,
     TypeSignature returnType,
     IEnumerable<string> genericParameters,
     IEnumerable<ParameterSignature> parameters)
 {
     Identity = identity;
     Name = name;
     Url = url;
     Classification = classification;
     OperatorClassification = operatorClassification;
     ReturnType = returnType;
     DeclaringType = declaringType;
     GenericParameters = new List<string>(genericParameters);
     Parameters = new List<ParameterSignature>(parameters);
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MethodSignature" /> class.
 /// </summary>
 /// <param name="identity">The Identity.</param>
 /// <param name="name">The type name.</param>
 /// <param name="url">The url.</param>
 /// <param name="classification">The method classification.</param>
 /// <param name="operatorClassification">The operator classification.</param>
 /// <param name="declaringType">The declaring type.</param>
 /// <param name="returnType">The return type.</param>
 /// <param name="genericParameters">The method's generic parameters.</param>
 /// <param name="parameters">The parameters.</param>
 public MethodSignature(
     string identity,
     string name,
     string url,
     MethodClassification classification,
     OperatorClassification operatorClassification,
     TypeSignature declaringType,
     TypeSignature returnType,
     IEnumerable<string> genericParameters,
     IEnumerable<ParameterSignature> parameters)
 {
     _identity = identity;
     _name = name;
     _url = url;
     _classification = classification;
     _operatorClassification = operatorClassification;
     _returnType = returnType;
     _declaringType = declaringType;
     _genericParameters = new List<string>(genericParameters);
     _parameters = new List<ParameterSignature>(parameters);
 }
Esempio n. 5
0
        private void Render(
            HtmlTextWriter writer,
            TypeSignature signature,
            TypeRenderOption options,
            bool isWritingLink)
        {
            var needToCloseLink = false;
            var documentedType = _model.FindType(signature.Identity);

            // Writing link?
            if ((options & TypeRenderOption.Link) == TypeRenderOption.Link)
            {
                if (!isWritingLink && documentedType != null)
                {
                    if (signature.Url != null)
                    {
                        isWritingLink = needToCloseLink = true;

                        writer.AddAttribute(HtmlTextWriterAttribute.Href, signature.Url);
                        writer.RenderBeginTag(HtmlTextWriterTag.A);
                    }
                }
            }

            // Write type namespace?
            if ((options & TypeRenderOption.Namespace) == TypeRenderOption.Namespace)
            {
                writer.WriteEncodedText(signature.Namespace.Name);
            }

            // Write type name?
            if ((options & TypeRenderOption.Name) == TypeRenderOption.Name)
            {
                if ((options & TypeRenderOption.Namespace) == TypeRenderOption.Namespace)
                {
                    writer.WriteEncodedText(".\u200B");
                }

                var alias = _language.GetAlias(signature.Identity);
                var name = alias ?? signature.Name;
                writer.WriteEncodedText(name);

                if (signature.GenericArguments.Count != 0)
                {
                    // Write generic arguments.
                    writer.WriteEncodedText("<");
                    var result = new List<string>();
                    foreach (var argument in signature.GenericArguments)
                    {
                        result.Add(argument);
                    }
                    writer.WriteEncodedText(string.Join(", \u200B", result));
                    writer.WriteEncodedText(">");
                }
                else if (signature.GenericParameters.Count != 0)
                {
                    // Write generic parameters.
                    writer.Write("<");
                    var result = new List<string>();
                    var parameterIndex = 0;
                    foreach (var parameter in signature.GenericParameters)
                    {
                        parameterIndex++;
                        Render(writer, parameter, options, isWritingLink);
                        if (parameterIndex != signature.GenericParameters.Count)
                        {
                            writer.WriteEncodedText(",\u200B");
                            writer.WriteEncodedText(" ");
                        }
                    }
                    writer.WriteEncodedText(string.Join(", \u200B", result));
                    writer.Write(">");
                }
            }

            // Writing link?
            if ((options & TypeRenderOption.Link) == TypeRenderOption.Link)
            {
                if (needToCloseLink)
                {
                    writer.RenderEndTag();
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Renders the syntax for a type.
        /// </summary>
        /// <param name="writer">The text writer.</param>
        /// <param name="signature">The type signature.</param>
        public void Render(HtmlTextWriter writer, TypeSignature signature)
        {
            var type = _resolver.FindType(signature.Identity);
            if (type == null)
            {
                throw new InvalidOperationException("Could not find type.");
            }

            if (type.Definition.IsPublic)
            {
                writer.WriteEncodedText("public");
            }

            if (!type.Definition.IsEnum)
            {
                if (type.Definition.IsAbstract && type.Definition.IsSealed)
                {
                    // Static
                    writer.WriteEncodedText(" ");
                    writer.WriteEncodedText("static");
                }
                else
                {
                    if (type.TypeClassification != TypeClassification.Interface)
                    {
                        if (type.Definition.IsAbstract)
                        {
                            // Abstract
                            writer.WriteEncodedText(" ");
                            writer.WriteEncodedText("abstract");
                        }
                        else if (type.Definition.IsSealed)
                        {
                            // Sealed
                            writer.WriteEncodedText(" ");
                            writer.WriteEncodedText("sealed");
                        }
                    }
                }
            }

            // Type classification
            writer.WriteEncodedText(" ");
            writer.WriteEncodedText(type.TypeClassification.ToString().ToLowerInvariant());

            // Type name
            writer.WriteEncodedText(" ");
            var typeSignature = _signatureResolver.GetTypeSignature(type);
            _renderer.Render(writer, typeSignature, TypeRenderOption.Name);

            if (!type.Definition.IsEnum)
            {
                // Base classes (and interfaces).
                var baseClasses = GetBaseTypes(type);
                if (baseClasses.Count > 0)
                {
                    writer.WriteEncodedText(" : ");
                    writer.Write(string.Join(", ", baseClasses));
                }

                // Generic parameter constraints.
                var constraints = GetGenericParameterConstraints(type);
                if (constraints.Count > 0)
                {
                    foreach (var constraint in constraints)
                    {
                        writer.WriteLine();
                        writer.WriteEncodedText("   where " + constraint.Key + " : ");
                        writer.Write(string.Join(", ", constraint.Value));
                    }
                }
            }
        }
Esempio n. 7
0
 public IHtmlString Render(TypeSignature signature)
 {
     var writer = new HtmlTextWriter(new StringWriter());
     Render(writer, signature);
     return MvcHtmlString.Create(writer.InnerWriter.ToString());
 }
Esempio n. 8
0
 public IHtmlString Render(TypeSignature type, TypeRenderOption option)
 {
     return _typeRenderer.Render(type, option);
 }
Esempio n. 9
0
 public void Render(HtmlTextWriter writer, TypeSignature type, TypeRenderOption option)
 {
     _typeRenderer.Render(writer, type, option);
 }