Skip to content
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

修复 特性获取 与 绑定泛型参数错误 #630

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
方法特性 获取
  • Loading branch information
aghci committed Dec 20, 2021
commit cce351d0be2df453df13bc205ea4deb4a61c78e4
5 changes: 4 additions & 1 deletion ILRuntime/Reflection/ILRuntimeMethodInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ public override object[] GetCustomAttributes(Type attributeType, bool inherit)
List<object> res = new List<object>();
for (int i = 0; i < customAttributes.Length; i++)
{
if (attributeTypes[i].Equals(attributeType))
if (attributeTypes[i].Equals(attributeType)||attributeType.IsAssignableFrom ( attributeTypes[i] ))
res.Add(customAttributes[i]);
}
return res.ToArray();
}
public Object GetCustomAttribute ( Type oType, Boolean inherit ) => this.GetCustomAttributes ( oType, inherit ).FirstOrDefault ();
public T GetCustomAttribute<T> ( Boolean inherit ) where T : System.Attribute => this.GetCustomAttributes<T> ( inherit ).FirstOrDefault ();
public T [] GetCustomAttributes<T> ( Boolean inherit ) where T : System.Attribute => this.GetCustomAttributes ( typeof ( T ), inherit ).Select ( t => ( T ) t ).ToArray ();

public override MethodImplAttributes GetMethodImplementationFlags()
{
Expand Down