In C #, the only possible way to declare a parameterized property is through an index. However, you could mimic something like this by creating a class that provides an index and adds a property of this type to your class:
class ParameterizedProperty<TProperty, TIndex> {
private Func<TIndex, TProperty> getter;
private Action<TIndex, TProperty> setter;
public ParameterizedProperty(Func<TIndex, TProperty> getter,
Action<TIndex, TProperty> setter) {
this.getter = getter;
this.setter = setter;
}
public TProperty this[TIndex index] {
get { return getter(index); }
set { setter(index, value); }
}
}
class MyType {
public MyType() {
Prop = new ParameterizedProperty<string, int>(getProp, setProp);
}
public ParameterizedProperty<string, int> Prop { get; private set; }
private string getProp(int index) {
}
private void setProp(int index, string value) {
}
}
MyType test = new MyType();
test.Prop[0] = "Hello";
string x = test.Prop[0];
You can expand the read-only idea and write only properties by removing the getter or setter from the class, if necessary.