设置属性值扩展

时间:2015-05-01 13:01:14

标签: .net reflection extension-methods

我如何编码" SetValue"扩展,允许我像这样设置属性值。我知道如何使用反射来设置值,但我不知道如何创建扩展,所以它可以像这样完成......

Public Class Obj
  Public Property myProp1 As String
  Public Property myProp2 As Integer
End Class

Dim myObj As New Obj

'Here is what I want to do...
myObj("myProp1").SetValue("ABC")
myObj("myProp2").SetValue(42)

'Instead of..
myObj.myProp1 = "ABC"
myObj.myProp2 = 42

谢谢,AD

0 个答案:

没有答案