Search code examples
c#xnafarseer

The property or indexer 'FarseerPhysics.Dynamics.Body.IsSensor' cannot be used in this context because it lacks the get accessor


Circle2.IsSensor = Circle1.IsSensor;

The property or indexer 'FarseerPhysics.Dynamics.Body.IsSensor' cannot be used in this context because it lacks the get accessor

I always get this error message. What is wrong? What should I change?


Solution

  • Because it is a write only property. Probably something like

    private static bool _isSensor;
    public static bool IsSensor
    {
       set 
       {
            _isSensor= value;
       }
    }
    

    Read more about accessors here. However according to design guidelines that FxCOP uses the design should not permit it. And if you have got access to the code think of changing the design.

    Get accessors provide read access to a property and set accessors provide write access. Although it is acceptable and often necessary to have a read-only property, the design guidelines prohibit the use of write-only properties. This is because letting a user set a value and then preventing the user from viewing the value does not provide any security. Also, without read access, the state of shared objects cannot be viewed, which limits their usefulness.

    How to Fix Violations To fix a violation of this rule, add a get accessor to the property. Alternatively, if the behavior of a write-only property is necessary, consider converting this property to a method.