diff --git a/gendarme/rules/Gendarme.Rules.BadPractice/DisableDebuggingCodeRule.cs b/gendarme/rules/Gendarme.Rules.BadPractice/DisableDebuggingCodeRule.cs index ccb7a8a24..d5393756e 100644 --- a/gendarme/rules/Gendarme.Rules.BadPractice/DisableDebuggingCodeRule.cs +++ b/gendarme/rules/Gendarme.Rules.BadPractice/DisableDebuggingCodeRule.cs @@ -151,7 +151,11 @@ public RuleResult CheckMethod (MethodDefinition method) continue; // ... to System.Console ... - MethodReference mr = (ins.Operand as MethodReference); + MethodReference mr = ins.Operand as MethodReference; + + if (mr == null) + continue; + if (!mr.DeclaringType.IsNamed ("System", "Console")) continue; diff --git a/gendarme/rules/Gendarme.Rules.Interoperability/GetLastErrorMustBeCalledRightAfterPInvokeRule.cs b/gendarme/rules/Gendarme.Rules.Interoperability/GetLastErrorMustBeCalledRightAfterPInvokeRule.cs index 63655d039..37b5dad90 100644 --- a/gendarme/rules/Gendarme.Rules.Interoperability/GetLastErrorMustBeCalledRightAfterPInvokeRule.cs +++ b/gendarme/rules/Gendarme.Rules.Interoperability/GetLastErrorMustBeCalledRightAfterPInvokeRule.cs @@ -135,12 +135,17 @@ private bool CheckPInvoke (Instruction startInstruction) //check if a method is called if (ins.OpCode.FlowControl == FlowControl.Call) { + MethodReference mRef = ins.Operand as MethodReference; - MethodDefinition mDef = (ins.Operand as MethodReference).Resolve (); + if (mRef == null) { + continue; + } + + MethodDefinition mDef = mRef.Resolve(); if (mDef != null && mDef.IsPInvokeImpl) { //check if another pinvoke method is called, this counts as "GetLastError not called" break; } - + string s = (mDef == null) ? String.Empty : mDef.DeclaringType.GetFullName (); switch (s) { case "System.Runtime.InteropServices.Marshal": diff --git a/gendarme/rules/Gendarme.Rules.Naming/AvoidDeepNamespaceHierarchyRule.cs b/gendarme/rules/Gendarme.Rules.Naming/AvoidDeepNamespaceHierarchyRule.cs index a49442f3c..ac7756b11 100644 --- a/gendarme/rules/Gendarme.Rules.Naming/AvoidDeepNamespaceHierarchyRule.cs +++ b/gendarme/rules/Gendarme.Rules.Naming/AvoidDeepNamespaceHierarchyRule.cs @@ -96,7 +96,10 @@ public class AvoidDeepNamespaceHierarchyRule : Rule, IAssemblyRule { [DefaultValue (DefaultMaxDepth)] [Description ("The depth at which namespaces may be nested without triggering a defect.")] public int MaxDepth { - get { return max_depth; } + get + { + return max_depth; + } set { if (value < 1) throw new ArgumentOutOfRangeException ("MaxDepth", "Minimum: 1"); @@ -149,5 +152,14 @@ public RuleResult CheckAssembly (AssemblyDefinition assembly) } return Runner.CurrentRuleResult; } + + public override string Solution + { + get + { + return string.Format("Try to keep the depth below {0}, with an additional one for specialization (e.g. Design, Interop, Permissions).", + MaxDepth); + } + } } }