Last active
August 29, 2015 13:57
-
-
Save tugberkugurlu/9683182 to your computer and use it in GitHub Desktop.
Location Class which should be struct?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Data.Spatial; | |
public class Location | |
{ | |
public Location(double lat, double lng) | |
{ | |
Latitude = lat; | |
Longitude = lng; | |
} | |
public Location(string wellKnownText) | |
{ | |
if (wellKnownText == null) | |
{ | |
throw new ArgumentNullException("wellKnownText"); | |
} | |
DbGeography dbGeography = DbGeography.FromText(wellKnownText); | |
if (dbGeography.Latitude == null || dbGeography.Longitude == null) | |
{ | |
throw new ArgumentException("wellKnownText (WKT) is not in a correct format.", "wellKnownText"); | |
} | |
Latitude = dbGeography.Latitude.Value; | |
Longitude = dbGeography.Longitude.Value; | |
} | |
public double Latitude { get; private set; } | |
public double Longitude { get; private set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Data.Spatial; | |
public struct SLocation | |
{ | |
private readonly double _lat; | |
private readonly double _lng; | |
public SLocation(double lat, double lng) | |
{ | |
_lat = lat; | |
_lng = lng; | |
} | |
public SLocation(string wellKnownText) | |
{ | |
if (wellKnownText == null) | |
{ | |
throw new ArgumentNullException("wellKnownText"); | |
} | |
DbGeography dbGeography = DbGeography.FromText(wellKnownText); | |
if (dbGeography.Latitude == null || dbGeography.Longitude == null) | |
{ | |
throw new ArgumentException("wellKnownText (WKT) is not in a correct format.", "wellKnownText"); | |
} | |
_lat = dbGeography.Latitude.Value; | |
_lng = dbGeography.Longitude.Value; | |
} | |
public double Latitude { get { return _lat; } } | |
public double Longitude { get { return _lng; } } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment