在运行时动态添加新方法和属性

时间:2012-02-16 05:13:52

标签: c# xml dynamic expando

XML:<class> <method>a1</method> <class>

C#:

Class Demo 
    { 
      public string a1 { get; set;}  
      public void a1() 
      { 
        ----- 
      } 
    }
    class test 
    {  
     public static void main(string args[])
     { 
      Demo d = new Demo(); 
      d.a1();
     }
    }

编译C#,它将作为另一个程序的参考。

如果我在a2之后添加新的XML方法,例如a1,我可以使用dynamic和expandos在运行时获取此方法。如果可能的话,请告诉我该怎么做。

另外,可以根据XML文件在运行时动态创建该方法。例如,如果d.a1()包含<method>c1</method>,那么它将显示来自Intellisense的d.c1()

1 个答案:

答案 0 :(得分:0)

您最好使用动态库并在运行时引用它们。见Can I load a .NET assembly at runtime and instantiate a type knowing only the name?

相关问题