C# 使用枚举或标志作为用户控件属性
我有一个web用户控件,它的类型属性是一个标志: 在服务器端代码中,我可以像这样分配它:C# 使用枚举或标志作为用户控件属性,c#,asp.net,enums,user-controls,C#,Asp.net,Enums,User Controls,我有一个web用户控件,它的类型属性是一个标志: 在服务器端代码中,我可以像这样分配它: Type = GraphTypes.Comment | GraphTypes.Like; 但在添加用户控件时,如: <uc:Graph Type="Comment|Like" runat="server" /> 我得到一个错误: 无法从“type”属性的字符串表示形式“Comment | Like”创建“GraphTypes”类型的对象 如何在我的标记中分配Comment | Like的
Type = GraphTypes.Comment | GraphTypes.Like;
但在添加用户控件时,如:
<uc:Graph Type="Comment|Like" runat="server" />
我得到一个错误:
无法从“type”属性的字符串表示形式“Comment | Like”创建“GraphTypes”类型的对象
如何在我的标记中分配
Comment | Like
的值?假设您的图形类型Enum
如下所示
[Flags]
enum GraphTypes
{
Comment = 1,
Like = 2,
Foo = 4,
Bar = 8
}
你只需要更换
Type="Comment|Like"
与
它等于
GraphTypes Type=GraphTypes.Comment | GraphTypes.Like代码>或图形类型=(图形类型)3代码>假设您的图形类型Enum
如下所示
[Flags]
enum GraphTypes
{
Comment = 1,
Like = 2,
Foo = 4,
Bar = 8
}
你只需要更换
Type="Comment|Like"
与
它等于GraphTypes Type=GraphTypes.Comment | GraphTypes.Like代码>或图形类型=(图形类型)3代码>然后它抛出错误值“3”不是枚举“GraphTypes”的有效值。请确保它是GraphTypes type=(GraphTypes)3代码>应该可以工作aswell@fubo,如何设置(All&~(Foo))?然后它抛出错误值“3”不是枚举“GraphTypes”的有效值。请确保它是GraphTypes type=(GraphTypes)3代码>应该可以工作aswell@fubo,如何设置(全部&~(Foo))?