当前文件路径:HeroBeastControlsNavMenu/NavMenu/Converter/NavMenuItemConverter.cs 
1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Text;
5
using System.Web;
6
using System.Web.UI;
7
using System.Web.UI.WebControls;
8
using System.Globalization;
9
10
namespace HeroBeastControls.NavMenu
11
...{
12
/**//// <summary>
13
/// NavMenuItem类型转换器
14
/// </summary>
15
public class NavMenuItemConverter : ExpandableObjectConverter
16
...{
17
方法#region 方法
18
19
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
20
...{
21
if (sourceType == typeof(string))
22
...{
23
return true;
24
}
25
return base.CanConvertFrom(context, sourceType);
26
}
27
28
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
29
...{
30
if (destinationType == typeof(string))
31
...{
32
return true;
33
}
34
return base.CanConvertTo(context, destinationType);
35
}
36
37
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture,
38
object value)
39
...{
40
if (value == null)
41
...{
42
return new NavMenuItem();
43
}
44
if (value is string)
45
...{
46
string s = (string)value;
47
if (s.Length == 0)
48
...{
49
return new NavMenuItem();
50
}
51
return "NavMenuItem";
52
53
}
54
return base.ConvertFrom(context, culture, value);
55
}
56
57
public override object ConvertTo(
58
ITypeDescriptorContext context,
59
CultureInfo culture, object value, Type destinationType)
60
...{
61
if (value != null)
62
...{
63
if (!(value is NavMenuItem))
64
...{
65
throw new ArgumentException(
66
"Invalid NavMenuItem", "value");
67
}
68
}
69
70
if (destinationType == typeof(string))
71
...{
72
if (value == null)
73
...{
74
return String.Empty;
75
}
76
return "NavMenuItem";
77
}
78
return base.ConvertTo(context, culture, value,
79
destinationType);
80
}
81
#endregion
82
}
83
}
84