当前文件路径:HeroBeastControlsNavMenu/NavMenu/Converter/NavMenuSubItemConverter.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
//该源码下载自www.51aspx.com(51aspx.com)
11
namespace HeroBeastControls.NavMenu
12
...{
13
public class NavMenuSubItemConverter : ExpandableObjectConverter
14
...{
15
方法#region 方法
16
17
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
18
...{
19
if (sourceType == typeof(string))
20
...{
21
return true;
22
}
23
return base.CanConvertFrom(context, sourceType);
24
}
25
26
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
27
...{
28
if (destinationType == typeof(string))
29
...{
30
return true;
31
}
32
return base.CanConvertTo(context, destinationType);
33
}
34
35
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture,
36
object value)
37
...{
38
if (value == null)
39
...{
40
return new NavMenuSubItem();
41
}
42
if (value is string)
43
...{
44
string s = (string)value;
45
if (s.Length == 0)
46
...{
47
return new NavMenuSubItem();
48
}
49
return "NavMenuSubItem";
50
51
}
52
return base.ConvertFrom(context, culture, value);
53
}
54
55
public override object ConvertTo(
56
ITypeDescriptorContext context,
57
CultureInfo culture, object value, Type destinationType)
58
...{
59
if (value != null)
60
...{
61
if (!(value is NavMenuSubItem))
62
...{
63
throw new ArgumentException(
64
"Invalid NavMenuSubItem", "value");
65
}
66
}
67
68
if (destinationType == typeof(string))
69
...{
70
if (value == null)
71
...{
72
return String.Empty;
73
}
74
return "NavMenuSubItem";
75
}
76
return base.ConvertTo(context, culture, value,
77
destinationType);
78
}
79
#endregion
80
}
81
}
82