本文整理汇总了C#中System.Enum.HasFlag方法的典型用法代码示例。如果您正苦于以下问题:C# Enum.HasFlag方法的具体用法?C# Enum.HasFlag怎么用?C# Enum.HasFlag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Enum
的用法示例。
在下文中一共展示了Enum.HasFlag方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSetValues
/// <summary>
/// Returns an array of set values in the given enum
/// </summary>
/// <remarks>
/// This will return each set value if you have [Flags], or the single value if you don't
/// </remarks>
public static Array GetSetValues(Enum enumeration)
{
List<object> setValues = new List<object>();
foreach (object possibleValue in Enum.GetValues(enumeration.GetType()))
{
if (enumeration.HasFlag((Enum)possibleValue))
{
setValues.Add(possibleValue);
}
}
return setValues.ToArray();
}
示例2: PreventInvalidAudienceTypeForWorkStage
/// ------------------------------------------------------------------------------------
// ReSharper disable once UnusedParameter.Local
private void PreventInvalidAudienceTypeForWorkStage(Enum invalidAudience, WorkStage stage)
{
if ((invalidAudience != null) && (invalidAudience.HasFlag(_metsAudienceType)))
{
throw new InvalidOperationException(string.Format(
"Resources with an audience of \"{0}\" cannot have a work stage of {1}",
_metsAudienceType, stage));
}
}
示例3: GetFlags
static IEnumerable<Enum> GetFlags(Enum input)
{
foreach (Enum value in Enum.GetValues(input.GetType()))
if (input.HasFlag(value))
yield return value;
}
示例4: HasFlag
public static bool HasFlag(Enum value, Enum flag)
{
//Added in .NET 4.0
return value.HasFlag(flag);
}
示例5: GetFlags
/// <summary>
/// Iterate over the bit values in enum property.
/// </summary>
private static IEnumerable<string> GetFlags(Enum input)
{
foreach (Enum value in Enum.GetValues(input.GetType()))
if (input.HasFlag(value))
yield return value.ToString();
}
示例6: AdjustBinding
public static void AdjustBinding(string hotkeyName, Enum key, Dictionary<string, Hotkey> dict)
{
dict[hotkeyName].Key = (Keys)key;
dict[hotkeyName].Ctrl = key.HasFlag(Keys.Control);
dict[hotkeyName].Alt = key.HasFlag(Keys.Alt);
dict[hotkeyName].Shift = key.HasFlag(Keys.Shift);
}
示例7: Resolve
//.........这里部分代码省略.........
if (e is ThreadType)
{
switch((ThreadType)e)
{
case ThreadType.Cpu: return "cpu";
case ThreadType.Wait: return "wait";
case ThreadType.Block: return "block";
}
}
if (e is PercolateFormat)
{
switch((PercolateFormat)e)
{
case PercolateFormat.Ids: return "ids";
}
}
if (e is GroupBy)
{
switch((GroupBy)e)
{
case GroupBy.Nodes: return "nodes";
case GroupBy.Parents: return "parents";
}
}
if (e is ClusterStateMetric)
{
var list = new List<string>();
if (e.HasFlag(ClusterStateMetric.Blocks)) list.Add("blocks");
if (e.HasFlag(ClusterStateMetric.Metadata)) list.Add("metadata");
if (e.HasFlag(ClusterStateMetric.Nodes)) list.Add("nodes");
if (e.HasFlag(ClusterStateMetric.RoutingTable)) list.Add("routing_table");
if (e.HasFlag(ClusterStateMetric.RoutingNodes)) list.Add("routing_nodes");
if (e.HasFlag(ClusterStateMetric.MasterNode)) list.Add("master_node");
if (e.HasFlag(ClusterStateMetric.Version)) list.Add("version");
if (e.HasFlag(ClusterStateMetric.All)) return "_all";
return string.Join(",", list);
}
if (e is Feature)
{
var list = new List<string>();
if (e.HasFlag(Feature.Settings)) list.Add("_settings");
if (e.HasFlag(Feature.Mappings)) list.Add("_mappings");
if (e.HasFlag(Feature.Aliases)) list.Add("_aliases");
return string.Join(",", list);
}
if (e is IndicesStatsMetric)
{
var list = new List<string>();
if (e.HasFlag(IndicesStatsMetric.Completion)) list.Add("completion");
if (e.HasFlag(IndicesStatsMetric.Docs)) list.Add("docs");
if (e.HasFlag(IndicesStatsMetric.Fielddata)) list.Add("fielddata");
if (e.HasFlag(IndicesStatsMetric.QueryCache)) list.Add("query_cache");
if (e.HasFlag(IndicesStatsMetric.Flush)) list.Add("flush");
if (e.HasFlag(IndicesStatsMetric.Get)) list.Add("get");
if (e.HasFlag(IndicesStatsMetric.Indexing)) list.Add("indexing");
if (e.HasFlag(IndicesStatsMetric.Merge)) list.Add("merge");
示例8: HasFlag
public static void HasFlag(Enum e, Enum flag, bool expected)
{
Assert.Equal(expected, e.HasFlag(flag));
}
示例9: EnumHasOnlyOne
/// <summary>
/// Checks if input has only one of the values set.
/// </summary>
/// <param name="input">The input value.</param>
/// <param name="values">The values to check against.</param>
/// <returns>Returns true if input has only one of the values, false otherwise.</returns>
private bool EnumHasOnlyOne(Enum input, params Enum[] values)
{
if (values.Length < 1)
return false;
var hasFlag = false;
foreach (var value in values) {
if (input.HasFlag(value)) {
if (hasFlag)
return false;
else
hasFlag = true;
}
}
return hasFlag;
}