.NET中的标志属性 [英] Flag attribute in .net

查看:61
本文介绍了.NET中的标志属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个患者信息系统项目,在该项目中我使用flag属性,但是在运行项目后出现错误"the name flag does not exist in current context".
我该如何清除?
请帮助我.

Hi,

I have a project of Patient information system.In this project I am using flag attribute but after run my project I am getting the error "the name flag does not exist in current context".
How can i clear this?
plz help me.

推荐答案

这是System.Flags.

(可选)使用

This is System.Flags.

Optionally, use

using System;







or

using Flags = System.Flags;



在上述情况下,您可以从"System.Flags"中省略"System".

请记住,该属性仅影响枚举类型的值的字符串表示形式,显示正确设置的位,例如"DeclaredOnly,Static";如果没有此属性,则为"10".

另外,"OptionalParamBinding = 262144"非常糟糕.使用十六进制表示法以提高可读性,或者更好的是使用二进制移位:



In the above cases you could omit "System" from "System.Flags".

Remember, this attribute only affect string presentation of the value of your enumeration type, showing bit set properly, for example "DeclaredOnly, Static"; without this attribute it would be "10".

Also, "OptionalParamBinding = 262144" is pretty bad. Use hexadecimal notation for readability, or, better yet, a binary shift:

[Flags]
enum NumericSamples {
   None = 0,
   First = 1 << 0,
   Second = 1 << 1,
   Third = 1 << 2,
}



有关更多有用的提示和技术,请参阅我的文章:
枚举类型不枚举!解决.NET和语言限制 [ ^ ],
人类可读的枚举元数据 [基于枚举的命令行实用程序 [



For more useful hints and techniques, see my articles:
Enumeration Types do not Enumerate! Working around .NET and Language Limitations[^],
Human-readable Enumeration Meta-data[^],
Enumeration-based Command Line Utility[^], especially the first one.

Good luck,

—SA


Sridharan,更多信息和源代码会有所帮助!

从您的问题中,我将盲目地猜测您使用的是标志"而不是标志",请参见以下内容:

Sridharan, some more information and source code would help!

From your question I''m going to blindly guess you are using ''flag'' instead of ''Flags'', see below:

[Flags] // System.Flags or System.FlagsAttribute will also work.
public enum BindingFlags
{
    Default = 0,
    IgnoreCase = 1,
    DeclaredOnly = 2,
    Instance = 4,
    Static = 8,
    Public = 16,
    NonPublic = 32,
    FlattenHierarchy = 64,
    InvokeMethod = 256,
    CreateInstance = 512,
    GetField = 1024,
    SetField = 2048,
    GetProperty = 4096,
    SetProperty = 8192,
    PutDispProperty = 16384,
    PutRefDispProperty = 32768,
    ExactBinding = 65536,
    SuppressChangeType = 131072,
    OptionalParamBinding = 262144,
    IgnoreReturn = 16777216,
}



我假设您知道标志的工作原理以及为什么/不使用它们:)



I''m going to assume you know how flags work and why you would/wouldn''t use them :)


这篇关于.NET中的标志属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