473,385 Members | 1,798 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,385 software developers and data experts.

Reflection to detemine collection or implement of IEnumerable

I have an app that I have several functions I need to determine if a
given propety is a a type of Collection

It could (and in most cases is) a Generic Collection

It could be , and array , an array list , etc though.

How can I determine if its A collection, or enumerable ?

It would seem to be easiest to determine if the property implements (or
parent) IEnumerable , dosent this make sense ?
BUT
I cannot find a way to determine at any level if a property implements
IEnumerable even.

Any help is greatly appreciated.

Thanks

Chris

Dec 6 '06 #1
1 2846
Ok, so far so good.

Now for example a property I may not know the type like a generic
collection

How can I determine that that given Property implements a given
interface, for example we know that a Generic CCollection implements
IEnumerable, and so does an Array.

These (IEnumerable) are the buggers I need to get my hands on.

Thanks

Chris

Ashen wrote:
If your code is in VB.Net you can use TypeOf to determine what the type is:

Private Sub TypeIt(ByVal MyObj As Object)
If TypeOf MyObj Is Array Then
MessageBox.Show("Array")
ElseIf TypeOf MyObj Is Collection Then
MessageBox.Show("Collection")
ElseIf TypeOf MyObj Is String Then
MessageBox.Show("String")
End If
End Sub

"cw******@gmail.com" wrote:
I have an app that I have several functions I need to determine if a
given propety is a a type of Collection

It could (and in most cases is) a Generic Collection

It could be , and array , an array list , etc though.

How can I determine if its A collection, or enumerable ?

It would seem to be easiest to determine if the property implements (or
parent) IEnumerable , dosent this make sense ?
BUT
I cannot find a way to determine at any level if a property implements
IEnumerable even.

Any help is greatly appreciated.

Thanks

Chris
Dec 6 '06 #2

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

Similar topics

3
by: howard dierking | last post by:
If I understand the Xml Serializer correctly, as it is serializing an object graph, if it comes across a collection object, it puts a tag in for the collection and then tries to serialize all of...
2
by: Robert W. | last post by:
I'm trying to write a utility that will use Reflection to examine any data model I pass it and correctly map out this model into a tree structure. When I say "any" , in fact there will only be 3...
2
by: Marc | last post by:
Given a class 'Invoice' with a property 'public IMyColl<IInvoiceLine> InvoiceLines' where 'IMyColl<T> : IList<T>' i would like to detect by reflection that 'InvoiceLines' is a...
5
by: Eric Goforth | last post by:
Hello, I have a generic subroutine that I pass an object and fieldname as arguments. The subroutine then uses reflection to search for the value of the fieldname. For example: 'Calling...
7
by: Michael Kellogg | last post by:
I created a custom collection based on System.Collections.Specialized.NameObjectCollectionBase. I also implemented two version of the "Item" property and coded them both as Default properties. ...
5
by: David Longnecker | last post by:
I'm working to create a base framework for our organization for web and client-side applications. The framework interfaces with several of our systems and provides the business and data layer...
7
by: =?Utf-8?B?Q29kZVJhem9y?= | last post by:
Can someone explain a few things about collections to me. In C# 2 generics, you can create a collection class by inheriting from System.Collections.ObjectModel.Collection. Using this you can...
8
by: Andrus | last post by:
Code below causes error in class definition line .....Isolator<T>' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'Myapp.Isolator<T>.GetEnumerator()'...
2
by: (2b|!2b)==? | last post by:
I am a relatively new to C#. I want to write a method that returns an 'iterable' collection: TheCollection = MyClass.MethodName(); // Further down, I want to use for .. each ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
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...
0
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,...

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.