Questions tagged [indexed-properties]

Properties of a Java Bean that could be accessed via index.

Properties of a Java Bean that could be accesses via index. Usually such property is a collection like a List, or Map, or array. Both collections have an index/key that could be used as a property accessor.

Here's how it's used in the Java Tutorial:

Indexed Properties

An indexed property is an array instead of a single value. In this case, the bean class provides a method for getting and setting the entire array. Here is an example for an int[] property called testGrades:

public int[] getTestGrades() {
    return mTestGrades;
}

public void setTestGrades(int[] tg) {
    mTestGrades = tg;
}

For indexed properties, the bean class also provides methods for getting and setting a specific element of the array.

public int getTestGrades(int index) {
    return mTestGrades[index];
}

public void setTestGrades(int index, int grade) {
    mTestGrades[index] = grade;
}
35 questions
84
votes
9 answers

Why C# doesn't implement indexed properties?

I know, I know... Eric Lippert's answer to this kind of question is usually something like "because it wasn't worth the cost of designing, implementing, testing and documenting it". But still, I'd like a better explanation... I was reading this blog…
Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
35
votes
6 answers

Easy creation of properties that support indexing in C#

In C# I find indexed properties extremely useful. For example: var myObj = new MyClass(); myObj[42] = "hello"; Console.WriteLine(myObj[42]); However as far as I know there is no syntactic sugar to support fields that themselves support indexing…
cdiggins
  • 17,602
  • 7
  • 105
  • 102
7
votes
5 answers

Is named indexer property possible?

Suppose I have an array or any other collection for that matter in class and a property which returns it like following: public class Foo { public IList Bars{get;set;} } Now, may I write anything like this: public Bar Bar[int index] { …
TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188
7
votes
3 answers

Validate elements of a String array with Java Bean Validation

I have a simple class that has one of its properties as a String array. As per this document, using @Valid on an array, collection etc. will recursively validate each element of the array/collection. @Valid @Pattern(regexp="^[_ A-Za-z0-9]+$") public…
Ironluca
  • 3,402
  • 4
  • 25
  • 32
7
votes
2 answers

Moq an indexed property and use the index value in the return/callback

I want to moq a property that has an index, and I want to be able to use the index values in the callback, the same way you can use method arguments in the callback for moq'd methods. Probably easiest to demonstrate with an example: public interface…
Rob
  • 4,327
  • 6
  • 29
  • 55
6
votes
1 answer

What is a reason NOT to make a Core Data property indexed?

What is a reason NOT to make a Core Data property indexed? From what I understand, searchable properties are supposed to be indexed, if it helps performance. If so, why isn't everything automatically indexed "internally"? Why must I turn it on/off…
Moshe
  • 57,511
  • 78
  • 272
  • 425
5
votes
2 answers

Named indexed property in C#?

A few languages - like Delphi - has a very convenient way of creating indexers: not only the whole class, but even single properties can be indexed, for instance: type TMyClass = class(TObject) protected function GetMyProp(index : integer) :…
Spook
  • 25,318
  • 18
  • 90
  • 167
4
votes
1 answer

protobuf-net How to avoid crashing when working with Indexed Properties

I'm trying to integrate the awesome protobuf-net into an existing codebase, but am encountering a crash when it tries to handle a custom type. A small demonstration is below: it will throw an InvalidOperationException in…
Gabriel
  • 1,443
  • 15
  • 24
3
votes
2 answers

Recognize indexer in LINQ expression

I need to programmatically recognize when an indexer occurs within an expression, but the resulting expression tree is not what I expected. class IndexedPropertiesTest { static void Main( string[] args ) { new IndexedPropertiesTest(); } …
HappyNomad
  • 4,458
  • 4
  • 36
  • 55
3
votes
2 answers

Binding to multiple indexers

I am trying to bind an indexed property with two indexers. The property looks like this public Item this[int x, int y] { get { return _items[x, y]; } set { _items[x, y] = value; } } According to…
Igor Lankin
  • 1,416
  • 2
  • 14
  • 30
3
votes
1 answer

Using Reflection to set the value of an indexed property

I am try to replicate the following c# code using reflection: UserProfileManager userProfileManager = new UserProfileManager(ServerContextGoesHere); UserProfile userProfile = null; userProfile =…
Ryan
  • 3,452
  • 4
  • 23
  • 20
2
votes
0 answers

TypeScript do not require all index properties

I have the following code: type AZ = 'a'|'b'|'c'|'d'| ... |'z'; // union of many types type Mapping = { [K in AZ]: string; } const obj: Mapping = { // error, missing properties 'c', 'd', etc. a: '', b: '' }; This lets me constrain props of…
2
votes
0 answers

Let Entity Framework (code first) ignore an indexed property

In an entity I have following declaration: Default Property Item(key As String) As String Because Entity Framework doesn't like indexed properties I've tried to ignore it: Public Class EntityMap Inherits EntityTypeConfiguration(Of EntityMap) …
2
votes
3 answers

Binding-driven Indexed Property Doesn't Return

Public Class View Public Property Items As String() = {"One", "Two", "Three"} Public Property Index As Integer = 0 End Class It's instance is set as DataContext of this XAML:
2
votes
5 answers

Non-integer indexed Indexer properties in C#

I want to have an indexed property in C#: public Boolean IsSelected[Guid personGuid] { get { Person person = GetPersonByGuid(personGuid); return person.IsSelected; } set { Person person = GetPersonByGuid(personGuid); …
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
1
2 3