DocsByReflection
DocsByReflection copied to clipboard
Fails to look up documentation for methods with out or ref parameters.
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.
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);
}
}
Please, make a pull-request with this fix.