Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
AvoidDeepNamespaceHierarchyRule: Added overload of "Solution" propert…
Browse files Browse the repository at this point in the history
…y that is required when MaxDepth property has value different than 4

DisableDebuggingCodeRule & GetLastErrorMustBeCalledRightAfterPInvokeRule: fixed NullReferenceException-s (discovered during SharpSVN analyze)
  • Loading branch information
usarskyy committed Mar 26, 2012
1 parent 2d9fc5f commit 62692c1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Expand Up @@ -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;

Expand Down
Expand Up @@ -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":
Expand Down
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
}
}
}

0 comments on commit 62692c1

Please sign in to comment.