I am trying to rename my indexer property using the IndexerName attribute in my abstract classes. But it still shows a compilation error. Type "XXX" already contains a definition for "Item" .
Abstract class:
public abstract class MyAbstract { [IndexerName("Indexer")] public abstract string this[string propertyName] { get; } }
Concrete class:
public class MyConcrete : MyAbstract { string item; public string Item { get { return item; } set { item = value; } } public override string this[string propertyName] { get { return propertyName; } } }
Compilation Error:
The type "MyConcrete" already contains a definition for "Item".
I tried to put IndexerName in the override of the indexer and show the error message "Cannot set the IndexerName attribute on the override marked by the indexer "
How to use IndexerName for abstract classes?
Thanks in advance.
, Item - , IndexerName .
Item
IndexerName
, . IndexerNameAttribute , . , , , . , , , . , , Item ( , ).
IndexerNameAttribute
[AttributeUsage(AttributeTargets.Property, Inherited = true)] public sealed class IndexerNameAttribute : Attribute
.
//base abstract class public abstract string GetItem(string propertyName); //and implement it in the derived classes