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

后端 未结 7 2226
忘了有多久
忘了有多久 2021-02-20 15:55

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:58

    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];
        }
    }
    

提交回复
热议问题