Late Binding Magic under VB.NET Converted to C #

I need to convert code from VB to C #. Given the following lines of VB (I think only because the option is not set to strict):

Dim someProp As SomeType Try someProp = CType(SomeInstance, Object).SomeProp ' ... 

Due to late binding, this code is possible under VB. Of course, the following will not work under C #:

 SomeType someProp; try { someProp = ((object)SomeInstance).SomeProp; // ... 

How can I formulate something like this in C #?

thanks for any tips sl3dg3

+4
source share
1 answer

If you are using C # 4.0:

 SomeType someProp; try { someProp = ((dynamic)SomeInstance).SomeProp; // ... 
+6
source

Source: https://habr.com/ru/post/1382459/


All Articles