-
Notifications
You must be signed in to change notification settings - Fork 13
/
VersionRangeConverter.cs
76 lines (67 loc) · 2.84 KB
/
VersionRangeConverter.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
namespace UIShell.OSGi
{
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
internal class VersionRangeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType != typeof(string))
{
return base.CanConvertFrom(context, sourceType);
}
return true;
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType != typeof(InstanceDescriptor))
{
return base.CanConvertTo(context, destinationType);
}
return true;
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
string version = value as string;
if (version == null)
{
return base.ConvertFrom(context, culture, value);
}
return new VersionRange(version);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == null)
{
throw new ArgumentNullException("destinationType");
}
VersionRange range = value as VersionRange;
if ((null != range) && (destinationType == typeof(string)))
{
return range.ToString();
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues)
{
if (propertyValues == null)
{
throw new ArgumentNullException("propertyValues");
}
object obj3 = propertyValues["min"];
object obj2 = propertyValues["max"];
if (((obj3 == null) || (obj2 == null)) || (!(obj3 is string) || !(obj2 is string)))
{
throw new ArgumentException("PropertyValueInvalidEntry");
}
return new VersionRange((string) obj3, (string) obj2);
}
public override bool GetCreateInstanceSupported(ITypeDescriptorContext context) => true;
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) =>
TypeDescriptor.GetProperties(typeof(VersionRange), attributes).Sort(new string[] { "min", "max" });
public override bool GetPropertiesSupported(ITypeDescriptorContext context) => true;
}
}