Ejemplo n.º 1
0
        private void RenderImplicitOrExplicitOperator(
            HtmlTextWriter writer,
            MethodSignature signature,
            MethodRenderOption options,
            bool isImplicit)
        {
            if ((options & MethodRenderOption.TypeName) == MethodRenderOption.TypeName ||
                (options & MethodRenderOption.TypeFullName) == MethodRenderOption.TypeFullName)
            {
                writer.WriteEncodedText(".");
            }

            if ((options & MethodRenderOption.Name) == MethodRenderOption.Name)
            {
                writer.WriteEncodedText(isImplicit ? "Implicit" : "Explicit");
            }

            if ((options & MethodRenderOption.Parameters) == MethodRenderOption.Parameters)
            {
                if ((options & MethodRenderOption.Name) == MethodRenderOption.Name)
                {
                    writer.WriteEncodedText(" ");
                }

                writer.WriteEncodedText("(\u200B");
                _renderer.Render(writer, signature.Parameters[0].ParameterType, TypeRenderOption.Name);
                writer.WriteEncodedText(" to ");
                _renderer.Render(writer, signature.ReturnType, TypeRenderOption.Name);
                writer.WriteEncodedText(")\u200B");
            }
        }
Ejemplo n.º 2
0
 public MvcHtmlString Render(LanguageProvider language,
     MethodSignature signature,
     MethodRenderOption options)
 {
     var builder = new HtmlTextWriter(new StringWriter());
     Render(builder, language, signature, options);
     return MvcHtmlString.Create(builder.InnerWriter.ToString());
 }
Ejemplo n.º 3
0
 public static IHtmlString MethodLink(this ApiServices context, DocumentedMethod method, MethodRenderOption options)
 {
     if (method != null)
     {
         var signature = context.SignatureResolver.GetMethodSignature(method);
         return context.SignatureRenderer.Render(signature, MethodRenderOption.Link | options);
     }
     return MvcHtmlString.Empty;
 }
Ejemplo n.º 4
0
        public MvcHtmlString Render(LanguageProvider language,
                                    MethodSignature signature,
                                    MethodRenderOption options)
        {
            var builder = new HtmlTextWriter(new StringWriter());

            Render(builder, language, signature, options);
            return(MvcHtmlString.Create(builder.InnerWriter.ToString()));
        }
Ejemplo n.º 5
0
        public string Render(
            ILanguageProvider language,
            MethodSignature signature,
            MethodRenderOption options)
        {
            var builder = new StringBuilder();

            // Add link.
            if ((options & MethodRenderOption.Link) == MethodRenderOption.Link)
            {
                builder.AppendFormat(@"<a href=""{0}"">", signature.Url);
            }

            if ((options & MethodRenderOption.Name) == MethodRenderOption.Name)
            {
                builder.Append(signature.Name);
            }

            if ((options & MethodRenderOption.Parameters) == MethodRenderOption.Parameters)
            {
                builder.Append("(");
                var parameterResult = new List <string>();
                foreach (var parameter in signature.Parameters)
                {
                    var parameterBuilder = new StringBuilder();
                    if (parameter.IsOutParameter)
                    {
                        parameterBuilder.Append("out ");
                    }
                    else if (parameter.IsRefParameter)
                    {
                        parameterBuilder.Append("ref ");
                    }

                    var paramType = _renderer.Render(language, parameter.ParameterType, TypeRenderOption.Name);
                    parameterBuilder.Append(paramType);
                    parameterResult.Add(parameterBuilder.ToString());
                }
                if (parameterResult.Count > 0)
                {
                    builder.Append(string.Join(", ", parameterResult));
                }
                builder.Append(")");
            }

            if ((options & MethodRenderOption.Link) == MethodRenderOption.Link)
            {
                builder.Append(@"</a>");
            }

            return(builder.ToString());
        }
Ejemplo n.º 6
0
 private static MethodRenderOption FixOptions(DocumentedMethod method, MethodRenderOption options)
 {
     if (method.Metadata.IsAlias)
     {
         if (method.Metadata.IsPropertyAlias)
         {
             options |= MethodRenderOption.PropertyAlias;
         }
         else
         {
             options |= MethodRenderOption.MethodAlias;
         }
     }
     return(options);
 }
Ejemplo n.º 7
0
 private static MethodRenderOption FixOptions(DocumentedMethod method, MethodRenderOption options)
 {
     if (method.Metadata.IsAlias)
     {
         if (method.Metadata.IsPropertyAlias)
         {
             options |= MethodRenderOption.PropertyAlias;
         }
         else
         {
             options |= MethodRenderOption.MethodAlias;
         }
     }
     return options;
 }
