我需要使用实现以下接口(interface)的 Reflection.Emit 生成一个类。
public interface IObject
{
T Get<T>(string propertyName);
}
有没有人举例说明我将如何发出以下内容作为简单的测试用例?
class GeneratedObject : IObject
{
public T Get<T>(string propertyName)
{
// this is the simplest possible implementation
return default(T);
}
}
最佳答案
如果您正在使用 Reflection.Emit,您真的应该获取 Reflection.Emit language add-in 的副本对于 Reflector .虽然不完美,但它应该至少让您完成任何给定发出代码的 95%。
关于c# - 使用 Reflection.Emit 创建一个实现接口(interface)的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1651455/