-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListStandardValues.cs
62 lines (56 loc) · 2.18 KB
/
ListStandardValues.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
namespace WebServiceStudio
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Globalization;
using System.Reflection;
internal class ListStandardValues : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return ((sourceType == typeof(string)) || base.CanConvertFrom(context, sourceType));
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
{
Array possibleValues = this.GetPossibleValues(context);
if (possibleValues != null)
{
foreach (object obj2 in possibleValues)
{
if (obj2 != null)
{
if (obj2.ToString() == value.ToString())
{
return obj2;
}
}
else
return null;
}
}
}
return base.ConvertFrom(context, culture, value);
}
protected virtual Array GetPossibleValues(ITypeDescriptorContext context)
{
MethodInfo method = context.Instance.GetType().GetMethod("Get" + context.PropertyDescriptor.Name + "List");
if (method == null)
{
return null;
}
return (method.Invoke(context.Instance, null) as Array);
}
public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
Array possibleValues = this.GetPossibleValues(context);
return new TypeConverter.StandardValuesCollection((possibleValues != null) ? ((ICollection) possibleValues) : ((ICollection) new object[0]));
}
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
}
}