473,473 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Calling an Indexer from a generic object

Hello,

I am able to test an object to see if it is an indexer (IsIndexer
function), however I don't know how to call the indexer without Unboxing
to the object's class.

Do I need to use reflection to use the indexer property, or is there
some sort of casting that I can do?
I would like to do something like this.

if(IsIndexer(o) == true) {
MessageBox.Show((Indexer)o)[1].ToString());
}
else {
// Nothing
}

public static bool IsIndexer(object o) {
Type t = o.GetType();

foreach(PropertyInfo propInfo in t.GetProperties()) {
ParameterInfo[] parameters = propInfo.GetIndexParameters();
if(parameters.Length > 0) {
return true;
}
}
return false;
}

Nov 15 '05 #1
0 1502

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

Similar topics

14
by: Nikhil Patel | last post by:
Hi all, Is it possible to have more than one indexer in a class. If not, are there any good alternative ways to achieve similar functionality. Thanks... -Nikhil
16
by: Yoramo | last post by:
Hello I have a class the containes several ArrayList's and I whold like to use a indexer for each one. I'm getting a compilation error. "already defines a member called 'this' with the same...
3
by: Sam Martin | last post by:
Basically, i've got a class called RegularExpressions which contains a private Hashtable of RegExps used in my apps. I obviously don't want to give full public access to the Hashtable, so I'd...
3
by: Nash Alexx | last post by:
Hello! I am quite new to C#, and one concept that really gives me a headache is "indexer". I have gone through the MSDN examples, and, at some level know how to use indexers. But, the thing is I...
17
by: SemSem | last post by:
i want to know waht is an index and how we use it with a simple example including the main of the program . thanx -- Islam Khalil,
19
by: Brett Romero | last post by:
Here's a table of data I'm putting into a collection: CodeId CodeGroup CodeSubGroup Type 1 K K.1 Shar1 2 K ...
2
by: hufaunder | last post by:
SITUATION: I have a class "MainClass" that has an indexer "SubClass1Indexer". This indexer returns an instance that implements a particular interface "ISubClass1". This interface defines another...
2
by: D2 | last post by:
Hi, I have a requirement where I need to call a generic method without knowing the class name i.e. I'm getting class name from xml file. Given below is a replica of the scenario we are having. ...
6
by: christian2.schmidt | last post by:
Hi, why does the first Console::Write give error "indexer needs array or pointer" and the second not? generic <typename TList, typename ItemTypewhere TList : IList<ItemType> ref class MyClass...
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,...
0
jinu1996
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
1
isladogs
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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...

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.