C# property with private set method still marked as CanWrite
I have been working on a data serializer that only serializes data that it can both Read and Write. I normally write this as follows
class SomeClass
{
public int MyValue { get; set; }
public int InternalValueOnly { get; private set; }
}
When run in .NET environments on Windows, macOS and Linux this shows the following property values:
PropertyInfo ofMyValue.CanRead: True
PropertyInfo ofMyValue.CanWrite: True
PropertyInfo ofInternalValueOnly.CanRead: True
PropertyInfo ofInternalValueOnly.CanWrite: False
In unity it changes to
PropertyInfo ofMyValue.CanRead: True
PropertyInfo ofMyValue.CanWrite: True
PropertyInfo ofInternalValueOnly.CanRead: True
PropertyInfo ofInternalValueOnly.CanWrite: True
I checked and this syntax is valid as of C# 3.0.. according to this forum post Unity is 3.0 w/ optional named arguments for 4.0. Is this normal behavior or do I have something incorrect here? My system has attributes I can put into place to make this work properly but it was much nicer when you didn't have to manage the serialization so hands on.
Your answer
Follow this Question
Related Questions
Modular property/interaction system 1 Answer
check if a list contains the same id as in another list 1 Answer
Setting another script's property from code doesn't actually set the property 1 Answer
Properties does not have new values 0 Answers
Can someone explain this to me? Player myPlayer = new Player(); 1 Answer