Overriding the Defaults in a struct (c#)

前端 未结 12 946
感情败类
感情败类 2021-01-04 00:47

Is it possible to set or override the default state for a structure?

As an example I have an

enum something{a,b,c,d,e};

and a struc

12条回答
  •  鱼传尺愫
    2021-01-04 01:22

    Each time you get/set property you need to set default value call InitDefaultValues() method

    private string _numberDecimalSeparator;
    public string NumberDecimalSeparator
    {
        get
        {
            InitDefaultValues();
            return _numberDecimalSeparator;
        }
        set
        {
            InitDefaultValues(); 
            _numberDecimalSeparator = value;
        }
    }
    

    ...

    private void InitDefaultValues()
    {
        if (!_inited)
        {
            _inited = false;
            var ci = CultureInfo.CurrentCulture;
             _numberDecimalSeparator = ci.With(x => x.NumberFormat).Return(x => x.NumberDecimalSeparator, ".");
    
            ...
        }
    }
    

提交回复
热议问题