// WPF MapControl - http://wpfmapcontrol.codeplex.com/
// Copyright © 2012 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
namespace MapControl
{
///
/// A collection of geographic locations.
///
[TypeConverter(typeof(LocationCollectionConverter))]
public class LocationCollection : ObservableCollection
{
public LocationCollection()
{
}
public LocationCollection(IEnumerable locations)
{
foreach (Location location in locations)
{
Add(location);
}
}
public static LocationCollection Parse(string source)
{
LocationCollection locations = new LocationCollection();
foreach (string locString in source.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
{
locations.Add(Location.Parse(locString));
}
return locations;
}
}
///
/// Converts from string to LocationCollection.
///
public class LocationCollectionConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return LocationCollection.Parse((string)value);
}
}
}