/Passbook.Generator/Location.cs
C# | 54 lines | 46 code | 8 blank | 0 comment | 5 complexity | 53c96016fb45cb65fa9f0e3ce2cd8130 MD5 | raw file
- using Newtonsoft.Json;
- using Passbook.Generator.Exceptions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Passbook.Generator
- {
- public class Location
- {
- public Location()
- {
- Latitude = double.MinValue;
- Longitude = double.MinValue;
- }
- public double Latitude { get; set; }
- public double Longitude { get; set; }
- public string RelevantText { get; set; }
- public void Write(JsonWriter writer)
- {
- Validate();
- writer.WriteStartObject();
- writer.WritePropertyName("latitude");
- writer.WriteValue(Latitude);
- writer.WritePropertyName("longitude");
- writer.WriteValue(Longitude);
- if (!string.IsNullOrEmpty(RelevantText))
- {
- writer.WritePropertyName("relevantText");
- writer.WriteValue(RelevantText);
- }
- writer.WriteEndObject();
- }
- private void Validate()
- {
- if (Latitude == double.MinValue)
- {
- throw new RequiredFieldValueMissingException("latitude");
- }
- if (Longitude == double.MinValue)
- {
- throw new RequiredFieldValueMissingException("longitude");
- }
- }
- }
- }