views:

99

answers:

1

The Type.MakeByRefType method in .NET returns a by-ref version of a type, e.g. passing the type of System.Int32 returns a type representing System.Int32&.

However, if you already have a System.Int32&, what is the mechanism for obtaining a plain old System.Int32? There doesn't seem to be an opposite method to remove the by-ref modifier.

At the moment I've put a hack in place which re-builds the assembly-qualified name without an & at the end of the type name and then loads that type, but this is horribly dirty...

+4  A: 

According to the docs for IsByRef, you can use Type.GetElementType. I don't have time to try this at the minute though...

Jon Skeet
+1 I just tested and it worked.
Andrew Hare
Yep that seems to do the trick, cheers! I feel a bit dumb seeing as it was in the docs for a related attribute... but never mind.
Greg Beech