C# Indexer Reflection

How to reflect an indexer without knowing the indexes of an object?

Page 1 of 1

1 Replies - 6799 Views - Last Post: 29 September 2009 - 08:56 AM Rate Topic: -----

#1 abdulb   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-September 09

C# Indexer Reflection

Posted 29 September 2009 - 04:50 AM

How to reflect an indexer without knowing the indexes of an object?

Class sample
{
  private Dictionary<string,string> Indexer = new Dictionary<string,string>();
  public string this[string s]
  {
	get
   {
	   reurn Indexer[s];
   }
   set
   { Indexer.Add(s,value); }
  }
}

Class FillSample
{

   Sample oSample = new Sample();

   public object Fill()
   {
	   oSample[key1] = "value1";
	   return oSample;
   }
}

class Reflector
{
	 FillSample oFill = new FillSample();
	object obj =  oFill.Fill();

	foreach(PropertyInfo oInfo in obj.GetProperties())
	{
	   if(oInfo.GetIndexParameters().Length > 1 && !oInfo.IsArray)
	  {
			 //I want to reflect the indexer here without knowing the indexes here
	   }
	}
}


This post has been edited by abdulb: 30 September 2009 - 12:56 AM


Is This A Good Question/Topic? 0
  • +

Replies To: C# Indexer Reflection

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1660
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: C# Indexer Reflection

Posted 29 September 2009 - 08:56 AM

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: :code:

Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1