Skip to content

Commit

Permalink
fixes #52
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharyPatten committed Jun 29, 2021
1 parent baddb07 commit afddb2f
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/Towel/Meta.cs
Expand Up @@ -831,6 +831,11 @@ internal static string GetXmlNameMethodBase(MethodInfo? methodInfo = null, Const
throw new TowelBugException($"{nameof(GetDocumentation)} {nameof(methodInfo)} is not null && {nameof(constructorInfo)} is not null");
}

if (methodInfo is not null && methodInfo.DeclaringType!.IsGenericType)
{
methodInfo = methodInfo.DeclaringType.GetGenericTypeDefinition().GetMethods().First(x => x.MetadataToken == methodInfo.MetadataToken);
}

MethodBase? methodBase = methodInfo ?? (MethodBase?)constructorInfo;
_ = methodBase ?? throw new TowelBugException($"{nameof(GetDocumentation)} {nameof(methodInfo)} is null && {nameof(constructorInfo)} is null");
_ = methodBase.DeclaringType ?? throw new ArgumentException($"{nameof(methodBase)}.{nameof(Type.DeclaringType)} is null");
Expand Down
157 changes: 157 additions & 0 deletions Tools/Towel_Testing/Meta.cs
Expand Up @@ -96,6 +96,142 @@ namespace Towel_Testing

