.net 使用反射生成多个方法
我想知道如何使用反射生成多类型方法。 例如:.net 使用反射生成多个方法,.net,reflection.emit,.net,Reflection.emit,我想知道如何使用反射生成多类型方法。 例如: class A() { public void CoreMethod1() { } public void CoreMethod2() { } // .. 20 such core methods public void Method1() { //some initializations //call to CoreMethod1(); } public void Method2() { //som
class A() {
public void CoreMethod1() {
}
public void CoreMethod2() {
}
// .. 20 such core methods
public void Method1() {
//some initializations
//call to CoreMethod1();
}
public void Method2() {
//some initializations
//call to CoreMethod2();
}
// i need 20 such methods which will call their respective CoreMethods
//Method1(),Method2() are similar except for their call to the core method. i.e Every respective method will call its coremethod. Ex : Method1() -> CoreMethod1(), Method2() -> CoreMethod2()
}
我的问题是,我可以生成Method1(),Method2(),Method3()。。动态地调用各自的核心方法。是否有更好的方法来完成此任务?使用T4模板编写一个简单的代码生成器。这里有一些很好的资源
- 汽车制造商
- 临福
- 后夏普
Reflection.Emit
。这可能是做这件事最详细的来源