當前位置: 首頁>>代碼示例>>C#>>正文


C# Enum.HasFlag方法代碼示例

本文整理匯總了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();
        }
開發者ID:ramarag,項目名稱:XTask,代碼行數:19,代碼來源:Enums.cs

示例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));
			}
		}
開發者ID:jwickberg,項目名稱:libpalaso,代碼行數:11,代碼來源:RampArchivingDlgViewModel.cs

示例3: GetFlags

 static IEnumerable<Enum> GetFlags(Enum input)
 {
     foreach (Enum value in Enum.GetValues(input.GetType()))
         if (input.HasFlag(value))
             yield return value;
 }
開發者ID:mauriciominella,項目名稱:PrototipoFazBem,代碼行數:6,代碼來源:ProductDetailViewModel.cs

示例4: HasFlag

 public static bool HasFlag(Enum value, Enum flag)
 {
     //Added in .NET 4.0
     return value.HasFlag(flag);
 }
開發者ID:qwertie,項目名稱:Theraot,代碼行數:5,代碼來源:EnumHelper.cs

示例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();
 }
開發者ID:Maxwolf,項目名稱:Resume,代碼行數:9,代碼來源:Person.cs

示例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);
 }
開發者ID:twinspire,項目名稱:twinspire,代碼行數:7,代碼來源:HotkeyOptions.cs

示例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");
開發者ID:c1sc0,項目名稱:elasticsearch-net,代碼行數:67,代碼來源:Enums.Generated.cs

示例8: HasFlag

 public static void HasFlag(Enum e, Enum flag, bool expected)
 {
     Assert.Equal(expected, e.HasFlag(flag));
 }
開發者ID:AndreGleichner,項目名稱:corefx,代碼行數:4,代碼來源:EnumTests.cs

示例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;
        }
開發者ID:darkalemanbr,項目名稱:MagmaGrimDawnToolkit,代碼行數:24,代碼來源:Arc.cs


注:本文中的System.Enum.HasFlag方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。