Getter does not work if the setter is internal

I have a class with this property.

public bool IsDeleted { get; internal set; }

I use this class on some WCF services, playing with some instances of the class. All other public properties are visible after receiving an instance of the class except IsDeleted. If I create a setter public, IsDeleted works too.

Any ideas on this weird behavior?

+4
source share
1 answer

Most of all .NET serialization methods (including WCF) require the use of an accessible getter and setter, since it must be able to set the property to a value when it deserializes the input field.

, .

[DataContract]
class Foo
{
    [DataMember(Name="IsDeleted")]
    private bool _isDeleted;

    public bool IsDeleted 
    { 
       get { return _isDeleted; }
       internal set { _isDeleted = value; } 
    }
}

, Foo DLL refrence, , .

class Foo
{
    public bool IsDeleted { get; set; }
}

, , , DLL Foo , WCF.


DLL, Silvermind, , .

[DataContract]
class Foo
{
    private bool _isDeleted;

    public bool IsDeleted 
    { 
       get { return _isDeleted; }
       set {  } 
    }

    internal void SetIsDeletedInternal(bool value)
    {
        _isDeleted = value;
    }
}

, , Foo, _isDeleted default(bool) , .

+6

All Articles