本文整理汇总了C#中Mono.Cecil.TypeDefinition.GetMethod方法的典型用法代码示例。如果您正苦于以下问题:C# TypeDefinition.GetMethod方法的具体用法?C# TypeDefinition.GetMethod怎么用?C# TypeDefinition.GetMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.TypeDefinition
的用法示例。
在下文中一共展示了TypeDefinition.GetMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// that will cover interfaces, delegates too
if (!type.HasFields)
return RuleResult.DoesNotApply;
// rule doesn't apply to enums, interfaces, structs, delegates or generated code
if (type.IsEnum || type.IsValueType || type.IsGeneratedCode ())
return RuleResult.DoesNotApply;
MethodDefinition explicitDisposeMethod = null;
MethodDefinition implicitDisposeMethod = null;
bool abstractWarning = false;
if (type.Implements ("System", "IDisposable")) {
implicitDisposeMethod = type.GetMethod (MethodSignatures.Dispose);
explicitDisposeMethod = type.GetMethod (MethodSignatures.DisposeExplicit);
if (IsAbstract (implicitDisposeMethod) || IsAbstract (explicitDisposeMethod)) {
abstractWarning = true;
} else {
return RuleResult.Success;
}
}
FieldCandidates.Clear ();
foreach (FieldDefinition field in type.Fields) {
// we can't dispose static fields in IDisposable
if (field.IsStatic)
continue;
TypeDefinition fieldType = field.FieldType.GetElementType ().Resolve ();
if (fieldType == null)
continue;
if (FieldTypeIsCandidate (fieldType))
FieldCandidates.Add (field);
}
// if there are fields types that implements IDisposable
if (type.HasMethods && (FieldCandidates.Count > 0)) {
// check if we're assigning new object to them
foreach (MethodDefinition method in type.Methods) {
CheckMethod (method, abstractWarning);
}
}
// Warn about possible confusion if the Dispose methods are abstract
if (IsAbstract (implicitDisposeMethod))
Runner.Report (implicitDisposeMethod, Severity.Medium, Confidence.High, AbstractDisposeMessage);
return Runner.CurrentRuleResult;
}
示例2: 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;
}
示例3: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// rules applies to types that overrides System.Object.Equals(object)
MethodDefinition method = type.GetMethod (MethodSignatures.ToString);
if ((method == null) || !method.HasBody)
return RuleResult.DoesNotApply;
// call base class to detect if the method can return null
return CheckMethod (method);
}
示例4: 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;
}
示例5: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// handle System.Object (which can't call base class)
if (type.BaseType == null)
return RuleResult.DoesNotApply;
MethodDefinition finalizer = type.GetMethod (MethodSignatures.Finalize);
if (finalizer == null) // no finalizer found
return RuleResult.DoesNotApply;
if (IsBaseFinalizeCalled (finalizer))
return RuleResult.Success;
Runner.Report (finalizer, Severity.Critical, Confidence.Total);
return RuleResult.Failure;
}
示例6: CheckCallingBaseMethod
private void CheckCallingBaseMethod (TypeDefinition type, MethodSignature methodSignature)
{
MethodDefinition method = type.GetMethod (methodSignature);
if (method == null)
return; // Perhaps should report that doesn't exist the method (only with ctor).
foreach (Instruction instruction in method.Body.Instructions) {
if (instruction.OpCode.FlowControl == FlowControl.Call) {
MethodReference operand = (MethodReference) instruction.Operand;
if (methodSignature.Matches (operand) && type.Inherits (operand.DeclaringType.ToString ()))
return;
}
}
Runner.Report (method, Severity.High, Confidence.High, String.Format ("The method {0} isn't calling its base method.", method));
}
示例7: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// rules applies to types that overrides System.Object.Equals(object)
MethodDefinition method = type.GetMethod (MethodSignatures.Equals);
if ((method == null) || !method.HasBody || method.IsStatic)
return RuleResult.DoesNotApply;
// rule applies
// scan IL to see if null is checked and false returned
if (CheckSequence (method.Body.Instructions [0], type))
return RuleResult.Success;
Runner.Report (method, Severity.Medium, Confidence.High);
return RuleResult.Failure;
}
示例8: 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;
int n = 0;
Severity severity = Severity.Medium;
bool use_structure = false;
// check parameters for 'ref', 'out', 'params'
if (invoke.HasParameters) {
IList<ParameterDefinition> pdc = invoke.Parameters;
n = pdc.Count;
// too many parameters to directly use Action/Func
// so we lower severity and suggest grouping them
if (n > ((type.Module.Runtime >= TargetRuntime.Net_4_0) ? 16 : 4)) {
severity = Severity.Low;
n = 1;
use_structure = true;
}
// special cases not directly usable with Action/Func
foreach (ParameterDefinition pd in pdc) {
if (pd.IsOut || pd.ParameterType.IsByReference || pd.IsParams ())
return RuleResult.Success;
}
}
string msg = invoke.ReturnType.IsNamed ("System", "Void") ? ActionMessage [n] : FuncMessage [n];
if (use_structure)
msg += " and use a structure to hold all your parameters into <T>.";
Runner.Report (type, severity, Confidence.High, msg);
return Runner.CurrentRuleResult;
}
示例9: CheckType
public RuleResult CheckType (TypeDefinition type)
{
if (!type.IsSerializable || !type.Implements ("System.Runtime.Serialization.ISerializable"))
return RuleResult.DoesNotApply;
MethodDefinition getObjectData = type.GetMethod (MethodSignatures.GetObjectData);
if (getObjectData != null) {
CheckUnusedFieldsIn (type, getObjectData);
CheckExtensibilityFor (type, getObjectData);
}
return Runner.CurrentRuleResult;
}
示例10: CacheTypeGetStoreMethod
private MethodDefinition CacheTypeGetStoreMethod(TypeDefinition cacheInterface, string cacheTypeStoreMethodName)
{
return cacheInterface.GetMethod(cacheTypeStoreMethodName, cacheInterface.Module.ImportType(typeof(void)),
new[] { cacheInterface.Module.ImportType<string>(), cacheInterface.Module.ImportType<object>() });
}
示例11: CacheTypeGetRetrieveMethod
private MethodDefinition CacheTypeGetRetrieveMethod(TypeDefinition cacheType, string cacheTypeRetrieveMethodName)
{
return cacheType.GetMethod(cacheTypeRetrieveMethodName, new GenericParameter("T", cacheType),
new[] { cacheType.Module.ImportType<string>() });
}
示例12: CacheTypeGetRemoveMethod
private MethodDefinition CacheTypeGetRemoveMethod(TypeDefinition cacheType, string cacheTypeRemoveMethodName)
{
return cacheType.GetMethod(cacheTypeRemoveMethodName, ModuleDefinition.TypeSystem.Void,
new[] { cacheType.Module.ImportType<string>() });
}
示例13: CheckType
public RuleResult CheckType (TypeDefinition type)
{
if (!type.HasFields || type.IsEnum)
return RuleResult.DoesNotApply;
Log.WriteLine (this);
Log.WriteLine (this, "----------------------------------");
Log.WriteLine (this, type.FullName);
FieldDefinition field = FindIntPtr (type);
if (field != null) {
Confidence confidence = Confidence.Low;
MethodDefinition finalizer = type.GetMethod (MethodSignatures.Finalize);
if (finalizer != null)
confidence = (Confidence) ((int) confidence - 1); // lower numbers have higher confidence
if (type.Implements ("System.IDisposable"))
confidence = (Confidence) ((int) confidence - 1);
Log.WriteLine (this, "'{0}' is an IntPtr.", field.Name);
Runner.Report (field, Severity.Medium, confidence);
}
return Runner.CurrentRuleResult;
}
示例14: CheckType
public RuleResult CheckType (TypeDefinition type)
{
if (!type.IsSerializable || !type.Implements ("System.Runtime.Serialization", "ISerializable"))
return RuleResult.DoesNotApply;
MethodDefinition getObjectData = type.GetMethod (MethodSignatures.GetObjectData);
if (getObjectData == null) {
// no GetObjectData means that the type's ancestor does the job but
// are we introducing new instance fields that need to be serialized ?
if (!type.HasFields)
return RuleResult.Success;
// there are some, but they could be static
foreach (FieldDefinition field in type.Fields) {
if (!field.IsStatic)
Runner.Report (field, Severity.Medium, Confidence.High);
}
} else {
if (type.HasFields)
CheckUnusedFieldsIn (type, getObjectData);
if (!type.IsSealed && getObjectData.IsFinal) {
string msg = "Either seal this type or change GetObjectData method to be virtual";
Runner.Report (getObjectData, Severity.High, Confidence.Total, msg);
}
}
return Runner.CurrentRuleResult;
}
示例15: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// rule does not apply to enums, delegates and to generated code
if (type.IsEnum || type.IsDelegate () || type.IsGeneratedCode ())
return RuleResult.DoesNotApply;
// rule applies only if the type overrides Equals(object)
if (!type.HasMethod (MethodSignatures.Equals))
return RuleResult.DoesNotApply;
// if so then the type should also implement Equals(type) since this avoid a cast
// operation (for reference types) and also boxing (for value types).
// we suggest to implement IEquatable<T> if
// * the assembly targets the 2.0 (or later) runtime
// * and it does not already implement it
if (type.Module.Runtime >= TargetRuntime.Net_2_0) {
if (!type.Implements ("System", "IEquatable`1")) {
Runner.Report (type, Severity.Medium, Confidence.Total, "Implement System.IEquatable<T>");
}
return Runner.CurrentRuleResult;
}
parameters [0] = type.GetFullName ();
if (type.GetMethod (MethodAttributes.Public, "Equals", "System.Boolean", parameters) != null)
return RuleResult.Success;
// we consider this a step more severe for value types since it will need
// boxing/unboxing with Equals(object)
Severity severity = type.IsValueType ? Severity.Medium : Severity.Low;
string msg = String.Format (CultureInfo.InvariantCulture, "Implement 'bool Equals({0})'", type.Name);
Runner.Report (type, severity, Confidence.High, msg);
return RuleResult.Failure;
}