Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. public class CustomContractResolver : DefaultContractResolver
  2. {
  3. protected override JsonContract CreateContract(Type objectType)
  4. {
  5. var contract = base.CreateContract(objectType);
  6.  
  7. if (objectType == typeof(decimal))
  8. {
  9. //Not sure this will actually give you the attribute, haven't tested it
  10. var custom = objectType.GetCustomAttributes(true).OfType<AvroFieldAttribute>().SingleOrDefault();
  11. if (custom != null)
  12. {
  13. contract.Converter = new AvroDecimalJsonConverter(custom.Precision, custom.Scale);
  14. }
  15.  
  16. }
  17.  
  18. return contract;
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement