I haven't been able to find the answer to this anywhere, but when I try to serialize a struct or class with static or const member variables, they don't serialize by default. If I try to force serialization by setting MemberSerialization.OptIn, I get an error.
ex.
[JsonObject(MemberSerialization.OptIn)]
public class Test
{
[JsonProperty]
public int x = 1;
[JsonProperty]
public static int y = 2;
}
If I try to serialize this class with:
Test t = new Test();
string s = JsonConvert.SerializeObject( t );
I get the error Error getting value from 'y' on 'Test'. The same happens if y is const.
My theory is that static and const values are stored somewhere special in memory, and for some reason the Json serializer dies trying to access them. That's entirely a hunch though, and I see nothing in the C# Reference for Static that's of any help. I'm relatively new to C# - and this is really a curiosity question more than anything at this point.
readonlyand initialized the variable within the class definition, making it instance data, but really, IMO a version specifier should be static. Also the question says serialize not deserialize.t.y... Oh well. Sometimes dumb questions need to be asked...