Dynamically invoke properties by string name using VB.NET

前端 未结 3 579
北海茫月
北海茫月 2020-12-28 14:30

I\'m currently working on a project where a section of the code looks like this:

Select Case oReader.Name
    Case \"NameExample1\"
        Me.Elements.NameE         


        
3条回答
  •  臣服心动
    2020-12-28 15:14

    Yes, CallByName is the best solution for you. Here's instruction of doing it:

    CallByName(yourClassOrObjectName,"NameExample1",CallType.Set,oReader.ReadString)
    

    You can write "NameExample" in place of "NameExample1".
    Mention, that third parameter lets you 'Get', 'Let' that parameter (and even invoke any method).
    So you can get your parameter's value using CallType.Get.

提交回复
热议问题