Type of AnyObject

Mladen Radonić

Type of AnyObject

Hi there!

Anyone have a clue what (if) am I doing wrong here - trying to check whether the correct kind of object is the current "In-Work" object:

AnyObject oAny;
oAny = part1.InWorkObject;
HybridBody hybridBody1;
hybridBody1 = hybridBodies1.Item(1);
if ( oAny.GetType().IsInstanceOfType(hybridBody1) ) hybridBody1 = (HybridBody)oAny;

(for instance, I want to intercept the case when the PartBody, as a non-HybridBody object is set as "In-Work")

 

The code runs, but doesn't detect the ab.m. case.

 

Regards, Mladen

Little Cthulhu

RE: Type of AnyObject
(in response to Mladen Radonić)

IsInstanceOf works with .NET types only. What you want is casting:

if (hybridBodies1.Item(1) is HybridBody hybridBody) ...

Mladen Radonić

RE: Type of AnyObject
(in response to Little Cthulhu)

Thanks so much L.C., for prompt and clear response!

The solution principle works, of course, but not to be confusing for any further reader - it is the oAny obj which needed to be inspected for type in this example.