471,350 Members | 1,127 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

PropertyInfo.PropertyType is never ValueType?

PropertyInfo[] props = obj.GetType().GetProperties();
foreach (PropertyInfo p in props)
if (p.PropertyType is ValueType)
this._commonProperties.Add(p.Name, p.GetValue(request,
null).ToString());

I get a warning that says p.PropertyType will never be ValueType....and it
was right.
After stepping through it the types are "System.Boolean" etc...
I want to add all integer, string, and boolean types to NameValueCollection,
but not objects.

I thought System.Boolean was a ValueType?
How should I test for this?
Jan 12 '06 #1
1 5706
INeedADip,

PropertyInfo.PropertyType returns "System.Type", so you are actually
querying whether or not "System.Type" is a value-type, and since the compiler
knows it's not and will never be, you get a warning.

You should rewrite as follows:
if (p.PropertyType.IsValueType)
{
...
}

HTH,
Baileys

"INeedADip" wrote:
PropertyInfo[] props = obj.GetType().GetProperties();
foreach (PropertyInfo p in props)
if (p.PropertyType is ValueType)
this._commonProperties.Add(p.Name, p.GetValue(request,
null).ToString());

I get a warning that says p.PropertyType will never be ValueType....and it
was right.
After stepping through it the types are "System.Boolean" etc...
I want to add all integer, string, and boolean types to NameValueCollection,
but not objects.

I thought System.Boolean was a ValueType?
How should I test for this?

Jan 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Tony Tullemans | last post: by
1 post views Thread by Paul | last post: by
reply views Thread by SyZLaB | last post: by
reply views Thread by tatilou | last post: by
7 posts views Thread by colin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.