本文整理汇总了C#中Mono.Cecil.TypeDefinition.Inherits方法的典型用法代码示例。如果您正苦于以下问题:C# TypeDefinition.Inherits方法的具体用法?C# TypeDefinition.Inherits怎么用?C# TypeDefinition.Inherits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.TypeDefinition
的用法示例。
在下文中一共展示了TypeDefinition.Inherits方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessType
public override void ProcessType(TypeDefinition type)
{
if (!type.Inherits ("Android.App.Application"))
return;
ProcessAttributeProvider (type);
}
示例2: 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));
}
示例3: IsImplementor
static bool IsImplementor(TypeDefinition type)
{
return type.Name.EndsWith ("Implementor") && type.Inherits ("Java.Lang.Object");
}
示例4: IsTypeConverter
static bool IsTypeConverter(TypeDefinition type)
{
return type.Inherits ("System.ComponentModel", "TypeConverter");
}
示例5: IsWebServiceClient
static bool IsWebServiceClient (TypeDefinition type)
{
return type.Inherits ("System.Web.Services.Protocols", "SoapHttpClientProtocol");
}
示例6: CheckType
public RuleResult CheckType(TypeDefinition type)
{
if (type.IsEnum || type.IsInterface || !type.HasFields)
return RuleResult.DoesNotApply;
Log.WriteLine (this);
Log.WriteLine (this, "----------------------------------");
bool isWinFormControl = usesWinForms && type.Inherits ("System.Windows.Forms", "Control");
// All fields start out as always null and unused.
foreach (FieldDefinition field in type.Fields) {
if (field.IsPrivate && !field.FieldType.IsValueType)
if (!isWinFormControl || field.Name != "components") // the winforms designer seems to like to leave this null
nullFields.Add (field);
}
CheckMethods (type);
if (type.HasNestedTypes) {
foreach (TypeDefinition nested in type.NestedTypes)
CheckMethods (nested);
}
// Report a defect if:
// 1) The field is explicitly set to null and not used (if
// if is implicitly set to null and not used AvoidUnusedPrivateFieldsRule
// will catch it).
setFields.IntersectWith (nullFields);
setFields.ExceptWith (usedFields);
if (setFields.Count > 0) {
foreach (FieldDefinition field in setFields) {
Log.WriteLine (this, "{0} is always null", field.Name);
Runner.Report (field, Severity.Medium, Confidence.High);
}
}
// 2) The field is always null and used somewhere.
nullFields.IntersectWith (usedFields);
if (nullFields.Count > 0) {
foreach (FieldDefinition field in nullFields) {
Log.WriteLine (this, "{0} is always null", field.Name);
Runner.Report (field, Severity.Medium, Confidence.High);
}
}
nullFields.Clear ();
setFields.Clear ();
usedFields.Clear ();
return Runner.CurrentRuleResult;
}
示例7: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// rule apply only to type that inherits from System.Exception
if (!type.Inherits (Exception))
return RuleResult.DoesNotApply;
// rule applies, only Success or Failure from the point on
// check if the type implements all the needed exception constructors
bool empty_ctor = false; // MyException ()
bool string_ctor = false; // MyException (string message)
bool inner_exception_ctor = false; // MyException (string message, Exception innerException)
bool serialization_ctor = false; // MyException (SerializationInfo info, StreamingContext context)
foreach (MethodDefinition ctor in type.GetConstructors ()) {
// skip cctor
if (ctor.IsStatic)
continue;
if (!ctor.HasParameters) {
// there can be only one so only it's visibility matters
empty_ctor = ctor.IsPublic;
continue;
}
switch (ctor.Parameters.Count) {
case 1:
string_ctor |= CheckForStringConstructor (ctor);
break;
case 2:
if (ctor.IsPublic) {
if (!inner_exception_ctor) {
inner_exception_ctor = CheckForInnerExceptionConstructor (ctor);
if (inner_exception_ctor)
break;
}
string_ctor |= CheckForStringConstructor (ctor);
} else {
serialization_ctor |= CheckForSerializationConstructor (ctor);
}
break;
default:
inner_exception_ctor |= CheckForInnerExceptionConstructor (ctor);
break;
}
}
if (!empty_ctor) {
string s = String.Format (MissingConstructor, "public", type.Name, "()");
Runner.Report (type, Severity.High, Confidence.Total, s);
}
if (!string_ctor) {
string s = String.Format (MissingConstructor, "public", type.Name, "(string message)");
Runner.Report (type, Severity.High, Confidence.Total, s);
}
if (!inner_exception_ctor) {
string s = String.Format (MissingConstructor, "public", type.Name,
"(string message, Exception innerException)");
Runner.Report (type, Severity.High, Confidence.Total, s);
}
if (!serialization_ctor) {
string s = String.Format (MissingConstructor, (type.IsSealed) ? "private" : "protected",
type.Name, "(SerializationInfo info, StreamingContext context)");
Runner.Report (type, Severity.High, Confidence.Total, s);
}
return Runner.CurrentRuleResult;
}
示例8: CheckType
public RuleResult CheckType (TypeDefinition type)
{
if (!type.IsClass || !type.HasMethods || !type.Inherits ("System.Windows.FrameworkElement"))
return RuleResult.DoesNotApply;
var arrangeOverride = type.GetMethod (arrangeSignature);
var measureOverride = type.GetMethod (measureSignature);
// The class doesn't have either method.
if (arrangeOverride == null && measureOverride == null)
return RuleResult.DoesNotApply;
// Only ArrangeOverride provided.
if (arrangeOverride != null && measureOverride == null)
Runner.Report (arrangeOverride, Severity.High, Confidence.Total);
// Only MeasureOverride provided.
if (measureOverride != null && arrangeOverride == null)
Runner.Report (measureOverride, Severity.High, Confidence.Total);
return Runner.CurrentRuleResult;
}