Best way to expose protected fields

前端 未结 6 993
不知归路
不知归路 2021-01-19 05:50

I have a base class like this:

 public class BaseModalCommand
 {

    protected object m_commandArgument;
    protected int m_commandID;
    protected int m_         


        
6条回答
  •  梦毁少年i
    2021-01-19 06:07

    Basically, FxCop recommends that you should do

    private object m_commandArgument;
    
    protected object CommandArgument
    {
       get { return m_commandArgument; }
       set { m_commandArgument =value}
    }
    

    This is based on OO encapsulation rule- (One of three OO rules). You may want to check the value before assigning, and you want to ensure this is not directly manipulated by the derived class.

提交回复
热议问题