コード例 #1
0
 internal static string TypeParameter(XDocument xmlComments, MethodInfo method, Type genericArgument)
 {
     return(XmlCommentHelper.MethodElement(xmlComments, method)
            ?.Descendants("typeparam")
            .FirstOrDefault(el => el.Attribute("name")?.Value == genericArgument.Name)
            ?.Value ??
            string.Empty);
 }
コード例 #2
0
 internal static string Returns(XDocument xmlComments, MethodInfo method)
 {
     return(XmlCommentHelper.MethodElement(xmlComments, method)
            ?.Descendants("returns")
            .FirstOrDefault()
            ?.Value ??
            string.Empty);
 }
コード例 #3
0
 internal static string Parameter(XDocument xmlComments, MethodBase method, ParameterInfo parameter)
 {
     return(XmlCommentHelper.MethodElement(xmlComments, method)
            ?.Descendants("param")
            .FirstOrDefault(el => el.Attribute("name")?.Value == parameter.Name)
            ?.Value ??
            string.Empty);
 }
コード例 #4
0
        private static string MemberNameAttribute(MethodBase methodInfo)
        {
            var stringBuilder = new StringBuilder(256);

            stringBuilder.Append("M:");
            stringBuilder.Append(methodInfo.DeclaringType?.FullName);
            stringBuilder.Append('.');
            stringBuilder.Append(methodInfo.Name.Replace('.', '#'));

            Type[]? genericTypeArguments = null;

            if (methodInfo.DeclaringType != null && methodInfo.DeclaringType.IsGenericTypeDefinition)
            {
                genericTypeArguments = methodInfo.DeclaringType.GetGenericArguments();
            }

            Type[]? genericMethodArguments = null;

            if (methodInfo.IsGenericMethodDefinition)
            {
                genericMethodArguments = methodInfo.GetGenericArguments();

                stringBuilder.Append("``");
                stringBuilder.Append(methodInfo.GetGenericArguments().Length);
            }

            var parameters = methodInfo.GetParameters();

            if (parameters.Length > 0)
            {
                stringBuilder.Append('(');

                stringBuilder.Append(
                    XmlCommentHelper.ReplaceGenericMethodParameter(
                        genericTypeArguments,
                        genericMethodArguments,
                        parameters[0].ParameterType));

                for (var i = 1; i < parameters.Length; ++i)
                {
                    stringBuilder.Append(',');

                    stringBuilder.Append(
                        XmlCommentHelper.ReplaceGenericMethodParameter(
                            genericTypeArguments,
                            genericMethodArguments,
                            parameters[i].ParameterType));
                }

                stringBuilder.Append(')');
            }

            return(stringBuilder.ToString());
        }
コード例 #5
0
        private static string?ReplaceGenericMethodParameter(
            Type[]?genericTypeArguments,
            Type[]?genericMethodArguments,
            Type parameterType)
        {
            if (parameterType.IsGenericType)
            {
                var parameterGenericArguments = parameterType.GetGenericArguments();

                var stringBuilder = new StringBuilder(256);

                stringBuilder.Append(parameterType.Namespace);

                if (!string.IsNullOrEmpty(parameterType.Namespace))
                {
                    stringBuilder.Append('.');
                }

                stringBuilder.Append(parameterType.Name.Split('`')[0]);
                stringBuilder.Append('{');

                stringBuilder.Append(
                    XmlCommentHelper.ReplaceGenericMethodParameter(
                        genericTypeArguments,
                        genericMethodArguments,
                        parameterGenericArguments[0]));

                for (var i = 1; i < parameterGenericArguments.Length; ++i)
                {
                    stringBuilder.Append(',');

                    stringBuilder.Append(
                        XmlCommentHelper.ReplaceGenericMethodParameter(
                            genericTypeArguments,
                            genericMethodArguments,
                            parameterGenericArguments[i]));
                }

                stringBuilder.Append('}');

                return(stringBuilder.ToString());
            }

            if (parameterType.FullName == null)
            {
                if (genericTypeArguments != null)
                {
                    for (var i = 0; i < genericTypeArguments.Length; ++i)
                    {
                        if (genericTypeArguments[i].Name == parameterType.Name)
                        {
                            return("`" + i);
                        }
                    }
                }

                if (genericMethodArguments != null)
                {
                    for (var i = 0; i < genericMethodArguments.Length; ++i)
                    {
                        if (genericMethodArguments[i].Name == parameterType.Name)
                        {
                            return("``" + i);
                        }
                    }
                }
            }

            return(parameterType.FullName);
        }