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 ...
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...
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...
Is an indexer an extended version of a property?.
...
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...
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...
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...
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...
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 ...
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...
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...
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...
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++)...
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]; }...
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....
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 ...
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?
...
public class MyClass<T>
{
public T this[int index]
{
get
{
...
}
set
{
...
}
}
public void MyMethod<T>()
{
int middleIndex = ...;
T value = this[middle...
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 ...