PropertyChanged for indexer property

后端 未结 4 571
天命终不由人
天命终不由人 2020-12-01 04:11

I have a class with an indexer property, with a string key:

public class IndexerProvider {
    public object this[string key] {
        get
        {
                


        
4条回答
  •  死守一世寂寞
    2020-12-01 05:16

    Actually, I believe setting the IndexerName attribute to "Item" is redundant. The IndexerName attribute is specifically designed to rename an index, if you want to give it's collection item a different name. So your code could look something like this:

    public class IndexerProvider : INotifyPropertyChanged {
    
        [IndexerName("myIndexItem")]
        public object this [string key] {
            get {
                return ...;
            }
            set {
                ... = value;
                FirePropertyChanged ("myIndexItem[]");
            }
        }
    }
    

    Once you set the indexer name to whatever you want, you can then use it in the FirePropertyChanged event.

提交回复
热议问题