DocsByReflection icon indicating copy to clipboard operation
DocsByReflection copied to clipboard

Fails to look up documentation for methods with out or ref parameters.

Open Shane88 opened this issue 10 years ago • 2 comments

When trying to look up documentation for a method that has out or ref parameters DocsService.GetXmlFromMember fails. I originally tried using the code here http://jimblackler.net/blog/?p=49 and ran into this issue. I then tried using this nuget package which also has the same issue. I reverted back to the code on jim blacklers blog and changed a small piece of code in DocsByReflection.XMLFromMember(MethodInfo methodInfo)

Where the following line was

parametersString += parameterInfo.ParameterType.FullName;

I changed it too

if (parameterInfo.ParameterType.IsByRef)
{
    parametersString += parameterInfo.ParameterType.FullName.Replace('&', '@');
}
else
{
    parametersString += parameterInfo.ParameterType.FullName;
}

I have not identified where the appropriate fix would be in this projects code base. The problem was that the types name for ref and out parameters contains a trailing &, but the XML documentation contains a @ instead.

Shane88 avatar Jan 05 '15 03:01 Shane88

I'd rather suggest this fix:

        public static string GetTypeFullNameForXmlDoc(Type type, bool isMethodParameter = false)
        {
            if (type.MemberType == MemberTypes.TypeInfo && type.IsGenericType && (!type.IsClass || isMethodParameter))
            {
                return String.Format(CultureInfo.InvariantCulture,
                    "{0}.{1}{{{2}}}",
                    type.Namespace,
                    type.Name.Replace("`1", ""),
                    GetTypeFullNameForXmlDoc(type.GetGenericArguments().FirstOrDefault()));
            }
            else if (type.IsByRef)
            {
                return String.Format(CultureInfo.InvariantCulture, "{0}@", GetTypeFullNameForXmlDoc(type.GetElementType()));
            }
            else if (type.IsNested)
            {
                return String.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}", type.Namespace, type.DeclaringType.Name, type.Name);
            }
            else
            {
                return String.Format(CultureInfo.InvariantCulture, "{0}.{1}", type.Namespace, type.Name);
            }
        }

msamusenka avatar Nov 30 '15 10:11 msamusenka

Please, make a pull-request with this fix.

giacomelli avatar Sep 24 '20 10:09 giacomelli