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


C# TypeDefinition.IsFlags方法代碼示例

本文整理匯總了C#中Mono.Cecil.TypeDefinition.IsFlags方法的典型用法代碼示例。如果您正苦於以下問題:C# TypeDefinition.IsFlags方法的具體用法?C# TypeDefinition.IsFlags怎麽用?C# TypeDefinition.IsFlags使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.Cecil.TypeDefinition的用法示例。


在下文中一共展示了TypeDefinition.IsFlags方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CheckType

        public RuleResult CheckType(TypeDefinition type)
        {
            // rule applies only to enums - but not enums marked with [Flags] attribute
            if (!type.IsEnum || type.IsFlags ())
                return RuleResult.DoesNotApply;

            // rule applies

            if (!IsPlural (type.Name))
                return RuleResult.Success;

            Runner.Report (type, Severity.Medium, Confidence.Normal);
            return RuleResult.Failure;
        }
開發者ID:FreeBSD-DotNet,項目名稱:mono-tools,代碼行數:14,代碼來源:UseSingularNameInEnumsUnlessAreFlagsRule.cs

示例2: CheckType

        public RuleResult CheckType(TypeDefinition type)
        {
            // rule applies only to enums with [Flags] attribute
            if (!type.IsFlags ())
                return RuleResult.DoesNotApply;

            // rule applies

            if (IsPlural (type.Name))
                return RuleResult.Success;

            // Confidence == Normal because valid names may end with 's'
            Runner.Report (type, Severity.Low, Confidence.Normal);
            return RuleResult.Failure;
        }
開發者ID:alfredodev,項目名稱:mono-tools,代碼行數:15,代碼來源:UsePluralNameInEnumFlagsRule.cs

示例3: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule apply only on [Flags] (this takes care of checking for enums)
			if (!type.IsFlags ())
				return RuleResult.DoesNotApply;

			// rule applies!

			FieldDefinition field = GetZeroValueField (type);
			if (field == null)
				return RuleResult.Success;

			// it's less likely an error if the field is named "None"
			Severity s = field.Name == "None" ? Severity.Medium : Severity.High;
			Runner.Report (field, s, Confidence.Total);
			return RuleResult.Failure;
		}
開發者ID:FreeBSD-DotNet,項目名稱:mono-tools,代碼行數:17,代碼來源:FlagsShouldNotDefineAZeroValueRule.cs

示例4: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule apply only on enums
			if (!type.IsEnum)
				return RuleResult.DoesNotApply;

			// rule doesn't apply on [Flags]
			if (type.IsFlags ())
				return RuleResult.DoesNotApply;

			// rule applies!

			FieldDefinition field = GetZeroValueField (type);
			if (field != null)
				return RuleResult.Success;

			Runner.Report (type, Severity.Low, Confidence.Total);
			return RuleResult.Failure;
		}
開發者ID:FreeBSD-DotNet,項目名稱:mono-tools,代碼行數:19,代碼來源:EnumsShouldDefineAZeroValueRule.cs

示例5: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			if (!type.IsEnum)
				return RuleResult.DoesNotApply;

			if (type.IsFlags ())
				return RuleResult.DoesNotApply;

			GetValues (type);
			if (values.Count < 3)
				return RuleResult.Success;

#if DEBUG
			Log.WriteLine (this);
			Log.WriteLine (this, "------------------------------------");
			Log.WriteLine (this, type.FullName);
			Log.WriteLine (this, "values: {0}", string.Join (" ", (from x in values select x.ToString ("X4")).ToArray ()));
#endif

			int numFlags = 0;
			int numMasks = 0;
			foreach (ulong value in values) {
				if (IsPowerOfTwo (value))
					++numFlags;
				else if (IsBitmask (value))
					++numMasks;
			}
			
			Log.WriteLine (this, "numFlags: {0}", numFlags);
			Log.WriteLine (this, "numMasks: {0}", numMasks);

			// The enum is bad if all of the values are powers of two or composed 
			// of defined powers of two,
			if (numFlags + numMasks == values.Count) {
				values.Sort ();		// sometimes enums are all sequential but not in order
				
				int numSequential = CountSequential ();				
				Log.WriteLine (this, "numSequential: {0}", numSequential);

				// and there are not too many sequential values (so we don't
				// complain about stuff like 1, 2, 3, 4, 5, 6).
				if (numSequential < 3) {
					Confidence confidence = values.Count >= 4 && numMasks == 0 ? Confidence.High : Confidence.Normal;
					Runner.Report (type, Severity.Medium, confidence);
				}
			}

			return Runner.CurrentRuleResult;
		}
開發者ID:nolanlum,項目名稱:mono-tools,代碼行數:49,代碼來源:UseFlagsAttributeRule.cs


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