I am using a custom serializer in c# in order to serialize/deserialize an object with a dictionary. However during the deserialization the dictionary object was not being set correctly. See code:
public DictionarySerializer<String, Point> jointDictionary
{
get { return _jointDictionary; }
set { _jointDictionary = jointDictionary; }
}
The jointDictionary object coming back was empty however in the debugger thread I noticed a “value” object that had the contents of my dictionary. Changing my code to the following fixed my issue:
public DictionarySerializer<String, Point> jointDictionary
{
get { return _jointDictionary; }
set { _jointDictionary = value; }
}
I have read about the “value” keyword and understand that it is a reserved word in C# to specify the value that the client it trying to use to set the object. So my question is, why wouldn’t the jointDictionary reference work as in my first attempt? And what is the correct usage for the value keyword?
The keyword
valuerepresents the value which is being passed to the property. You should always use it within the property setter.In the case you used
jointDictionaryyou were binding to the property getter. This makesCompiles to
Which since this accesses the property getter it really becomes