Indexer

You design a C# indexer using an attribute with the <<Indexer>> stereotype. Another attribute with the <<IndexerImplementation>> stereotype is automatically created, it is displayed with an underscore sign in the list of attributes. The corresponding getter and setter operations are also automatically created.

You can get rid of the implementation attribute.

If you remove both getter and setter operations, the attribute no longer has the <<Indexer>> stereotype.

When you define a <<Indexer>> attribute, the attribute changeability and the getter/setter operations are tightly related as explained in the following table:

Operations

Indexer attribute changeability

If you keep both getter and setter operations

Indexer is Changeable

If you remove the setter operation of a changeable property

Indexer becomes Read-only

If you remove the getter operation of a changeable property

Indexer becomes Write-only

On the other hand, if you modify the indexer changeability, operations will reflect this change, for example, if you turn a changeable indexer into a read-only indexer, the setter operation is automatically removed.

In the following example, class Person contains indexer attribute Item. The parameter used to sort the property is String Name:.



public class Person
{
 private Hashtable _childAges;
 // Indexer Item
 private int this[String name]
 {
  get
  {
   return (int)_ChildAges[name];
  }
  set
  {
    _ChildAges[name] = value;
  }
 }
}
Person someone;
someone ["Alice"] = 3;
someone ["Elvis"] = 5;

The following table lists the different indexer modifiers supported in PowerDesigner:

C# property modifier

PowerDesigner equivalent

New

New extended attribute set to True

Usafe

Usafe extended attribute set to True

Virtual

Virtual extended attribute set to True

Override

Override extended attribute set to True

Extern

Extern extended attribute set to True

Abstract

Abstract extended attribute set to True

Sealed

Sealed extended attribute set to True

Parameters

Type a value in the value box of the Indexer parameters extended attribute to specify which value of the property attribute is to be used as parameter.