本文整理汇总了C#中Mono.Cecil.TypeDefinition.IsDelegate方法的典型用法代码示例。如果您正苦于以下问题:C# TypeDefinition.IsDelegate方法的具体用法?C# TypeDefinition.IsDelegate怎么用?C# TypeDefinition.IsDelegate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.TypeDefinition
的用法示例。
在下文中一共展示了TypeDefinition.IsDelegate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// rule does not apply to interface (since [Serializable] is not applicable to interfaces)
// nor does it apply to delegates
if (type.IsInterface || type.IsDelegate ())
return RuleResult.DoesNotApply;
// rule does not apply if the type does not implements ISerializable
if (!type.Implements ("System.Runtime.Serialization", "ISerializable"))
return RuleResult.DoesNotApply;
// rule applies only if base type is serializable
if (!type.BaseType.IsNamed ("System", "Object")) {
TypeDefinition base_type = type.BaseType.Resolve ();
// in doubt don't report
if ((base_type == null) || !base_type.IsSerializable)
return RuleResult.DoesNotApply;
}
// rule applies, only Success or Failure from the point on
// ok if the type has the [Serializable] pseudo-attribute
if (type.IsSerializable)
return RuleResult.Success;
Runner.Report (type, Severity.Critical, Confidence.Total);
return RuleResult.Failure;
}
示例2: Create
/// <summary>
/// Create a type builder for the given type.
/// </summary>
internal static IClassBuilder[] Create(ReachableContext context, AssemblyCompiler compiler, TypeDefinition typeDef)
{
if (typeDef.FullName == "<Module>")
return new IClassBuilder[] { new SkipClassBuilder() };
if (typeDef.IsDelegate())
return new IClassBuilder[] {new DelegateClassBuilder(context, compiler, typeDef) };
if (typeDef.IsAttribute())
return new IClassBuilder[] {new AttributeClassBuilder(context, compiler, typeDef) };
if (typeDef.IsAnnotation())
return new IClassBuilder[] {new AnnotationClassBuilder(context, compiler, typeDef) };
if (typeDef.HasDexImportAttribute())
return new IClassBuilder[] {new DexImportClassBuilder(context, compiler, typeDef) };
if (typeDef.HasJavaImportAttribute())
return new IClassBuilder[] {CreateJavaImportBuilder(context, compiler, typeDef)};
if (typeDef.IsEnum)
{
if (typeDef.UsedInNullableT)
{
var nullableBaseClassBuilder = new NullableEnumBaseClassBuilder(context, compiler, typeDef);
IClassBuilder builder = new EnumClassBuilder(context, compiler, typeDef, nullableBaseClassBuilder);
return new[] { builder, nullableBaseClassBuilder };
}
return new IClassBuilder[] { new EnumClassBuilder(context, compiler, typeDef, null) };
}
else
{
IClassBuilder builder = new StandardClassBuilder(context, compiler, typeDef);
if (typeDef.UsedInNullableT)
return new[] { builder, new NullableBaseClassBuilder(context, compiler, typeDef) };
return new[] { builder };
}
}
示例3: CheckType
public RuleResult CheckType(TypeDefinition type)
{
// rule applies only to types and interfaces
if (type.IsEnum || type.IsDelegate() || type.IsGeneratedCode() ||
type.IsValueType || type.IsInterface)
return RuleResult.DoesNotApply;
// rule only applies to type that implements IDisposable
if (!type.Implements("System", "IDisposable"))
return RuleResult.DoesNotApply;
// rule only applies to type that doesn't derive from class that implements IDisposable
if (type.BaseType.Implements("System", "IDisposable"))
return RuleResult.DoesNotApply;
// rule only applies if type has a Dispose(bool) method
if (!type.HasMethod(Dispose))
return RuleResult.DoesNotApply;
// no problem if a finalizer is found
if (type.HasMethod(MethodSignatures.Finalize))
return RuleResult.Success;
Runner.Report(type, Severity.Medium, Confidence.High);
return RuleResult.Failure;
}
示例4: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// rule applies only to types, interfaces and structures (value types)
if (type.IsEnum || type.IsDelegate () || type.IsGeneratedCode ())
return RuleResult.DoesNotApply;
// rule onyly applies to type that implements IDisposable
if (!type.Implements ("System.IDisposable"))
return RuleResult.DoesNotApply;
// no problem is a finalizer is found
if (type.HasMethod (MethodSignatures.Finalize))
return RuleResult.Success;
// otherwise check for native types
foreach (FieldDefinition field in type.Fields) {
// we can't dispose static fields in IDisposable
if (field.IsStatic)
continue;
if (!field.FieldType.GetElementType ().IsNative ())
continue;
Runner.Report (field, Severity.High, Confidence.High);
}
// special case: a struct cannot define a finalizer so it's a
// bad candidate to hold references to unmanaged resources
if (type.IsValueType && (Runner.CurrentRuleResult == RuleResult.Failure))
Runner.Report (type, Severity.High, Confidence.High, Struct);
return Runner.CurrentRuleResult;
}
示例5: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// rule only apply to (non generated) delegates
if (!type.IsDelegate () || type.IsGeneratedCode ())
return RuleResult.DoesNotApply;
MethodDefinition invoke = type.GetMethod ("Invoke");
// this happens for System.MulticastDelegate
if (invoke == null)
return RuleResult.DoesNotApply;
if (!invoke.ReturnType.IsNamed ("System", "Void"))
return RuleResult.Success;
if (!invoke.HasParameters)
return RuleResult.Success;
IList<ParameterDefinition> pdc = invoke.Parameters;
if (pdc.Count != 2)
return RuleResult.Success;
if (!pdc [0].ParameterType.IsNamed ("System", "Object"))
return RuleResult.Success;
if (!pdc [1].ParameterType.Inherits ("System", "EventArgs"))
return RuleResult.Success;
Runner.Report (type, Severity.Medium, Confidence.High);
return RuleResult.Failure;
}
示例6: CheckType
public RuleResult CheckType (TypeDefinition type)
{
if (type.IsInterface || type.IsValueType || type.IsDelegate ())
return RuleResult.DoesNotApply;
int depth = 0;
while (type.BaseType != null) {
type = type.BaseType.Resolve ();
if (type == null)
break;
if (countExternalDepth || Runner.Assemblies.Contains (type.Module.Assembly))
depth++;
}
if (depth <= MaximumDepth)
return RuleResult.Success;
// Confidence is total unless we count outside the current assembly,
// where it's possible we can't resolve up to System.Object
Confidence confidence = countExternalDepth ? Confidence.High : Confidence.Total;
// Severity is based on the depth
string msg = String.Format (CultureInfo.CurrentCulture, "Inheritance tree depth : {0}.", depth);
Runner.Report (type, GetSeverity (depth), confidence, msg);
return RuleResult.Failure;
}
示例7: CheckType
public RuleResult CheckType (TypeDefinition type)
{
//does rule apply?
if (type.IsEnum || type.IsInterface || type.IsAbstract || type.IsDelegate () || type.IsGeneratedCode ())
return RuleResult.DoesNotApply;
if (!type.HasFields || (type.Fields.Count < MinimumFieldCount))
return RuleResult.DoesNotApply;
if (!type.HasMethods || (type.Methods.Count < MinimumMethodCount))
return RuleResult.DoesNotApply;
//yay! rule do apply!
double coh = GetCohesivenessForType (type);
if (coh >= SuccessLowerLimit)
return RuleResult.Success;
if (0 == coh)
return RuleResult.DoesNotApply;
//how's severity?
Severity sev = GetCohesivenessSeverity(coh);
string msg = String.Format (CultureInfo.CurrentCulture, "Type cohesiveness : {0}%", (int) (coh * 100));
Runner.Report (type, sev, Confidence.Normal, msg);
return RuleResult.Failure;
}
示例8: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// rule doesn't apply on enums, interfaces, delegates or to compiler/tools-generated code
// e.g. CSC compiles anonymous methods as an inner type that expose public fields
if (type.IsEnum || type.IsInterface || !type.HasFields || type.IsDelegate () || type.IsGeneratedCode ())
return RuleResult.DoesNotApply;
// rule doesn't apply to type non (externally) visible
if (!type.IsVisible ())
return RuleResult.DoesNotApply;
foreach (FieldDefinition fd in type.Fields) {
if (!fd.IsVisible () || fd.IsSpecialName || fd.HasConstant || fd.IsInitOnly)
continue;
string name = fd.Name;
if (fd.FieldType.IsArray) {
string s = String.Format (CultureInfo.InvariantCulture,
"Consider changing the field '{0}' to a private or internal field and add a 'Set{1}{2}' method.",
name, Char.ToUpper (name [0], CultureInfo.InvariantCulture).ToString (CultureInfo.InvariantCulture), name.Substring (1));
Runner.Report (fd, Severity.Medium, Confidence.Total, s);
} else {
string s = String.Format (CultureInfo.InvariantCulture,
"Field '{0}' should be private or internal and its value accessed through a property.", name);
Runner.Report (fd, Severity.Medium, Confidence.Total, s);
}
}
return Runner.CurrentRuleResult;
}
示例9: CheckType
public RuleResult CheckType (TypeDefinition type)
{
if (type.IsEnum || type.IsInterface || type.IsDelegate ())
return RuleResult.DoesNotApply;
MethodDefinition equality = type.GetMethod (MethodSignatures.op_Equality);
if ((equality == null) || type.HasMethod (MethodSignatures.Equals))
return RuleResult.Success;
Runner.Report (equality, Severity.High, Confidence.High);
return RuleResult.Failure;
}
示例10: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// rule does not apply to interface and enumerations
if (type.IsInterface || type.IsEnum || !type.HasFields || type.IsDelegate ())
return RuleResult.DoesNotApply;
foreach (FieldDefinition field in type.Fields) {
if (field.IsStatic && field.IsVisible () && !field.IsInitOnly && !field.IsLiteral) {
Runner.Report (field, Severity.Medium, Confidence.High);
}
}
return Runner.CurrentRuleResult;
}
示例11: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// rule does not apply to interface and enumerations
if (type.IsInterface || type.IsEnum || !type.HasFields || type.IsDelegate ())
return RuleResult.DoesNotApply;
foreach (FieldDefinition field in type.Fields) {
if (field.IsStatic && field.IsVisible () && !field.IsInitOnly && !field.IsLiteral) {
Runner.Report (field, Severity.Medium, Confidence.High, String.Format("Change the field \"{0}\" to read-only, or mark it [ThreadStatic], or make it non visible outside the assembly.", field.Name));
}
}
return Runner.CurrentRuleResult;
}
示例12: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// rule does not apply to interface, enumerations and delegates or to types without fields
if (type.IsInterface || type.IsEnum || !type.HasFields || type.IsDelegate ())
return RuleResult.DoesNotApply;
foreach (FieldDefinition field in type.Fields) {
//IsInitOnly == readonly
if (field.IsInitOnly && field.IsVisible () && field.FieldType.IsArray) {
// Medium = this will work as long as no code starts "playing" with the array values
Runner.Report (field, Severity.Medium, Confidence.Total);
}
}
return Runner.CurrentRuleResult;
}
示例13: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// rule applies only to sealed types, but not to enum, value types and delegate (sealed)
if (!type.IsSealed || type.IsEnum || type.IsValueType || type.IsDelegate ())
return RuleResult.DoesNotApply;
foreach (MethodDefinition method in type.Methods) {
// method is virtual and not final (sealed)
if (method.IsVirtual && !method.IsFinal) {
// so just make sure it's not an override of an ancestor
if (!method.IsOverride ())
Runner.Report (method, Severity.Low, Confidence.Total);
}
}
return Runner.CurrentRuleResult;
}
示例14: CheckType
public RuleResult CheckType (TypeDefinition type)
{
if (type.IsEnum || type.IsInterface || type.IsDelegate ())
return RuleResult.DoesNotApply;
// get the static constructor
MethodDefinition cctor = type.Methods.FirstOrDefault (m => m.IsConstructor && m.IsStatic);
if (cctor == null)
return RuleResult.DoesNotApply;
// check if we store things into static fields
if (!OpCodeEngine.GetBitmask (cctor).Get (Code.Stsfld))
return RuleResult.DoesNotApply;
// verify each store we do in a static field
foreach (Instruction ins in cctor.Body.Instructions) {
if (ins.OpCode.Code != Code.Stsfld)
continue;
// make sure we assign to this type (and not another one)
FieldReference fr = (ins.Operand as FieldReference);
if (fr.DeclaringType != type)
continue;
// if it's this one then we have a FieldDefinition available
FieldDefinition field = (fr as FieldDefinition);
// check for static (we already know with Stsfld) and readonly
if (!field.IsInitOnly)
continue;
// look at what is being assigned
Instruction previous = ins.Previous;
// while skipping conversions
if (Convert.Get (previous.OpCode.Code))
previous = previous.Previous;
// and report constant stuff
if (Constant.Get (previous.OpCode.Code)) {
// adjust severity based on the field visibility and it's type
Severity s = (field.FieldType.IsNamed ("System", "String") || !field.IsVisible ()) ?
Severity.High : Severity.Medium;
Runner.Report (field, s, Confidence.Normal);
}
}
return Runner.CurrentRuleResult;
}
示例15: CheckType
public RuleResult CheckType(TypeDefinition type)
{
// rule does not apply to interface, enumerations and delegates or to types without fields
if (type.IsInterface || type.IsEnum || !type.HasFields || type.IsDelegate ())
return RuleResult.DoesNotApply;
foreach (FieldDefinition field in type.Fields) {
if (!field.IsVisible ())
continue;
//not readonly native fields or arrays of native fields
if ((field.FieldType.IsNative () && !field.IsInitOnly) ||
(field.FieldType.IsArray && field.FieldType.GetElementType ().IsNative ())) {
Runner.Report (field, Severity.Medium, Confidence.Total);
}
}
return Runner.CurrentRuleResult;
}