作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不了解具有通用参数的成员的 Module.ResolveMember 行为。根据下面的文档代码应该可以工作,但是 fooMember.DeclaringType 出于某种原因没有用 bool 类型参数化。
class A<T> where T:new()
{
T a;
public void foo()
{
a = new T();
}
}
class B:A<bool>
{ }
class Program
{
static void Main(string[] args)
{
var test = new B();
var aType = test.GetType().BaseType;
var token = aType.GetMember("foo").First().MetadataToken;
var fooMember = aType.Module.ResolveMember(token, aType.GetGenericArguments(), null);
Debug.Assert(aType == fooMember.DeclaringType);
Console.ReadKey();
}
}
为什么这行不通?
最佳答案
原来 ResolveMethod(Int32, Type[], Type[])
需要 methodref 标记,对于泛型方法,我们有不同的 methodrefs 用于不同的泛型参数。 ResolveMethod
应该用于获取基于编译相关信息的方法,而不是解析泛型方法信息。
关于c# - 泛型类的 Module.ResolveMember 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52477986/
我不了解具有通用参数的成员的 Module.ResolveMember 行为。根据下面的文档代码应该可以工作,但是 fooMember.DeclaringType 出于某种原因没有用 bool 类型参
我是一名优秀的程序员,十分优秀!