Expand|Select|Wrap|Line Numbers
- class test
- {
- public double Value
- {
- get;
- set;
- }
- public test(double newVal){
- Value = newVal;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- object a = new test(123.45);
- Type dynType = Type.GetType("ConsoleApplication29.test");
- System.Reflection.PropertyInfo dynProperty = dynType.GetProperty("Value");
- double val = (double)dynProperty.GetValue(a,
- System.Reflection.BindingFlags.GetProperty,
- null,
- null,
- null);
- Console.WriteLine(val);
- Console.ReadLine();
- }
- }
Expand|Select|Wrap|Line Numbers
- Class Test
- Private _Value As Double
- Public Property Value() As Double
- Get
- Return _Value
- End Get
- Set(ByVal value As Double)
- _Value = value
- End Set
- End Property
- Public Sub New(ByVal Value As Double)
- _Value = Value
- End Sub
- End Class
- Sub Main()
- Dim a As Object = New Test(123.45)
- Dim dynType As Type = Type.GetType("ConsoleApplication28.Test2")
- Dim dynProperty As System.Reflection.PropertyInfo = dynType.GetProperty("Value")
- Dim val As Double = dynProperty.GetValue(a, _
- System.Reflection.BindingFlags.GetProperty, _
- Nothing, _
- Nothing, _
- Nothing)
- Console.WriteLine(val)
- Console.ReadLine()
- End Sub
It fails in VB at the line:
Dim dynType As Type = Type.GetType("ConsoleApplication28.Test2")
Which returns nothing to dynType, but in C# it actually returns a type instance!
I'd like not to have to write a C# assembly for the sole purpose of allowing this function in my VB application...
Anyone got any ideas how to work around this?