-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDynamicEditor.cs
121 lines (112 loc) · 4.04 KB
/
DynamicEditor.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Data;
using System.Drawing.Design;
using WebServiceStudio.Dialogs;
namespace WebServiceStudio
{
public class DynamicEditor : UITypeEditor
{
private static Hashtable editorTable = null;
private static string typeNotFoundMessage = "ProxyPropertiesType {0} specified in WebServiceStudio.exe.options is not found";
static DynamicEditor()
{
editorTable = new Hashtable();
editorTable[typeof(object)] = Activator.CreateInstance(typeof(UITypeEditor));
editorTable[typeof(DataSet)] = Activator.CreateInstance(typeof(DataSetEditor));
editorTable[typeof(DateTime)] = Activator.CreateInstance(typeof(DateTimeEditor));
foreach (CustomHandler handler in Configuration.MasterConfig.DataEditors)
{
Type type = Type.GetType(handler.TypeName);
if (type == null)
{
NewMainForm.ShowMessage(typeof(DynamicEditor), MessageType.Warning, string.Format(typeNotFoundMessage, handler.TypeName));
}
else
{
Type type2 = Type.GetType(handler.Handler);
if (type2 == null)
{
NewMainForm.ShowMessage(typeof(DynamicEditor), MessageType.Warning, string.Format(typeNotFoundMessage, handler.Handler));
}
else
{
editorTable[type] = Activator.CreateInstance(type2);
}
}
}
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
Type type = null;
if (value == null)
{
TreeNodeProperty instance = context.Instance as TreeNodeProperty;
if (instance != null)
{
type = instance.Type;
}
}
else
{
type = value.GetType();
}
if (type != null)
{
return GetEditor(type).EditValue(context, provider, value);
}
return base.EditValue(context, provider, value);
}
private Type GetContainedType(ITypeDescriptorContext context)
{
if (context != null)
{
TreeNodeProperty instance = context.Instance as TreeNodeProperty;
if (instance != null)
{
return instance.Type;
}
}
return null;
}
public static UITypeEditor GetEditor(Type type)
{
object obj2 = null;
if (type != null)
{
if (typeof(DataSet).IsAssignableFrom(type))
{
type = typeof(DataSet);
}
obj2 = editorTable[type];
}
if (obj2 == null)
{
obj2 = editorTable[typeof(object)];
}
return (obj2 as UITypeEditor);
}
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return GetEditor(this.GetContainedType(context)).GetEditStyle(context);
}
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return base.GetPaintValueSupported(context);
}
public static bool IsEditorDefined(Type type)
{
if (GetEditor(type).GetType().IsAssignableFrom(typeof(UITypeEditor)))
{
return false;
}
return true;
}
public override void PaintValue(PaintValueEventArgs e)
{
base.PaintValue(e);
}
}
}