本文整理汇总了C#中Mono.Cecil.TypeDefinition.IsStatic方法的典型用法代码示例。如果您正苦于以下问题:C# TypeDefinition.IsStatic方法的具体用法?C# TypeDefinition.IsStatic怎么用?C# TypeDefinition.IsStatic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.TypeDefinition
的用法示例。
在下文中一共展示了TypeDefinition.IsStatic方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanInstantiateType
static bool CanInstantiateType (TypeDefinition type)
{
// type is static (>= 2.0)
if (type.IsStatic ())
return false;
if (type.IsSealed && type.HasMethods) {
foreach (MethodDefinition ctor in type.Methods) {
if (ctor.IsConstructor && ctor.IsVisible ())
return true;
}
return false;
}
return true;
}
示例2: DoesTypeStealthilyImplementInterface
private static bool DoesTypeStealthilyImplementInterface (TypeDefinition type, TypeReference iface)
{
//ignore already uninteresting types below (self, enum, struct, static class)
if (type == iface || type.IsEnum || type.IsValueType || type.IsStatic ())
return false;
//if type has less methods than the interface no need to check further
if (!type.HasMethods)
return false;
IList<MethodDefinition> mdc = iface.GetMethods ().ToList ();
if (type.Methods.Count < mdc.Count)
return false;
//type already publicly says it implements the interface
if (type.Implements (iface.FullName))
return false;
foreach (MethodDefinition m in mdc) {
//if any candidate fails we can return right away
//since the interface will never be fully implemented
MethodDefinition candidate = type.GetMethod (MethodAttributes.Public, m.Name);
if (null == candidate || !candidate.IsPublic || candidate.IsStatic)
return false;
//ok interesting candidate! let's check if it matches the signature
if (!AreSameElementTypes (m.ReturnType, candidate.ReturnType))
return false;
if (!CompareParameters (m, candidate))
return false;
}
return true;
}
示例3: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// rule applies only if the type isn't: an enum, an interface, a struct, a delegate or compiler generated
if (type.IsEnum || type.IsInterface || type.IsValueType || type.IsDelegate () || type.IsGeneratedCode ())
return RuleResult.DoesNotApply;
// it also does not apply if the type is static (2.0+ only)
if (type.IsStatic ())
return RuleResult.DoesNotApply;
if (!IsAllStatic (type))
return RuleResult.Success;
// rule applies!
foreach (MethodDefinition ctor in type.Methods) {
if (ctor.IsConstructor && !ctor.IsStatic && ctor.IsVisible ()) {
Runner.Report (ctor, Severity.Low, Confidence.High);
}
}
return Runner.CurrentRuleResult;
}
示例4: DoesTypeStealthilyImplementInterface
private static bool DoesTypeStealthilyImplementInterface (TypeDefinition type, TypeDefinition iface)
{
//ignore already uninteresting types below (self, enum, struct, static class)
if (type == iface || type.IsEnum || type.IsValueType || type.IsStatic ())
return false;
//if type has less methods than the interface no need to check further
if (!type.HasMethods)
return false;
IList<MethodDefinition> mdc = iface.Methods;
if (type.Methods.Count < mdc.Count)
return false;
//type already publicly says it implements the interface
if (type.Implements (iface.Namespace, iface.Name))
return false;
foreach (MethodDefinition m in mdc) {
// FIXME: ignore methods with generic constraints
if (HasConstraints (m))
return false;
//if any candidate fails we can return right away
//since the interface will never be fully implemented
MethodDefinition candidate = type.GetMethod (MethodAttributes.Public, m.Name);
if (null == candidate || !candidate.IsPublic || candidate.IsStatic)
return false;
//ok interesting candidate! let's check if it matches the signature
if (!m.CompareSignature (candidate))
return false;
// FIXME: ignore methods with generic constraints
if (HasConstraints (candidate))
return false;
}
if (iface.HasInterfaces) {
foreach (TypeReference tr in iface.Interfaces) {
TypeDefinition td = tr.Resolve ();
if (td == null)
continue;
if (!DoesTypeStealthilyImplementInterface (type, td))
return false;
}
}
return true;
}
示例5: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// rule applies only if the type isn't: an enum, an interface, a struct, a delegate or compiler generated
if (type.IsEnum || type.IsInterface || type.IsValueType || !type.HasFields && GetMethodCount (type) == 0
|| type.IsDelegate () || type.IsGeneratedCode ()
|| type.BaseType != null && type.BaseType.FullName != "System.Object")
return RuleResult.DoesNotApply;
// success if the type is already static
if (type.IsStatic ())
return RuleResult.Success;
if (IsAllStatic (type)) {
// no technical reason not to use a static type exists
Runner.Report (type, Severity.Medium, Confidence.High);
}
return Runner.CurrentRuleResult;
}
示例6: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// rule applies only if the type isn't: an enum, an interface, a struct, a delegate or compiler generated
if (type.IsEnum || type.IsInterface || type.IsValueType || type.IsDelegate () || type.IsGeneratedCode ()
|| type.BaseType != null && !type.BaseType.IsNamed ("System", "Object"))
return RuleResult.DoesNotApply;
// success if the type is already static or, before 2.0, is it's sealed
if ((type.Module.Runtime >= TargetRuntime.Net_2_0) ? type.IsStatic () : type.IsSealed)
return RuleResult.Success;
if (IsAllStatic (type)) {
// no technical reason not to use a static type exists
Runner.Report (type, Severity.Medium, Confidence.High);
}
return Runner.CurrentRuleResult;
}