The best way to open protected fields

I have a base class:

 public class BaseModalCommand
 {

    protected object m_commandArgument;
    protected int m_commandID;
    protected int m_enableUIFlags;

    public virtual void OnIdle()
    {
    }

    public virtual void OnResume()
    {
    }

    public virtual void OnStart(int commandID, object argument)
    {
    }

    public virtual void OnStop()
    {
    }



    public virtual int EnableUIFlags
    {
        get
        {
            return this.m_enableUIFlags;
        }
    }
}

Virtual methods must be overridden in derived types. If I run it through FxCop, it complains that it does not declare the visible fields of the instance and does not recommend changing it to private and exposing it to a protected property.

Any thoughts? I think this message can be ignored.

+2
source share
6 answers

: , , , . , , , . . , , , , . , .

, , ( gisresearch). ( ) . , ( ), , . , .

, . : , , .

+11

FxCop . direclty. , , , - .

+4

, getter/setter

protected object m_commandArgument;

private object m_commandArgument;

protected object CommandArgument {get; set;}

, / .

.

private string _email;
protected string Email
{ 
   get { return _email; }
   set 
   {
       if(value.IndexOf("@") > 0)
           _email = value;
       else
            throw new ArgumentException("Not a valid Email");
   }
}
+4

. - , -.

,

+1

, FxCop

private object m_commandArgument;

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

OO ( OO). , , .

0

, FxCop.

, , , . , / .

0

All Articles