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

后端 未结 7 2363
忘了有多久
忘了有多久 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 <string, ComplexType> to group all properties. Something like this:

    protected Dictionaty<string, ComplexType> _properties = new Dictionaty<string, ComplexType>();
    public ComplexType Property(string name)
    {
        get
        {
            if (!properties.ContainsKey(name))
                _properties[name] = new ComplexType();
    
            return __properties[name];
        }
    }
    
    0 讨论(0)
提交回复
热议问题