473,804 Members | 3,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PropertyInfo.Pr opertyType is never ValueType?

PropertyInfo[] props = obj.GetType().G etProperties();
foreach (PropertyInfo p in props)
if (p.PropertyType is ValueType)
this._commonPro perties.Add(p.N ame, p.GetValue(requ est,
null).ToString( ));

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

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

PropertyInfo.Pr opertyType returns "System.Typ e", so you are actually
querying whether or not "System.Typ e" 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().G etProperties();
foreach (PropertyInfo p in props)
if (p.PropertyType is ValueType)
this._commonPro perties.Add(p.N ame, p.GetValue(requ est,
null).ToString( ));

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

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

Jan 12 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7223
by: Tony Tullemans | last post by:
I am trying to write a subroutine that will examine all the properties of a form to determine which of those are SqlCommand objects, and then set the Connection property of those SqlCommands to a passed-in SqlCommand object. I can find the properties OK but am unsuccessful in trying to change their value due to the way I have identified those SqlCommand objects (as a PropertyInfo). Can anyone give me a hint (or suggest a better way) as...
4
10103
by: Brian Brane | last post by:
I have properties that wrap DataRow columns as in: public int aNumber { get{ return m_DataRow; } set{ m_DataRow = value; } } If the column happens to contain DBNull, I get a cast exception since DBNull cannot be converted to int. I wrote the following method that looks up the column's data type and if it is a ValueType, returns the default value for the ValueType.
15
8244
by: Charles Law | last post by:
I have adapted the following code from the MSDN help for PropertyInfo SetValue. In the original code, the structure MyStructure is defined as a class MyProperty, and it works as expected. There is also a minor change in class Mypropertyinfo, which I have commented out. When using a structure, however, the second call to GetValue returns "Default caption". Can anyone tell me why, and how I can make this work? <code> Imports System
1
3965
by: Paul | last post by:
This part is easy: Dim oControl As Control oControl = Me.Page.FindControl("TextBox1") Dim oPropertyInfo As PropertyInfo oPropertyInfo = oControl.GetType.GetProperty("Text") oPropertyInfo.SetValue(oControl, "Some New Text", Nothing)
0
7186
by: SyZLaB | last post by:
I had a problem using system.reflection.propertyinfo.getvalue in vb - and searched a lots of newsgroups and libraries - but none had the solution to my problem - and it also seamed like many others had the same problem: system.reflection.propertyinfo.getValue fails with "Object does not match target type." As many of the posts where to old to answer, here's the "solution" : The obj parameter is the object from where propertyinfo gets the...
0
1427
by: tatilou | last post by:
Hello, I need add new method to my properties. these methods should give me some attributes coming from my database. I think, to create a class with implement PropertyInfo but I don't know how To call my custom class. My code like this : public abstract class Class2 : PropertyInfo //, RuntimePropertyInfo
3
4387
by: Steve Richter | last post by:
when enumerating thru the properties of a type, how do I select only the properties of the derived class? In the example below, the AddrBookPrompt class is derived from the Form class. When I enumerate the properties I get all the properties of the base class + the properties of my derived class. thanks, AddrBookPrompt abPmt = new AddrBookPrompt();
7
16574
by: Tom Dacon | last post by:
I'm using Reflection to iterate over the properties and fields of an arbitrary object. For non-indexed properties it's pi.GetValue(theObject, Nothing) for VB, or pi.GetValue(theObject, null) for C# For indexed properties, instead of Nothing (null) you pass an array of index values. OK, no problem so far.
7
1697
by: colin | last post by:
Hi, Im a bit confused about when you cast a value type to an object. I have a property grid wich stores the data and the defualt as objects. the data is limited to primitive types, structs and strings. the structs only have primitive types. however once ive set the data to the defualt, if the data is a struct then any edits change the defualt data as well
0
9710
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9589
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10593
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10329
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9163
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3830
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3000
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.