【发布时间】:2018-02-07 17:31:48
【问题描述】:
我有几个编辑器。每个编辑器都有特定性,例如数据库中的特定字段类型或可编辑或不可编辑。
所以我需要一组带有名称和属性的编辑器类型。我需要能够用集合填充组合框
如何声明每种类型并拥有类型列表?
我试试这个
public enum TemplateType
{TextBox,ColorPicker};
public class TabloidBaseControl
{
public static DbType DefaultFieldType { get { return DbType.String; } }
public static int? DefaultFieldLength { get { return 20; } }
public static int? DefaultFieldDecimal { get { return null; } }
}
public class TCColorPicker:TabloidBaseControl
{
public new static int? DefaultFieldLength = 7;
}
public class TCTextBox: TabloidBaseControl
{
public new static int? DefaultFieldLength = 20;
}
public static Dictionary<TemplateType, TabloidBaseControl> TabloidControlList = new Dictionary<TemplateType, TabloidBaseControl> {
{TemplateType.TextBox,new TCTextBox()},
{TemplateType.ColorPicker,new TCColorPicker() }
};
这是正确的方法吗?
【问题讨论】:
-
您确定您发布的代码正确吗?
-
是的,这是我的代码......但是车辆的例子不是一个好主意,我删除它
-
好吧,你得到的代码有什么问题?你不想做什么?也就是说,这个问题还是很模糊的。你想完成什么?
-
起初对不起我的英语。我有很多编辑器,每个编辑器都有相同的属性,例如数据库中需要的字段类型。我需要有一个此编辑器的列表以填充到组合框中,并从选定的值中找到数据库字段类型。
-
我明白了那部分,但我不明白为什么这段代码不能做你想做的事。
标签: c# class static declaration