[TestMethod] public void MethodInfo_GetDocumentation()
{
#region GitHub Incident 52

try
{
MethodInfo methodInfo = typeof(XmlDocumentationFromMethod.GitHubIncident52Class<int>).GetMethod(nameof(XmlDocumentationFromMethod.GitHubIncident52Class<int>.GitHubIncident52Method))!;
string? xmlDocumentation = methodInfo.GetDocumentation();
Assert.IsTrue(!string.IsNullOrWhiteSpace(xmlDocumentation));
string? xmlDocumentationMember = ((MemberInfo)methodInfo).GetDocumentation();
Assert.IsTrue(xmlDocumentation == xmlDocumentationMember);
}
catch
{
Debugger.Break();
MethodInfo methodInfo = typeof(XmlDocumentationFromMethod.GitHubIncident52Class<int>).GetMethod(nameof(XmlDocumentationFromMethod.GitHubIncident52Class<int>.GitHubIncident52Method))!;
string? xmlDocumentation = methodInfo.GetDocumentation();
Assert.IsTrue(!string.IsNullOrWhiteSpace(xmlDocumentation));
string? xmlDocumentationMember = ((MemberInfo)methodInfo).GetDocumentation();
Assert.IsTrue(xmlDocumentation == xmlDocumentationMember);
}

try
{
MethodInfo methodInfo = typeof(XmlDocumentationFromMethod.GitHubIncident52Class<int>).GetMethod(nameof(XmlDocumentationFromMethod.GitHubIncident52Class<int>.GitHubIncident52Method2))!;
string? xmlDocumentation = methodInfo.GetDocumentation();
Assert.IsTrue(xmlDocumentation is null);
string? xmlDocumentationMember = ((MemberInfo)methodInfo).GetDocumentation();
Assert.IsTrue(xmlDocumentation == xmlDocumentationMember);
}
catch
{
Debugger.Break();
MethodInfo methodInfo = typeof(XmlDocumentationFromMethod.GitHubIncident52Class<int>).GetMethod(nameof(XmlDocumentationFromMethod.GitHubIncident52Class<int>.GitHubIncident52Method2))!;
string? xmlDocumentation = methodInfo.GetDocumentation();
Assert.IsTrue(xmlDocumentation is null);
string? xmlDocumentationMember = ((MemberInfo)methodInfo).GetDocumentation();
Assert.IsTrue(xmlDocumentation == xmlDocumentationMember);
}

try
{
MethodInfo methodInfo = typeof(XmlDocumentationFromMethod.GitHubIncident52Class<int>).GetMethod(nameof(XmlDocumentationFromMethod.GitHubIncident52Class<int>.GitHubIncident52Method3))!;
string? xmlDocumentation = methodInfo.GetDocumentation();
Assert.IsTrue(!string.IsNullOrWhiteSpace(xmlDocumentation));
string? xmlDocumentationMember = ((MemberInfo)methodInfo).GetDocumentation();
Assert.IsTrue(xmlDocumentation == xmlDocumentationMember);
}
catch
{
Debugger.Break();
MethodInfo methodInfo = typeof(XmlDocumentationFromMethod.GitHubIncident52Class<int>).GetMethod(nameof(XmlDocumentationFromMethod.GitHubIncident52Class<int>.GitHubIncident52Method3))!;
string? xmlDocumentation = methodInfo.GetDocumentation();
Assert.IsTrue(!string.IsNullOrWhiteSpace(xmlDocumentation));
string? xmlDocumentationMember = ((MemberInfo)methodInfo).GetDocumentation();
Assert.IsTrue(xmlDocumentation == xmlDocumentationMember);
}

try
{
MethodInfo methodInfo = typeof(XmlDocumentationFromMethod.GitHubIncident52Class<int>).GetMethod(nameof(XmlDocumentationFromMethod.GitHubIncident52Class<int>.GitHubIncident52Method4))!;
string? xmlDocumentation = methodInfo.GetDocumentation();
Assert.IsTrue(xmlDocumentation is null);
string? xmlDocumentationMember = ((MemberInfo)methodInfo).GetDocumentation();
Assert.IsTrue(xmlDocumentation == xmlDocumentationMember);
}
catch
{
Debugger.Break();
MethodInfo methodInfo = typeof(XmlDocumentationFromMethod.GitHubIncident52Class<int>).GetMethod(nameof(XmlDocumentationFromMethod.GitHubIncident52Class<int>.GitHubIncident52Method4))!;
string? xmlDocumentation = methodInfo.GetDocumentation();
Assert.IsTrue(xmlDocumentation is null);
string? xmlDocumentationMember = ((MemberInfo)methodInfo).GetDocumentation();
Assert.IsTrue(xmlDocumentation == xmlDocumentationMember);
}

try
{
MethodInfo methodInfo = typeof(XmlDocumentationFromMethod.GitHubIncident52Class).GetMethod(nameof(XmlDocumentationFromMethod.GitHubIncident52Class.GitHubIncident52Method1))!;
string? xmlDocumentation = methodInfo.GetDocumentation();
Assert.IsTrue(!string.IsNullOrWhiteSpace(xmlDocumentation));
string? xmlDocumentationMember = ((MemberInfo)methodInfo).GetDocumentation();
Assert.IsTrue(xmlDocumentation == xmlDocumentationMember);
}
catch
{
Debugger.Break();
MethodInfo methodInfo = typeof(XmlDocumentationFromMethod.GitHubIncident52Class).GetMethod(nameof(XmlDocumentationFromMethod.GitHubIncident52Class.GitHubIncident52Method1))!;
string? xmlDocumentation = methodInfo.GetDocumentation();
Assert.IsTrue(!string.IsNullOrWhiteSpace(xmlDocumentation));
string? xmlDocumentationMember = ((MemberInfo)methodInfo).GetDocumentation();
Assert.IsTrue(xmlDocumentation == xmlDocumentationMember);
}

try
{
MethodInfo methodInfo = typeof(XmlDocumentationFromMethod.GitHubIncident52Class).GetMethod(nameof(XmlDocumentationFromMethod.GitHubIncident52Class.GitHubIncident52Method2))!;
string? xmlDocumentation = methodInfo.GetDocumentation();
Assert.IsTrue(xmlDocumentation is null);
string? xmlDocumentationMember = ((MemberInfo)methodInfo).GetDocumentation();
Assert.IsTrue(xmlDocumentation == xmlDocumentationMember);
}
catch
{
Debugger.Break();
MethodInfo methodInfo = typeof(XmlDocumentationFromMethod.GitHubIncident52Class).GetMethod(nameof(XmlDocumentationFromMethod.GitHubIncident52Class.GitHubIncident52Method2))!;
string? xmlDocumentation = methodInfo.GetDocumentation();
Assert.IsTrue(xmlDocumentation is null);
string? xmlDocumentationMember = ((MemberInfo)methodInfo).GetDocumentation();
Assert.IsTrue(xmlDocumentation == xmlDocumentationMember);
}

#endregion

#region Delegate

try
{
Action<int> action = new XmlDocumentationFromMethod.GitHubIncident52Class<int>().GitHubIncident52Method;
MethodInfo methodInfo = action.Method;
string? xmlDocumentation = methodInfo.GetDocumentation();
Assert.IsTrue(!string.IsNullOrWhiteSpace(xmlDocumentation));
string? xmlDocumentationMember = ((MemberInfo)methodInfo).GetDocumentation();
Assert.IsTrue(xmlDocumentation == xmlDocumentationMember);
}
catch
{
Debugger.Break();
Action<int> action = new XmlDocumentationFromMethod.GitHubIncident52Class<int>().GitHubIncident52Method;
MethodInfo methodInfo = action.Method;
string? xmlDocumentation = methodInfo.GetDocumentation();
Assert.IsTrue(!string.IsNullOrWhiteSpace(xmlDocumentation));
string? xmlDocumentationMember = ((MemberInfo)methodInfo).GetDocumentation();
Assert.IsTrue(xmlDocumentation == xmlDocumentationMember);
}

#endregion

foreach (MethodInfo methodInfo in Assembly.GetExecutingAssembly().GetMethodInfosWithAttribute<XmlDocumentationFromMethodAttribute>())
{
try
Expand Down Expand Up @@ -357,6 +493,27 @@ public class XmlDocumentationFromMethodAttribute : Attribute { }

public class XmlDocumentationFromMethod
{
public class GitHubIncident52Class<T1>
{
/// <summary>hello world</summary>
public void GitHubIncident52Method(T1 x) { }

public void GitHubIncident52Method2(T1 x) { }

/// <summary>hello world</summary>
public void GitHubIncident52Method3<T2>(T1 a, T2 b) { }

public void GitHubIncident52Method4<T2>(T1 a, T2 b) { }
}

public class GitHubIncident52Class
{
/// <summary>hello world</summary>
public void GitHubIncident52Method1<T2>(T2 b) { }

public void GitHubIncident52Method2<T2>(T2 b) { }
}

/// <summary>Test A</summary>
/// <returns>object</returns>
[XmlDocumentationFromMethod]
Expand Down

0 comments on commit afddb2f

Please sign in to comment.