Ejemplo n.º 8
0
 public static IHtmlString MethodLink(this ApiServices context, DocumentedMethod method, MethodRenderOption options)
 {
     if (method != null)
     {
         options = FixOptions(method, options);
         var signature = context.SignatureResolver.GetMethodSignature(method);
         return(context.SignatureRenderer.Render(signature, MethodRenderOption.Link | options));
     }
     return(MvcHtmlString.Empty);
 }
Ejemplo n.º 9
0
        public void Render(
            HtmlTextWriter writer,
            LanguageProvider language,
            MethodSignature signature,
            MethodRenderOption options)
        {
            // Add link.
            if ((options & MethodRenderOption.Link) == MethodRenderOption.Link)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Href, signature.Url);
                writer.RenderBeginTag(HtmlTextWriterTag.A);
            }

            // Declaring type (with or without namespace).
            if ((options & MethodRenderOption.TypeName) == MethodRenderOption.TypeName ||
                (options & MethodRenderOption.TypeFullName) == MethodRenderOption.TypeFullName)
            {
                var onlyTypeName = (options & MethodRenderOption.TypeName) == MethodRenderOption.TypeName;
                var typeOptions = onlyTypeName ? TypeRenderOption.Name : TypeRenderOption.Namespace;
                _renderer.Render(writer, signature.DeclaringType, typeOptions);
            }

            var isImplicitOperator = signature.OperatorClassification == OperatorClassification.Implicit;
            var isExplicitOperator = signature.OperatorClassification == OperatorClassification.Explicit;
            var isImplicitOrExplicitOperator = isImplicitOperator || isExplicitOperator;

            if (isImplicitOrExplicitOperator)
            {
                // Implicit operator
                RenderImplicitOrExplicitOperator(writer, signature, options, isImplicitOperator);
            }
            else
            {
                // Everything else.
                if ((options & MethodRenderOption.Name) == MethodRenderOption.Name)
                {
                    if ((options & MethodRenderOption.TypeName) == MethodRenderOption.TypeName ||
                        (options & MethodRenderOption.TypeFullName) == MethodRenderOption.TypeFullName)
                    {

                        writer.WriteEncodedText("\u200B.");
                    }
                    writer.WriteEncodedText(GetMethodName(signature));
                }

                var isPropertyAlias = (options & MethodRenderOption.PropertyAlias) == MethodRenderOption.PropertyAlias;
                if (!isPropertyAlias && (options & MethodRenderOption.Parameters) == MethodRenderOption.Parameters)
                {
                    if (signature.Classification != MethodClassification.Operator)
                    {
                        writer.WriteEncodedText("(");
                        var parameterResult = new List<string>();
                        foreach (var parameter in signature.Parameters)
                        {
                            var parameterBuilder = new StringBuilder();
                            if (parameter.IsOutParameter)
                            {
                                parameterBuilder.Append("out ");
                            }
                            else if (parameter.IsRefParameter)
                            {
                                parameterBuilder.Append("ref ");
                            }
                            var paramType = _renderer.Render(parameter.ParameterType, TypeRenderOption.Name);
                            parameterBuilder.Append(paramType);
                            parameterResult.Add(parameterBuilder.ToString());
                        }
                        if (parameterResult.Count > 0)
                        {
                            var isMethodAlias = (options & MethodRenderOption.MethodAlias) == MethodRenderOption.MethodAlias;
                            if (isMethodAlias || (options & MethodRenderOption.ExtensionMethod) == MethodRenderOption.ExtensionMethod)
                            {
                                if (signature.Classification == MethodClassification.ExtensionMethod)
                                {
                                    // Remove first parameter.
                                    parameterResult.RemoveAt(0);
                                }
                            }
                            writer.Write(string.Join(", \u200B", parameterResult));
                        }
                        writer.WriteEncodedText(")\u200B");
                    }
                }
            }

            if ((options & MethodRenderOption.Link) == MethodRenderOption.Link)
            {
                writer.RenderEndTag();
            }
        }
Ejemplo n.º 10
0
        private void RenderImplicitOrExplicitOperator(
            HtmlTextWriter writer,
            MethodSignature signature,
            MethodRenderOption options,
            bool isImplicit)
        {
            if ((options & MethodRenderOption.TypeName) == MethodRenderOption.TypeName ||
                (options & MethodRenderOption.TypeFullName) == MethodRenderOption.TypeFullName)
            {
                writer.WriteEncodedText(".");
            }

            if ((options & MethodRenderOption.Name) == MethodRenderOption.Name)
            {
                writer.WriteEncodedText(isImplicit ? "Implicit" : "Explicit");
            }

            if ((options & MethodRenderOption.Parameters) == MethodRenderOption.Parameters)
            {
                if ((options & MethodRenderOption.Name) == MethodRenderOption.Name)
                {
                    writer.WriteEncodedText(" ");
                }

                writer.WriteEncodedText("(\u200B");
                _renderer.Render(writer, signature.Parameters[0].ParameterType, TypeRenderOption.Name);
                writer.WriteEncodedText(" to ");
                _renderer.Render(writer, signature.ReturnType, TypeRenderOption.Name);
                writer.WriteEncodedText(")\u200B");
            }
        }
Ejemplo n.º 11
0
 public string Render(ILanguageProvider language, MethodSignature signature, MethodRenderOption options)
 {
     return(_methodRenderer.Render(language, signature, options));
 }
Ejemplo n.º 12
0
        public void Render(
            HtmlTextWriter writer,
            LanguageProvider language,
            MethodSignature signature,
            MethodRenderOption options)
        {
            // Add link.
            if ((options & MethodRenderOption.Link) == MethodRenderOption.Link)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Href, signature.Url);
                writer.RenderBeginTag(HtmlTextWriterTag.A);
            }

            // Declaring type (with or without namespace).
            if ((options & MethodRenderOption.TypeName) == MethodRenderOption.TypeName ||
                (options & MethodRenderOption.TypeFullName) == MethodRenderOption.TypeFullName)
            {
                var onlyTypeName = (options & MethodRenderOption.TypeName) == MethodRenderOption.TypeName;
                var typeOptions  = onlyTypeName ? TypeRenderOption.Name : TypeRenderOption.Namespace;
                _renderer.Render(writer, signature.DeclaringType, typeOptions);
            }

            var isImplicitOperator           = signature.OperatorClassification == OperatorClassification.Implicit;
            var isExplicitOperator           = signature.OperatorClassification == OperatorClassification.Explicit;
            var isImplicitOrExplicitOperator = isImplicitOperator || isExplicitOperator;

            if (isImplicitOrExplicitOperator)
            {
                // Implicit operator
                RenderImplicitOrExplicitOperator(writer, signature, options, isImplicitOperator);
            }
            else
            {
                // Everything else.
                if ((options & MethodRenderOption.Name) == MethodRenderOption.Name)
                {
                    if ((options & MethodRenderOption.TypeName) == MethodRenderOption.TypeName ||
                        (options & MethodRenderOption.TypeFullName) == MethodRenderOption.TypeFullName)
                    {
                        writer.WriteEncodedText("\u200B.");
                    }
                    writer.WriteEncodedText(GetMethodName(signature));
                }

                var isPropertyAlias = (options & MethodRenderOption.PropertyAlias) == MethodRenderOption.PropertyAlias;
                if (!isPropertyAlias && (options & MethodRenderOption.Parameters) == MethodRenderOption.Parameters)
                {
                    if (signature.Classification != MethodClassification.Operator)
                    {
                        writer.WriteEncodedText("(");
                        var parameterResult = new List <string>();
                        foreach (var parameter in signature.Parameters)
                        {
                            var parameterBuilder = new StringBuilder();
                            if (parameter.IsOutParameter)
                            {
                                parameterBuilder.Append("out ");
                            }
                            else if (parameter.IsRefParameter)
                            {
                                parameterBuilder.Append("ref ");
                            }
                            var paramType = _renderer.Render(parameter.ParameterType, TypeRenderOption.Name);
                            parameterBuilder.Append(paramType);
                            parameterResult.Add(parameterBuilder.ToString());
                        }
                        if (parameterResult.Count > 0)
                        {
                            var isMethodAlias = (options & MethodRenderOption.MethodAlias) == MethodRenderOption.MethodAlias;
                            if (isMethodAlias || (options & MethodRenderOption.ExtensionMethod) == MethodRenderOption.ExtensionMethod)
                            {
                                if (signature.Classification == MethodClassification.ExtensionMethod)
                                {
                                    // Remove first parameter.
                                    parameterResult.RemoveAt(0);
                                }
                            }
                            writer.Write(string.Join(", \u200B", parameterResult));
                        }
                        writer.WriteEncodedText(")\u200B");
                    }
                }
            }

            if ((options & MethodRenderOption.Link) == MethodRenderOption.Link)
            {
                writer.RenderEndTag();
            }
        }
Ejemplo n.º 13
0
 public IHtmlString Render(MethodSignature method, MethodRenderOption option)
 {
     return(_methodRenderer.Render(_languageProvider, method, option));
 }
Ejemplo n.º 14
0
 public IHtmlString Render(MethodSignature method, MethodRenderOption option)
 {
     return _methodRenderer.Render(_languageProvider, method, option);
 }