Skip to content

Property Indexers Support

Cy Scott edited this page Aug 23, 2021 · 2 revisions

Interfaces that have indexer members will have the property implemented, unless the interface is marked a partial (i.e. public partial interface IHaveAnIndex {}). The property implementation will throw the NotImplementedException exception. Here is a simple example of how it works:

[Generate]
public interface IHaveAnIndex
{
    string this[int index] { get; set; }
}

The generated code will look like:

public class HaveAnIndexModel : IHaveAnIndex
{
    public string this[int index]
    {
        get
        {
            throw new System.NotImplementedException();
        }
        set
        {
            throw new System.NotImplementedException();
        }
    }
        
    public HaveAnIndexModel()
    {
    }
        
}

Clone this wiki locally