首页 \ 问答 \ 循环“选定”枚举值?(Loop through “selected” Enum values? [duplicate])

循环“选定”枚举值?(Loop through “selected” Enum values? [duplicate])

这个问题在这里已经有了答案:

我知道如何遍历枚举属性列表,但我将如何遍历所有“选定”枚举属性? 例如,如果有人做了Prop1 | Prop2 Prop1 | Prop2反对public enum Foo { Prop1; Prop2; Prop3 } public enum Foo { Prop1; Prop2; Prop3 } public enum Foo { Prop1; Prop2; Prop3 } ,我将如何实现这一目标?

这是我现在拥有的:

var values = Enum.GetValues(typeof(FileStatus)).Cast<FileStatus>();
foreach (var value in values)
{
}

它遍历所有的枚举属性,但我只想循环那些“被选中”的。

更新:设置了[Flags]属性。

更新2:枚举包含大量的属性,我不能也不会键入/硬编码一个属性检查,而是我想动态地循环每个属性,并检查我的枚举实例Bar包含循环项目集。


This question already has an answer here:

I know how to loop through enum list of properties, but how would I loop through all "selected" enum properties? For example, if one did Prop1 | Prop2 against public enum Foo { Prop1; Prop2; Prop3 }, how would I achieve this?

This is what I have now:

var values = Enum.GetValues(typeof(FileStatus)).Cast<FileStatus>();
foreach (var value in values)
{
}

It loops through all enum properties, but I'd like to loop only the ones that were "selected".

Update: [Flags] attribute was set.

Update 2: The enum contains a large number of properties, I can't and won't type/hardcode a single property check, instead I want to dynamically loop through each of them and check if my enum instance Bar contains the looped item set.


原文:https://stackoverflow.com/questions/10303353
更新时间:2022-10-13 18:10

最满意答案

你可以使用svn:ignore 。 您通常需要告诉SVN将特殊属性应用于文件:

svn propset svn:ignore "*.jpg" .

(注意命令末尾的点。)

对于多个文件,您可以添加换行符。

在此输入完全相同的换行符:

svn propset svn:ignore "file1
file2
file3" dir1

检查文件是否被忽略:

svn status --no-ignore

然后提交代码。

是的,许多重复的问题已经可用。

你可以参考我最喜欢的svn cheatguide

您可以使用您忽略的文件和目录创建一个文件svn-ignore.txt

*.class
*.jar
*.war
*.ear
 target/
.classpath
.settings/
.project
.metadata
 bin/

现在尝试以下操作:

svn propset svn:ignore -RF /root/svn-ignore.txt . [dot for current dir]

-R是递归的。


You can use svn:ignore. You generally need to tell SVN to apply special properties to the files:

svn propset svn:ignore "*.jpg" .

(Note the dot at the end of the command.)

For multiple files you can add a newline character.

Type exactly like here with line breaks:

svn propset svn:ignore "file1
file2
file3" dir1

Check that the files are ignored:

svn status --no-ignore

Then commit the code.

And yes, many duplicate questions are already available.

You can refer my favorite svn cheatguide.

You can create a file, svn-ignore.txt, with your ignored files and directories:

*.class
*.jar
*.war
*.ear
 target/
.classpath
.settings/
.project
.metadata
 bin/

Now try the following:

svn propset svn:ignore -RF /root/svn-ignore.txt . [dot for current dir]

-R is for recursive.

相关问答

更多
  • 你可以使用svn:ignore 。 您通常需要告诉SVN将特殊属性应用于文件: svn propset svn:ignore "*.jpg" . (注意命令末尾的点。) 对于多个文件,您可以添加换行符。 在此输入完全相同的换行符: svn propset svn:ignore "file1 file2 file3" dir1 检查文件是否被忽略: svn status --no-ignore 然后提交代码。 是的,许多重复的问题已经可用。 你可以参考我最喜欢的svn cheatguide 。 您可以使 ...
  • 不要忘记,根据gitignore ,Git认为,在不同的“忽视模式来源”中有一个优先级: 从命令行读取支持它们的那些命令的模式。 在距离.gitignore文件中读取的文件与路径相同的目录中,或在任何父目录中,其中较高级别文件(直到根目录)中的模式被下级文件中的模式覆盖到包含该文件的目录。 从$GIT_DIR/info/exclude读取的模式。 从配置变量core.excludesfile指定的文件读取模式。 最后两个可以解决您的问题,但是 它们不会被复制到远处的存储库 他们的模式可以被其他来源所覆盖 ( ...
  • 您需要做出关于在转换中使用哪组忽略的策略决策,并可能删除生成的.gitignore文件或用户创建的文件。 转换前你有.gitignore吗? 如果是这样,请将其与之后的那个进行比较。 看来这个政策决定与你的“提交顺序”问题是分开的,对吗? 基本上,政策问题只是“得到你喜欢的最终.gitignore”。 做到达到目的所需的一切。 在git中,.gitignore文件的管理方式与任何其他文件完全相同。 所以你可以说git log .gitignore并查看提交内容的贡献。 假设整个.gitignore文件在一个 ...
  • 你的问题是,开头的/*模式是匹配顶级的所有文件和目录,包括testdir ,所以testdir内的所有内容都被忽略。 这就是你想要的: # Ignore everything * # Don't ignore directories, so we can recurse into them !*/ # Don't ignore .gitignore and *.foo files !.gitignore !*.foo 当你做一个git add . 使用此配置,您应该发现只有.gitignore和*.foo ...
  • .gitignore告诉git它应该忽略哪些文件(或模式)。 它通常用于避免从工作目录提交对其他协作者无用的临时文件,例如编译产品,IDE创建的临时文件等。 您可以在这里找到完整的详细信息。 .gitignore tells git which files (or patterns) it should ignore. It's usually used to avoid committing transient files from your working directory that aren't u ...
  • 使用! 否定模式: *.dll !myfile.dll Use ! to negate the pattern: *.dll !myfile.dll
  • svn:ignore属性与.svn文件夹中的其他属性一起存储。 它将在您下次提交后自动存储在存储库中。 如果你只想提交svn:ignore更改而不提交其他“普通”文件,你可以尝试: svn commit --depth=empty . 可以使用svn propget svn:ignore检查svn propget svn:ignore 。 svn:ignore property is stored together with other properties inside the .svn folder. ...
  • 这些文件已经添加到git存储库中。 做git rm --cached .idea然后提交。 These files are added into the git repository already. Do the git rm --cached .idea then commit.
  • 你可以使用git exclude代替。 请参阅最后一节: http://help.github.com/ignore-files/ you can use git exclude instead. See the last section here: http://help.github.com/ignore-files/
  • 您需要在.gitignore文件中添加static 。 正斜杠正在阻止git找到目录。 编辑1:如果git rm --cached static已经跟踪了该文件夹,您可能需要运行git rm --cached static 。 编辑2:海报的标准已更改,他们只想忽略根目录中的static文件夹。 只需在.gitignore文件中添加/static (并删除static ) 。 这在另一个问题中讨论。 You need to add static to your .gitignore file. The fo ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)