c# - 使用 Reflection.Emit 创建一个实现接口(interface)的类

标签 c# .net reflection interface reflection.emit

我需要使用实现以下接口(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/

相关文章:

c# - 在 VS2010 中将实体模型从一个项目复制到另一个项目

.net - DomainService 是否在执行 linq 之前加载所有实体?

java - 将通用事件传递给 Guava EventBus?

java - 在java中一次调用更新不同类型的对象

c# - 获取可空类型的类型定义会破坏不可空类型的代码

c# - 以编程方式更改 ListView 行的背景颜色(wpf)

c# - 如何使用 ITestFilterService 和/或 ITestFilterBuilder 以编程方式为 NUnit 3 创建自定义过滤器

.net - 使用 ILMerge 时无法加载 mscorsn.dll

c# - 从 float 到 double 并返回到 float 的转换不会丢失精度

c# - 如何在 C# 中插入新行时从存储过程获取 autoID