public RuleResult CheckAssembly(AssemblyDefinition assembly) { // check every namespaces inside the assembly using the NamespaceEngine foreach (string ns in NamespaceEngine.NamespacesInside(assembly)) { // rule only apply to "internal" namespaces if (!ns.EndsWith(".Internal", StringComparison.Ordinal) && !ns.EndsWith(".Impl", StringComparison.Ordinal)) { continue; } foreach (TypeDefinition type in NamespaceEngine.TypesInside(ns)) { // only report for this assembly if (type.Module.Assembly != assembly) { continue; } // report all types inside that namespace if (type.IsVisible()) { Runner.Report(type, Severity.Medium, Confidence.Total); } } } return(Runner.CurrentRuleResult); }
public RuleResult CheckAssembly(AssemblyDefinition assembly) { foreach (string ns in NamespaceEngine.NamespacesInside(assembly)) { CheckNamespace(ns); } return(Runner.CurrentRuleResult); }
public RuleResult CheckAssembly(AssemblyDefinition assembly) { MethodDefinition entry_point = assembly.EntryPoint; if (entry_point != null) { // for EXE assemblies ignore the namespace of the entry point ignore.AddIfNew(entry_point.DeclaringType.Namespace); } // ignore assemblies with a single namespace int count = 0; string single = null; foreach (string ns in NamespaceEngine.NamespacesInside(assembly)) { // no type inside the assembly if (ns == null) { break; } // only count if there are some visible types inside the namespace bool visible = false; foreach (TypeDefinition type in NamespaceEngine.TypesInside(ns)) { if (type.IsVisible()) { visible = true; break; } } if (visible) { single = ns; count++; } // no need to go more than 2 if (count > 1) { break; } } if (count == 1) { ignore.AddIfNew(single); } return(RuleResult.Success); }
public RuleResult CheckAssembly(AssemblyDefinition assembly) { // assembly names are very visible, severity == high CheckIdentifier(assembly, assembly.Name.Name, Severity.High); // check every namespaces inside the assembly using the NamespaceEngine // note: we don't reuse CheckIdentifier because we want to avoid // creating Namespace instance unless necessary foreach (string ns in NamespaceEngine.NamespacesInside(assembly)) { CheckIdentifier(NamespaceDefinition.GetDefinition(ns), ns, Severity.Medium); } return(Runner.CurrentRuleResult); }
public RuleResult CheckAssembly(AssemblyDefinition assembly) { if (!CheckName(assembly.Name.Name, false)) { Runner.Report(assembly, Severity.Medium, Confidence.High); } // check every namespaces inside the assembly using the NamespaceEngine foreach (string ns in NamespaceEngine.NamespacesInside(assembly)) { if (!CheckName(ns, false)) { Runner.Report(NamespaceDefinition.GetDefinition(ns), Severity.Medium, Confidence.High); } } return(Runner.CurrentRuleResult); }
public RuleResult CheckAssembly(AssemblyDefinition assembly) { // check every namespaces inside the assembly using the NamespaceEngine foreach (string ns in NamespaceEngine.NamespacesInside(assembly)) { // shortest invalid namespace would be "a.b.c.d.e" // so we can skip anything less than 2 * MaxDepth // note: overflow does not matter if (ns.Length < unchecked (MaxDepth + MaxDepth)) { continue; } // count the levels (i.e. number of dots + 1) int levels = CountLevels(ns); if (levels <= MaxDepth) { continue; } // we have some exceptions for namespace specialization // i.e. stuff we often prefer to have in a sub-namespace // and for internal (non-visible) namespaces if (levels == MaxDepth + 1) { if (NamespaceDefinition.IsSpecialized(ns)) { continue; } else if (ns.EndsWith(".Internal", StringComparison.Ordinal) || ns.EndsWith(".Impl", StringComparison.Ordinal)) { continue; } } Severity severity = (levels < MaxDepth * 2) ? Severity.Medium : Severity.High; Runner.Report(NamespaceDefinition.GetDefinition(ns), severity, Confidence.High); } return(Runner.CurrentRuleResult); }