diff options
Diffstat (limited to 'Xamarin.Forms.Pages/JsonSourceConverter.cs')
-rw-r--r-- | Xamarin.Forms.Pages/JsonSourceConverter.cs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Xamarin.Forms.Pages/JsonSourceConverter.cs b/Xamarin.Forms.Pages/JsonSourceConverter.cs new file mode 100644 index 00000000..461c96d9 --- /dev/null +++ b/Xamarin.Forms.Pages/JsonSourceConverter.cs @@ -0,0 +1,22 @@ +using System; + +namespace Xamarin.Forms.Pages +{ + public class JsonSourceConverter : TypeConverter + { + public override object ConvertFromInvariantString(string value) + { + if (value != null) + { + value = value.Trim(); + Uri uri; + if (Uri.TryCreate(value, UriKind.Absolute, out uri) && uri.Scheme != "file") + return new UriJsonSource { Uri = uri }; + if (value.StartsWith("[") || value.StartsWith("{")) + return new StringJsonSource { Json = value }; + } + + throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(JsonSource))); + } + } +}
\ No newline at end of file |