-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception thrown for non-generic method inside generic class #93
Comments
Can you share the code of how you get the Using the |
Sure, there you go. Type being evaluated: /// <summary>
/// Comment.
/// </summary>
public class GenericClass<TType> : IInterfaceA, IInterfaceB<TType>
where TType : class
{
// ...
/// <summary>
/// Comment.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
} This is the code that uses your library: var members = type.GetMembers(
BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic
).Where(m => !m.Name.StartsWith("get_") && !m.Name.StartsWith("set_"));
foreach (var memberInfo in members)
{
switch (memberInfo.MemberType)
{
// ...
case MemberTypes.Method:
var method = (MethodInfo)memberInfo;
if (method.IsPrivate)
{
continue;
}
var methodDoc = method.GetDocumentation();
}
} Is this helpful? |
@ZacharyPatten I don't know if it could break some other part of the code, but by changing it to: if (methodInfo.DeclaringType.IsGenericType && methodInfo.IsGenericMethod)
{
methodInfo = methodInfo.DeclaringType.GetGenericTypeDefinition().GetMethods(
BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic
).First(x => x.MetadataToken == methodInfo.MetadataToken);
} Because protected methods were not being returned. it works. I don't know if it could break something else, I'm still testing it, but at least for the first scenario it works. |
I just tested that solution with my full project and it seems to be working. Thanks for your help! |
Ah... you are 100% correct. I never added the If you would like to open a pull request I would gladly pull in this code fix. That way you can get credit for the fix. :) Otherwise I can fix it myself. Let me know. I will also add a unit test for this to ensure it will be covered in future regression testing. |
Awesome, I don't mind the credit 😅 Again, thank you for your work! |
This fix was deployed in https://github.com/ZacharyPatten/Towel/releases/tag/1.0.40 Sorry you ran into another bug, but thank you for addressing it so it could be fixed. :) As always, if the fix did not fully resolve the issue feel free to re-open. |
@ZacharyPatten thank you! |
The exception:
This exception happens on Meta.cs, line 846:
Towel/Sources/Towel/Meta.cs
Line 846 in 527a9f4
My method is not generic and the class is, is it still required to update the method info in that case?
Structure:
The problem is, the
MetadataToken
for the methods are different, please take a look:This is the value for the original method info (the one that called
GetDocumentation
:And this is the value for the one in the call response:
@ZacharyPatten please let me know if you need more information, I'm also trying to figure it out on my end.
The text was updated successfully, but these errors were encountered: