indexer

How to access a property for each memebr of an indexer using reflection in C# .net 2.0

I have the following method: object GetIndexer() The result of the method is an indexer of the type: SomeCollection<T> Now T can be anything, by I know that each T extends the type Y. I tried casting SomeCollection<Y> result= (SomeCollection<Y>) GetIndexer() It didn't work. What I need to know is how to access a property for ...

How can you bind an Indexed property to a control in WPF

Given an instance of the class ThisClassShouldBeTheDataContext as the Datacontext for the view class ThisClassShouldBeTheDataContext { public Contacts Contacts {get;set;} } class Contacts { public IEnumerable<Person> Persons {get;set;} public Person this[string Name] { get { var p = from i in Persons where i.Name...

How to set enum Type indexer in Spring.NET configuration xml?

I have this code: public enum StateId { NotSet = 0, AL, ..., WY } public class EnumBasedArray<I,V>:IEnumerable<V> { public V this[I index] { get { return _data[index]; } set { _data[index] = value; } } // other code to manage values internally } public class AnotherObject { ... } public class ArrayOfAnotherObjectByS...

What is the relationship between indexers and properties in C#?

Is an indexer an extended version of a property?. ...

C# what is the point or benefit of an indexer?

Doing some code reading and stumbled upon this snippet that I haven't seen before: public SomeClass { public someInterface this[String strParameter] { get { return SomeInternalMethod(strParameter); } } } It looks like it is called as follows: SomeClass _someClass = new SomeClass(); SomeInterface returnedValue = _som...

C# .Net 3.5 Using Overloaded Indexers with different return types

I have a parent class which is essentially a glorified list. It's extended by several subclasses for various functionalities. public class HierarchialItemList<ItemType> : IEnumerable<ItemType> { public ItemType this[String itemCode] { get { foreach (IHierarchialItem curItem in...

Real world use cases for C# indexers ?

I've seen lot of examples for c# Indexers, but in what way will it help me in real life situations. I know the C# guru wouldn't have added this if it wasn't a serious feature, but i cant think of a real world situation (not the foo bar stuff) to use indexers. Note:I realize a related question exists, but it doesn't help me much. Thank...

Creating a setter method that takes extra arguments in Ruby

I'm trying to write a method that acts as a setter and takes some extra arguments besides the assigned value. Silly example: class WordGenerator def []=(letter, position, allowed) puts "#{letter}#{allowed ? ' now' : ' no longer'} allowed at #{position}" end def allow=(letter, position, allowed) # ... end end Writing i...

Lucene: Wildcards are missing from index

Hi - i am building a search index that contains special names - containing ! and ? and & and + and ... I have to tread the following searches different: me & you me + you But whatever i do (did try with queryparser escaping before indexing, escaped it manually, tried different indexers...) - if i check the search index with Luke they ...

Returning IEnumerable from an indexer, bad practice?

If I had a CarsDataStore representing a table something like: Cars -------------- Ford | Fiesta Ford | Escort Ford | Orion Fiat | Uno Fiat | Panda Then I could do IEnumerable<Cars> fords = CarsDataStore["Ford"]; Is this a bad idea? It's inconsistent with the other datastore objects in my api (which all have a single column PK index...

using indexer to retrieve Linq to SQL object from datastore

class UserDatastore : IUserDatastore { ... public IUser this[Guid userId] { get { User user = (from u in _dataContext.Users where u.Id == userId select u).FirstOrDefault(); return user; } } ... } One of the d...

Using Moq to set indexers in C#

I'm having trouble figuring out how to set indexers in C# with Moq. The Moq documentation is weak, and I've done a lot of searching... what I'd like to do is similar in the solution to How to Moq Setting an Indexed property: var someClass = new Mock<ISomeClass>(); someClass.SetupSet(o => o.SomeIndexedProperty[3] = 25); I want to modif...

How can I apply indexer to Dictionary.Values (C# 3.0)

I have done a program string[] arrExposureValues = stock.ExposureCollection[dt].Values.ToArray(); for(int i = 0; i < arrExposureValues.Length; i++) Console.WriteLine(arrExposureValues[i]); Nothing wrong and works fine. But is it possible to do something like the below for(int i = 0; i < stock.ExposureCollection[dt].Count; i++)...

CSharp Parameterized Property class implemented via Generics?

I would like to build a generic class that I can use to implement Parameterized Properties in C#. The basic code I want is this: public class ParameterizedProperty<typeReturn, typeIndexer> { private typeReturn oReturn = default(typeReturn); public typeReturn this[typeIndexer oIndexer] { get { return oReturn[oIndexer]; }...

How to use indexers with Extension Methods having out parameter and function calls

Is it possible to use indexers with extension methods. eg. Consider it as an example only. public static object SelectedValue(this DataGridView dgv, string ColumnName) { return dgv.SelectedRows[0].Cells[ColumnName].Value; } EDIT usage mygrid.SelectedValue("mycol") How to use it as an indexer mygrid....

Syntax to bind to the current dataitem's default indexer in WPF?

I have a Listbox with an itemssource set to an ObservableCollection of DataRow. Let's say each DataRow has 5 columns for this example. In the DataTemplate of the ListBox I have 5 textblocks (1 for each column). My question is how can I bind to an indexer of the row to get the columns value? Here is my attempt but nothing displays so I ...

C# indexer's Documentation

I have looked over the MSDN site and I haven't been able to find C# indexer's documentation of a specific class For instance, I want to find HttpRequest's public string this[string key] documentation Where can i find it? ...

Calling indexer from within the same (generic) class

public class MyClass<T> { public T this[int index] { get { ... } set { ... } } public void MyMethod<T>() { int middleIndex = ...; T value = this[middle...

Overload indexer to have foreach'able class

I tried to do something like this but this doesn't work: class Garage { private List<Car> cars = new List<Car>(); public Car this[int i] { get { return cars[i]; } } //... } Garage g = new Garage(); //get CS1579 - no GetEnumerator definition foreach ...