我使用反射来获取对象的类型,或者对于此问题,在运行时使用具有实例属性类型的对象,然后我需要将现有变量的类型更改为新找到的类型.这可能吗?例如,下面的代码并没有在内部指示的行工作:
Public Sub DoSomething(x As T, y As T, exp As String)
'This is a instance property on the object of a different type
'i.e. 'T.AnotherType' We need to reflect to find out what type of object
'AnotherType is and work with it
If exp.Split(".").Count Then
Dim tp As Type = Nothing
tp = x.GetType
tp = tp.GetProperty(exp.Split(".").ElementAt(0)).PropertyType()
'Line below works, gets the right type, and now I need both x and y values passed in to be …
Run Code Online (Sandbox Code Playgroud)