本文介绍了T4 code世代:在当前项目中访问类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用T4 code一代,是有可能访问在当前项目中定义的类型?

Using T4 code generation, is it possible to access the types defined in the current project?

例如,如果我有一个接口,我想它的实现委托给另一个类,即

For example, if I have an interface and I want to delegate its implementation to another class, i.e.

interface IDoSomething {
    public void do_something();
}

class DoSomethingImpl : IDoSomething {
    public void do_something() {
        // implementation...
    }
}

class SomeClass : IDoSomething {
    IDoSomething m_doSomething = new DoSomethingImpl();

    // forward calls to impl object
    public void do_something() {
        m_doSomething.do_something();
    }
}

我想自动化呼叫转移的 SomeClass的与code产生;这可能吗?

I would like to automate the call-forwarding in SomeClass with code generation; is this possible?

推荐答案

我会建议使用codeModel。下面是一个example.远离反射,T4将锁定编译的二进制文件。如果codeModel不适合工作,你正在做什么,试着反省(example).

I would recommend using CodeModel. Here is an example. Stay away from Reflection, T4 will lock the compiled binaries. If CodeModel doesn't work for what you are trying to do, try Introspection (example).

这篇关于T4 code世代:在当前项目中访问类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:07