NDepend放弃具有属性的类型的方法



如何丢弃具有属性的类型(下面的示例)中的所有方法(作为notmycode)?

例如,我有一个类型为:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
 public partial class OperatorSession { ... }

感谢

查询是:

// <Name>Not my code, methods tagged with GeneratedCodeAttribute</Name>
notmycode from t in Application.Types
where t.HasAttribute ("System.CodeDom.Compiler.GeneratedCodeAttribute".AllowNoMatch())
select t

请注意,类型的默认notmycode查询已经考虑了用GeneratedCodeAttribute标记的方法。

// <Name>Discard generated Types from JustMyCode</Name>
// --- Make sure to make this query richer to discard generated types from NDepend rules results ---
notmycode
from t in Application.Types where
  // Resources, Settings, or typed DataSet generated types for example, are tagged with this attribute
  t.HasAttribute ("System.CodeDom.Compiler.GeneratedCodeAttribute".AllowNoMatch()) ||
  // This attributes identifies a type or member that is not part of the user code for an application.
  t.HasAttribute ("System.Diagnostics.DebuggerNonUserCodeAttribute".AllowNoMatch()) ||
  // Delegate types are always generated
  t.IsDelegate ||
  // Discard ASP.NET page types generated by aspnet_compiler.exe
  // See: http://www.ndepend.com/FAQ.aspx#ASPNET
  t.ParentNamespace.Name.EqualsAny("ASP", "__ASP") ||
  // Discard generated type ContractException
  t.Name == "__ContractsRuntime+ContractException" ||
  t.FullName == "System.Diagnostics.Contracts.RuntimeContractsAttribute" ||
  t.FullName == "System.Diagnostics.Contracts.__ContractsRuntime" ||
  // Discard all types declared in a folder path containing the word "generated"
  (t.SourceFileDeclAvailable &&
   t.SourceDecls.All(s => s.SourceFile.FilePath.ParentDirectoryPath.ToString().ToLower().Contains("generated")))
select new { t, t.NbILInstructions }

相关内容

  • 没有找到相关文章

最新更新