giacomelli / docsbyreflection Goto Github PK
View Code? Open in Web Editor NEWDiscover the code documentation at runtime by reflection.
Discover the code documentation at runtime by reflection.
Currently this library only targets the .NET Framework. It would be nice if it supported .NET Core as well, since most code is heading that way.
To test: create a compiled command-line tool that uses DocsByReflection
about itself.
You can even hit it using administrative shares: \\localhost\C$\git\MySolution\MyApp\bin\debug\MyApp.exe
.
Error ---> DocsByReflection.DocsByReflectionException: Could not ascertain assembly filename from assembly code base 'file://storage/ict/Solutions/Systems/DocGen/Temp/1.12.7725.25130/DocGenDebug/DocGen.exe'
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.
Between version 1.0.12.14 -> 1.0.12.20 there is a regression causing the following error:
{
"Message": "An error has occurred.",
"ExceptionMessage": "The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.",
"ExceptionType": "System.InvalidOperationException",
"StackTrace": null,
"InnerException": {
"Message": "An error has occurred.",
"ExceptionMessage": "Unable to cast object of type 'System.Reflection.MdFieldInfo' to type 'System.Reflection.PropertyInfo'.",
"ExceptionType": "System.InvalidCastException",
"StackTrace": " at DocsByReflection.DocsService.GetXmlFromMember(MemberInfo member, Boolean throwError)\r\n at WebApiProxy.Server.MetadataProvider.GetDescription(MemberInfo member)\r\n at WebApiProxy.Server.MetadataProvider.<AddModelDefinition>b__8_1(FieldInfo constant)\r\n at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)\r\n at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__19.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Net.Http.HttpContent.<CopyToAsyncCore>d__44.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.WebHost.HttpControllerHandler.<WriteBufferedResponseContentAsync>d__22.MoveNext()"
}
}
Formatted stack trace:
at DocsByReflection.DocsService.GetXmlFromMember(MemberInfo member, Boolean throwError)\r\n
at WebApiProxy.Server.MetadataProvider.GetDescription(MemberInfo member)\r\n
at WebApiProxy.Server.MetadataProvider.<AddModelDefinition>b__8_1(FieldInfo constant)\r\n
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()\r\n
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)\r\n
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)\r\n
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n
at System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content)\r\n
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__19.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at System.Net.Http.HttpContent.<CopyToAsyncCore>d__44.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at System.Web.Http.WebHost.HttpControllerHandler.<WriteBufferedResponseContentAsync>d__22.MoveNext()
I want to get documentation for all properties that have it. Method DocsService.GetXmlFromMember
for properety without documentation throw exception. How I can check availability of documentation for property without exception catching?
I found an edge case that it's not handled.
class outerclass
{
void SomeFunction(innerclass[] input)
{}class innerclass
{}
}
In this case SomeFunction is ignored and the library cannot find the documentation for the element.
I added support for this case, it's really simple. In DocsTypeService add
else if (type.IsNested) { return String.Format(CultureInfo.InvariantCulture, "{0}{1}.{2}{3}", typeNamespace, type.DeclaringType.Name, type.Name, isOut ? "@" : "").Replace("&", ""); } else if (type.GetElementType() != null && type.GetElementType().IsNested) { // this is new return String.Format(CultureInfo.InvariantCulture, "{0}{1}.{2}{3}", typeNamespace, type.GetElementType().DeclaringType.Name, type.Name, isOut ? "@" : "").Replace("&", ""); } else { return String.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", typeNamespace, type.Name, isOut ? "@" : "").Replace("&", ""); }
Are the maintainer interested in adding this case?
Anyway, hope this modification helps someone.
Consider a method with following signature:
Task Foo(string text, byte[] content, string text, Dictionary<string, string> properties);
Then GetXmlFromMember returns null.
Hello,
When in xml file exist a comment an InvalidCastException is thrown: "Unable to cast object of type 'System.Xml.XmlComment' to type 'System.Xml.XmlElement'."
You can se this exception by example using Microsoft.Data.Service.xml in
This interface declares the methods required to support getting values
from projected results for $select queries
</summary>
</member>
I found the exception is thrown in the public static method GetXmlFromName in DocsTypeService.cs. In the foreach loop over the xmlDocument["doc"]["members"].
Regards,
José Luis
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.