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? 1 5952
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? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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.
|
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
|
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)
|
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...
| |
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
|
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();
|
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.
|
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
|
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...
|
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,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |