I would like to set two fields with the same JsonProperty value. If I try to have both of the fields with the same JsonEntity value I will get an error that I can't have two fields with the same JsonProperty.
public class Entity
{
[JsonProperty("code")]
public String Id
{
get
{
return Id;
}
set
{
Id = value;
IdDuplicate = value;
}
}
public String IdDuplicate { get; set; }
}
Serialize it like this:
JsonConvert.DeserializeObject<JsonEntitys>("{ \"code\": \"test\" }");
But I get
(0xc0000005) 'Access violation'
I've managed to solve it using this way:
public class Entity
{
public String id { private get; set; }
[JsonProperty("code")]
public String Id
{
get
{
return this.id;
}
set
{
this.id = value;
this.IdDuplicate = value;
}
}
public String IdDuplicate { get; set; }
}
try this:
public class Entity
{
public String Id { get; set; }
public String code
{
get
{
return Id;
}
set
{
Id = value;
IdDuplicate = value;
}
}
public String IdDuplicate { get; set; }
}
User contributions licensed under CC BY-SA 3.0