473,378 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Reflecting a property type for IList

Hi,

is it possible to determine if the PropertyType of a property support IList?

We are inspecting all properties of a Type and we need to care about the
properties which have a type which supports IList. I tried to do the
following:

public void TestPropertiesOfType()
{
System.Type t = typeof (MyClass);
PropertyInfo[] properties = t.GetProperties();
foreach (PropertyInfo pi in properties)
{
if (pi.PropertyType is IList)
Console.WriteLine("Property {0} supports IList", pi.Name);
}
}

public class MyClass
{
public ArrayList MyArrayList
{
get { return _al; }
set { _al = value; }
}
}

ArrayList does support IList, but how can I find this one out? I know that
the above implmentation is incorrect because the Type returned by
pi.PropertyType itself does not support IList.

Any help is appreciated!

Regards,
Michael
Nov 16 '05 #1
2 6599
Try:

System.Type t = typeof (MyClass);
PropertyInfo[] properties = t.GetProperties();
Type type;

type = typeof(IList);

foreach (PropertyInfo pi in properties)
{
if (pi.PropertyType.GetInterface(type.Name) != null)
MessageBox.Show("Property {0} supports IList", pi.Name);
}

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
"Michael Groeger" <go*********@web.de> escribió en el mensaje
news:Oz*************@TK2MSFTNGP15.phx.gbl...
Hi,

is it possible to determine if the PropertyType of a property support
IList?

We are inspecting all properties of a Type and we need to care about the
properties which have a type which supports IList. I tried to do the
following:

public void TestPropertiesOfType()
{
System.Type t = typeof (MyClass);
PropertyInfo[] properties = t.GetProperties();
foreach (PropertyInfo pi in properties)
{
if (pi.PropertyType is IList)
Console.WriteLine("Property {0} supports IList", pi.Name);
}
}

public class MyClass
{
public ArrayList MyArrayList
{
get { return _al; }
set { _al = value; }
}
}

ArrayList does support IList, but how can I find this one out? I know that
the above implmentation is incorrect because the Type returned by
pi.PropertyType itself does not support IList.

Any help is appreciated!

Regards,
Michael

Nov 16 '05 #2
Carlos,

thanks for your reply. Great, it works !

Regards,
Michael

"Carlos J. Quintero [.NET MVP]" <ca*****@NOSPAMsogecable.com> schrieb im
Newsbeitrag news:#5**************@tk2msftngp13.phx.gbl...
Try:

System.Type t = typeof (MyClass);
PropertyInfo[] properties = t.GetProperties();
Type type;

type = typeof(IList);

foreach (PropertyInfo pi in properties)
{
if (pi.PropertyType.GetInterface(type.Name) != null)
MessageBox.Show("Property {0} supports IList", pi.Name);
}

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
"Michael Groeger" <go*********@web.de> escribió en el mensaje
news:Oz*************@TK2MSFTNGP15.phx.gbl...
Hi,

is it possible to determine if the PropertyType of a property support
IList?

We are inspecting all properties of a Type and we need to care about the
properties which have a type which supports IList. I tried to do the
following:

public void TestPropertiesOfType()
{
System.Type t = typeof (MyClass);
PropertyInfo[] properties = t.GetProperties();
foreach (PropertyInfo pi in properties)
{
if (pi.PropertyType is IList)
Console.WriteLine("Property {0} supports IList", pi.Name);
}
}

public class MyClass
{
public ArrayList MyArrayList
{
get { return _al; }
set { _al = value; }
}
}

ArrayList does support IList, but how can I find this one out? I know that the above implmentation is incorrect because the Type returned by
pi.PropertyType itself does not support IList.

Any help is appreciated!

Regards,
Michael


Nov 16 '05 #3

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

Similar topics

8
by: critter | last post by:
I am trying to get a value of a property of a class, but not an instance of the class. Using Reflection, I can find the class in my assembly, and I can find the property of my class, however, I...
2
by: rajivpopat | last post by:
I've been reading a discussion thread at http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_frm/thread/119f8362a9f5ff52 regarding typecasting generic collections to...
4
by: MattBell | last post by:
I've tried to search for an answer to this without much success, and I think it's probably a common thing to do: I have a web service I want to accept an XmlDocument as an argument which conforms...
3
by: | last post by:
Hi all, I have a question on reflection Lets say I have a custom object called Address. Now, lets say I have a string variable that holds the name of a variable in the object such as...
1
by: Marek | last post by:
Hi I have a user control that has a property which is a class implementing IList: public partial class MultiPanelControl : UserControl { protected MultiPanelList _panels = new MultiPanelList();...
1
by: suki | last post by:
How can i set the data binding property of an label to a field of a dataset (defined in a class in my project) ? In this data field, there are many entries and i want to have as much labels as...
1
by: tomjbr.32022025 | last post by:
I have started looking at the nhibernate framework, but do not really like the string based API which makes it impossible to use automatic refactoring of a property name without the risk of getting...
7
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...
2
by: SimonDotException | last post by:
I am trying to use reflection in a property of a base type to inspect the properties of an instance of a type which is derived from that base type, when the properties can themselves be instances of...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.