循环“选定”枚举值?(Loop through “selected” Enum values? [duplicate])
这个问题在这里已经有了答案:
- 在Flags Enum中迭代值? 12个答案
我知道如何遍历枚举属性列表,但我将如何遍历所有“选定”枚举属性? 例如,如果有人做了
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:
- Iterate over values in Flags Enum? 13 answers
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
againstpublic 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
最满意答案
你可以使用
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忽略像.gitignore(SVN ignore like .gitignore)[2024-02-14]
你可以使用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文件在一个 ...
-
.gitignore忽略所有文件,然后递归地允许* .foo(.gitignore ignore all files then recursively allow *.foo)[2022-05-16]
你的问题是,开头的/*模式是匹配顶级的所有文件和目录,包括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?(What is .gitignore exactly?)[2023-10-23]
.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 ... -
例外.gitignore(Exceptions in .gitignore)[2023-10-26]
使用! 否定模式: *.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. ...
-
gitignore - 如何忽略.idea /目录为rubymine(gitignore - how to ignore .idea/ directory for rubymine)[2023-05-01]
这些文件已经添加到git存储库中。 做git rm --cached .idea然后提交。 These files are added into the git repository already. Do the git rm --cached .idea then commit. -
防止使用git-svn将本地.gitignore推送到svn repo(Preventing local .gitignore from being pushed to svn repo with git-svn)[2022-04-17]
你可以使用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 ...