-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
WebViewSourceTypeConverter.cs
33 lines (28 loc) · 1.18 KB
/
WebViewSourceTypeConverter.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
#nullable disable
using System;
using System.ComponentModel;
using System.Globalization;
namespace Microsoft.Maui.Controls
{
/// <include file="../../docs/Microsoft.Maui.Controls/WebViewSourceTypeConverter.xml" path="Type[@FullName='Microsoft.Maui.Controls.WebViewSourceTypeConverter']/Docs/*" />
public class WebViewSourceTypeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
=> sourceType == typeof(string);
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
=> destinationType == typeof(string);
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var strValue = value?.ToString();
if (strValue != null)
return new UrlWebViewSource { Url = strValue };
throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", strValue, typeof(UrlWebViewSource)));
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (value is not UrlWebViewSource uwvs)
throw new NotSupportedException();
return uwvs.Url;
}
}
}