Announcement

Collapse
No announcement yet.

[CLOSED] [#3253] "CanWrite" of GetProperty returns True when should be False

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    [CLOSED] [#3253] "CanWrite" of GetProperty returns True when should be False

    In .NET, when the "CanWrite" property of a read-only auto-property returns False but in Bridge code it returns True - eg.

    public class Program
    {
        public static void Main()
        {
            var person = new Person(123, "Dan");
            var idProperty = typeof(Person).GetProperty("Id");
    
            Console.WriteLine("CanWrite: " + idProperty.CanWrite);
        }
    }
    
    public class Person
    {
        public Person(int id, string name)
        {
            Id = id;
            Name = name;
        }
    
        public int Id { get; }
        public string Name { get; }
    }
    (Available at https://deck.net/20da1af33b518a35b9ec06c4ea698218)

    I'm not sure if this is a limitation of the Bridge reflection implementation or if it's something that you would expect to work.

    I noticed this because I'm looking into any easy wins for JSON.NET optimisations and I think that it should be safe to skip trying to set properties that don't have public setters (or, better, avoid setting readonly properties) because they should have been set internally (such as by a constructor).. however, I can't find a way to tell whether a property has a private / readonly setter.
    Last edited by geoffrey.mcgill; 2017-11-06 @ 11:17 PM.

    #2
    Thanks for bringing this to our attention. We will investigate and fix right away.

    Comment

    Working...
    X