本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}