Jump to content

How bad is typecasting .Net references?


Recommended Posts

I'm using a custom .Net api on a current project, and for reasons that are too lengthy to explain I've resorted to using a typecast to change a .Net reference wire from one .Net object type to a different, but similar .Net object type. (Property nodes have similar fields, but in a different order.)

It works okay while smoke testing, but I'm not very comfortable with it at all. I don't know the underlying mechanics of how LV maps property nodes to .Net accessors, leaving me wondering what kinds of failures I'm likely to see. Anyone have insight they'd like to share?

Link to comment

I'm surprised that it even works at all, since the properties are in a different order. I take that to mean LV maps its property nodes in a somewhat intelligent way, but for speed's sake, I hope it's not via reflection... My expectation would be access violations, or corrupted data at the very least. You are both reading and writing?

Link to comment

I take it these objects are unrelated, so you can't do proper dynamic casts via the to more specific primitive?

I don't really know how they are related as I don't have access to the .Net source code. If I were to guess I would say they might be siblings, but they're actually interfaces--not concrete classes--and they may not be in any sort of inheritance hierarchy.

Here's a snippet showing the full property nodes before and after the typecast. Oddly, the SteppedLevelGenerator property node (before typecasting) always returns error 1172 while the FrequencySweepGenerator node (after typecasting) does not.

[Grrr... my premium membership incorrectly expired and I'm over the freebie upload quota. I'll try to upload it once I get my membership sorted out.]

Edited by Daklu
Link to comment

I don't really know how they are related as I don't have access to the .Net source code. If I were to guess I would say they might be siblings, but they're actually interfaces--not concrete classes--and they may not be in any sort of inheritance hierarchy.

You might be able to get information about their relationship without source code. Use IL disassembler (ildasm.exe) that ships with the .NET SDK.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.