type equality to System.Void

Topics: PE reader, Source Model
Oct 29, 2011 at 9:12 PM

Hi there!

I am very new to CCI so please forgive me.

The Expression


ALWAYS return false. Why? How would you test if the return type of a method is void?

Thank you,


Oct 29, 2011 at 10:14 PM

Type references cannot be compared for equality using Equals. Please use TypeHelper.TypesAreEquivalent. In this particular case you could also just check the type code: methodDefinition.Type.TypeCode == PrimitiveTypeCode.Void.

Oct 29, 2011 at 11:31 PM

wow! thanks!

PrimitiveTypeCode.Void works!


however the other solution doesn't! accidentally i tried exactly the TypesAreEquivalent method in the beginning and just the way you suggested.

it turns out that:

if (!TypeHelper.TypesAreEquivalent(node.MethodDefinition.Type, node.MethodDefinition.Type.PlatformType.SystemVoid))            

works, but

if (!TypeHelper.TypesAreEquivalent(node.MethodDefinition.Type, FHost.PlatformType.SystemVoid))            



is there a difference in between the different PlatformType properties? i thought of ITypeRefernce.PlatformType as a shortcut to Host.PlatformType for if the host isn't at hand.

I have only one host which is created like:

            FHost = new PeReader.DefaultHost();



Oct 29, 2011 at 11:37 PM

If the type is a dummy type, its platform type property will be a dummy instance, which is not the same as the one you'll get from your host.

Oct 29, 2011 at 11:58 PM

well. hm.


but then i would suggest that the way over blabla.Type.PlattformType should not work and the way over the host should always work.

But its the other way around. 

So: if i go over a potential dummy type then i sometimes get an equality fo that type to System.Void, which then shouldn't be a dummy type but system.Void?!

I get never an equality to System.Void when doing it the "safe" way over the host.


confused Sebastian