PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Passbook.Generator/Location.cs

https://github.com/Comezon/dotnet-passbook
C# | 54 lines | 46 code | 8 blank | 0 comment | 5 complexity | 53c96016fb45cb65fa9f0e3ce2cd8130 MD5 | raw file
  1. using Newtonsoft.Json;
  2. using Passbook.Generator.Exceptions;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. namespace Passbook.Generator
  8. {
  9. public class Location
  10. {
  11. public Location()
  12. {
  13. Latitude = double.MinValue;
  14. Longitude = double.MinValue;
  15. }
  16. public double Latitude { get; set; }
  17. public double Longitude { get; set; }
  18. public string RelevantText { get; set; }
  19. public void Write(JsonWriter writer)
  20. {
  21. Validate();
  22. writer.WriteStartObject();
  23. writer.WritePropertyName("latitude");
  24. writer.WriteValue(Latitude);
  25. writer.WritePropertyName("longitude");
  26. writer.WriteValue(Longitude);
  27. if (!string.IsNullOrEmpty(RelevantText))
  28. {
  29. writer.WritePropertyName("relevantText");
  30. writer.WriteValue(RelevantText);
  31. }
  32. writer.WriteEndObject();
  33. }
  34. private void Validate()
  35. {
  36. if (Latitude == double.MinValue)
  37. {
  38. throw new RequiredFieldValueMissingException("latitude");
  39. }
  40. if (Longitude == double.MinValue)
  41. {
  42. throw new RequiredFieldValueMissingException("longitude");
  43. }
  44. }
  45. }
  46. }