C# Equivalent for C++ Macros and using Auto<> Properties

后端 未结 7 1918
灰色年华
灰色年华 2021-02-20 16:35

I have some auto-instantiation code which I would like to apply to about 15 properties in a fairly big class. The code is similar to the following but the type is differ

7条回答
  •  说谎
    说谎 (楼主)
    2021-02-20 16:44

    Try to use Hashtable or Dictionary to group all properties. Something like this:

    protected Dictionaty _properties = new Dictionaty();
    public ComplexType Property(string name)
    {
        get
        {
            if (!properties.ContainsKey(name))
                _properties[name] = new ComplexType();
    
            return __properties[name];
        }
    }
    

提交回复
热议问题