vb.net类/反射的动态名称

时间:2018-01-10 13:02:28

标签: vb.net object methods dynamic attributes

我想使用我从其他地方获得的配置来选择一个动态实例化的类,然后选择动态选择获取FoodItem的方法。

我们假设我们有以下课程:

Class Orange
    inherits treefruits ( which inhertis tree -> which inherits basicLife)
    color as string
    shadeOfOrange as string

    function eat
    function pickAndPeel as FoodItem

END Class

Class Potatoe
   inherits vegetables ( which inhertis plants -> which inherits basicLife)
   color as string
   hasWorm as boolean

   function eat
   function cook as FoodItem
   function chipAndFry as FoodItem -> This is where config wants me to go.
   function makeWedges as FoodItem
End Class

Class frozenPizza
   inherits IndustrialFoods ( which inherits ... which inherits ... which inherits basicLife)
   size as integer
   temperature as integer

   function eat
   function bakeInOven as FoodItem
   function heatInMicrowave as Fooditem
   function grillInSmoker as Fooditem
End Class

configString as String = "Potatoe-chipAndFry"
//Here has to come the Part which instanciates a new potatoe and then runs it's chipAndFry method

如您所见,它们具有相似的功能和属性,但它们并不相同。对于香蕉,苹果等也是如此。列表太长而不能用于交换机箱 - 至少它太长而且不易维护。

感谢两条评论我已经了解了反射,我发现了一个例子,它涵盖了方法和类的动态使用,这应该是我需要分离我的配置字符串并开始工作({{3 }})

至于方法,我想我明白了如何获得" ChipAndFry"要运行的配置字符串的一部分。我不知道如何动态地实现课程(我不会从维基百科的例子中获得" complete.classpath.and.Foo")那就是我的意思我明天正在工作。

0 个答案:

没有答案