有没有办法在使用 Relection.Emit 动态创建的类上使用扩展方法?例如:
class somewhere
{
somewhere()
{
// define the type here using ReflectionEmit, etc.
Type tableType = CreateTableType(...table parameters...);
var table = Activator.CreateInstance(tableType);
table.Shuffle();
}
}
//... elsewhere
public class static TableTypeExtensions
{
public static Table Shuffle( this Table t)
{
...
}
}
但我没有名为“Table”的类,只有 Type tableType 可用。
有什么解决办法吗?
谢谢
最佳答案
使动态类实现一个接口(interface)(如果需要,可以是一个空接口(interface)),向接口(interface)添加扩展。
关于c# - 将扩展方法与运行时程序集一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3730866/