c# - ASP.NET Web API Help Page can't process Generic Type Controller -
c# - ASP.NET Web API Help Page can't process Generic Type Controller -
i have question asp.net web api helppages.
usually helppages can generate webapi xmldocumentation sample code:
public class valuecontrollerbase : apicontroller { /// <summary> /// base of operations /// </summary> public ienumerable<string> do() { homecoming new string[] { "value1", "value2" }; } } public class valuescontroller : valuecontrollerbase { /// <summary> /// testing api /// </summary> public string get(int id) { homecoming "value"; } }
this can generate successfully, this:
api api/values/get/{id} description testing api api post api/values/do description base of operations
but if utilize generic base of operations controller, not generate api document.
sample:
public class valuecontrollerbase<t> : apicontroller { /// <summary> /// base of operations /// </summary> public ienumerable<string> do() { homecoming new string[] { "value1", "value2" }; } } public class valuescontroller<string> : valuecontrollerbase { /// <summary> /// testing api /// </summary> public string get(int id) { homecoming "value"; } }
if utilize code @ sec section, helppages can generate api document, doesn't generate api annotation. difference between 2 examples sec section code utilize generic type.
api api/values/get/{id} description testing api api post api/values/do description null
in method do()
, annotation doesn't display compared first
is there solution prepare these problems?
i able solve adjusting code in xmldocumentationprovider
.
the original implemention of xmldocumentationprovider.gettypename(type)
following:
private static string gettypename(type type) { string name = type.fullname; if (type.isgenerictype) { // format generic type name like: generic{system.int32,system.string} type generictype = type.getgenerictypedefinition(); type[] genericarguments = type.getgenericarguments(); string generictypename = generictype.fullname; // trim generic parameter counts name generictypename = generictypename.substring(0, generictypename.indexof('`')); string[] argumenttypenames = genericarguments.select(t => gettypename(t)).toarray(); name = string.format(cultureinfo.invariantculture, "{0}{{{1}}}", generictypename, string.join(",", argumenttypenames)); } if (type.isnested) { // changing nested type name outertype+innertype outertype.innertype match xml documentation syntax. name = name.replace("+", "."); } homecoming name; }
i don't know why, effort create type name xml lookup include actual generic attributes, rather generic type name (for example, create nullable{bool} rather nullable`1). generic name defined in xml file.
a simple alter code gets name/reference documentation generic class correctly:
.... if (type.isgenerictype) { type generictype = type.getgenerictypedefinition(); name = generictype.fullname; } ....
after making change, annotations began display correctly generics types, , me, didn't break else either.
c# asp.net-web-api asp.net-web-api-helppages
Comments
Post a Comment