Let's say I got a class like this:
[Version(123)]
public class Test
{
}
How would I add a property "Version": 123 to the generated json ?
I've been playin with a custom ContractResolver
but with no success..
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
var properties = base.CreateProperties(type, memberSerialization);
var attributes = type.GetCustomAttributes(false);
VersionAttribute attribute = (VersionAttribute)attributes.FirstOrDefault(att => att is VersionAttribute);
if (attribute != null)
{
JsonProperty versionProperty = new JsonProperty();
versionProperty.ValueProvider = new ValueProvider(attribute);
versionProperty.PropertyType = typeof(int);
versionProperty.PropertyName = "Version";
versionProperty.DefaultValue = 0;
properties.Add(versionProperty);
}
return properties;
}