How to find if a parameter is struct?

230 views
Skip to first unread message

deedee

unread,
Jan 6, 2012, 10:57:31 AM1/6/12
to mono-cecil
Hi,

I have been trying to determine if a parameter in a methodDefinition
is a struct or not. But it appears to have similar set of properties
as any passed by reference parameter would have.
Any ideas?

Thanks!

Vidisha Ghosh

unread,
Jan 6, 2012, 11:40:02 AM1/6/12
to mono-cecil
The reason I am baffled because the IsValueType returns false for a struct, when I check for "parameterReference.ParameterType.IsValueType".
Am I doing something wrong here?


--
--
mono-cecil



--
Vidisha Ghosh

Jb Evain

unread,
Jan 6, 2012, 12:06:08 PM1/6/12
to mono-...@googlegroups.com
Hi,

On Jan 6, 2012, at 5:40 PM, Vidisha Ghosh wrote:
> The reason I am baffled because the IsValueType returns false for a struct, when I check for "parameterReference.ParameterType.IsValueType".
> Am I doing something wrong here?

This looks weird. Can you send me an assembly which reproduces this ?

As a workaround, you can call .Resolve on the TypeReference to get a TypeDefinition that will have the proper ValueTypeness.

Jb

Vidisha Ghosh

unread,
Jan 6, 2012, 1:19:36 PM1/6/12
to mono-...@googlegroups.com
Hi,
Thanks for the workaround, that works just fine! And I noticed that those methods had the structs passed by ref...so maybe that was the problem!
Thanks again!



--
--
mono-cecil



--
Vidisha Ghosh

Jb Evain

unread,
Jan 6, 2012, 3:53:04 PM1/6/12
to mono-...@googlegroups.com
On Jan 6, 2012, at 7:19 PM, Vidisha Ghosh wrote:
> Thanks for the workaround, that works just fine! And I noticed that those methods had the structs passed by ref...so maybe that was the problem!

Then no, it's not a problem.

The ParameterType will be a ByReferenceType, whose ElementType will be the original Value Type, with .IsValueType returning true.

Reply all
Reply to author
Forward
0 new messages