Adding properties dynamically to a class

后端 未结 6 1934
天命终不由人
天命终不由人 2020-12-03 17:14

In my class I have private variables and properties like this.

private string _itemCOde=string.Empty;
private string  _itemName=string.Empty;

public string          


        
6条回答
  •  爱一瞬间的悲伤
    2020-12-03 17:50

    You can dynamically associate names and values with each other using a Dictionary. You could combine this with your own wrapper using the indexer:

    public string this[this key]
    {
        get { return dictionary[key]; }
        set { dictionary[key] = value == null ? null : value.Trim(); }
    }
    

    Still, if the database changes, then you really should probably change your object because it changed.

提交回复
热议问题