-
Notifications
You must be signed in to change notification settings - Fork 175
/
Extensions.cs
58 lines (52 loc) · 1.68 KB
/
Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Linq;
using Microsoft.Bot.Schema;
namespace Bot.Builder.Community.Dialogs.Location
{
/// <summary>
/// Extensions for <see cref="Place"/>
/// </summary>
public static class Extensions
{
/// <summary>
/// Gets the postal address.
/// </summary>
/// <param name="place">The place.</param>
/// <returns>The <see cref="PostalAddress"/> if available, null otherwise.</returns>
public static PostalAddress GetPostalAddress(this Place place)
{
if (place.Address != null)
{
return (PostalAddress)place.Address;
}
return null;
}
/// <summary>
/// Gets the geo coordinates.
/// </summary>
/// <param name="place">The place.</param>
/// <returns>The <see cref="GeoCoordinates"/> if available, null otherwise.</returns>
public static GeoCoordinates GetGeoCoordinates(this Place place)
{
if (place.Geo != null)
{
return (GeoCoordinates)place.Geo;
}
return null;
}
internal static string GetFormattedAddress(this Bing.Location location, string separator)
{
if (location?.Address == null)
{
return null;
}
return string.Join(separator, new[]
{
location.Address.AddressLine,
location.Address.Locality,
location.Address.AdminDistrict,
location.Address.PostalCode,
location.Address.CountryRegion
}.Where(x => !string.IsNullOrEmpty(x)));
}
}
}