我試圖從字符串引用公共屬性。這怎麼能在vb.net中完成? 我有存儲在strucParam(i).TxtPropertyName中的「FirstName」的文本值。使用字符串動態引用對象屬性
這是目前我在做什麼:
Dim tmpValue As String
Dim ucAppName As UserControl_appName = CType(Parent.FindControl(strucParam(i).ParentFindControl), UserControl_appName)
tmpValue = ucAppName.FirstName.Text
我怎樣才能在strucParam(我).TxtPropertyName使用該值,這樣我可以從我的代碼中刪除「.FirstName」?謝謝!
我無法使用null。我不得不用Nothing來代替它。運行以下代碼時,出現「對象與目標類型不匹配」錯誤。 FirstName屬性實際上是一個文本框。所以我不需要以某種方式在代碼中引用.Text? tmpFirstName = ucAppName.GetType()。GetProperty(strucParam(i).PropertyName).GetValue(objAppNav,Nothing) – crjunk 2011-01-21 18:12:32