CodeCharter analyses your solution once and hands the DSL a cached code model. This page lists what you can query, sorted by entity type.
When you write a rule you navigate the model starting from a root collection. Property reads, method calls, LINQ chains, and at the end you collect the matches.
Root collections
Every query starts at one of these.
| Root | Element | Contents |
|---|---|---|
Types |
TypeModel |
All classes, structs, interfaces, enums, records |
Methods |
MethodModel |
All methods across all types |
Properties |
PropertyModel |
All properties |
Fields |
FieldModel |
All fields |
Events |
EventModel |
All events |
Namespaces |
NamespaceModel |
All namespaces |
Assemblies |
AssemblyModel |
One per project |
TypeDependencies |
TypeDependency |
Directed type-to-type dependencies |
SyntaxIssues |
SyntaxIssue |
Pre-analysed syntax patterns (see below) |
TypeModel
Identity:
Name string # without namespace
FullName string # Namespace.Type
Namespace string
Kind string # "Class" | "Interface" | "Struct" | "Enum"
Modifiers:
IsAbstract bool
IsSealed bool
IsStatic bool
IsPartial bool
AccessModifier string # "Public" | "Internal" | "Private" | "Protected"
Structural metrics:
LinesOfCode int
NumberOfMethods int
NumberOfFields int
NumberOfDerivedTypes int
WeightedMethodsPerClass int
DepthOfInheritance int
LackOfCohesion double
ResponseForClass int
Abstractness double
Instability double
DistanceFromMainSequence double
MaintainabilityIndex double
CouplingEfferent int
CouplingAfferent int
Relationships:
BaseType TypeModel
Methods collection<MethodModel>
Constructors collection<MethodModel>
Properties collection<PropertyModel>
Fields collection<FieldModel>
NestedTypes collection<TypeModel>
DerivedTypes collection<TypeModel>
UsedTypes collection<TypeModel>
UsedByTypes collection<TypeModel>
ImplementedInterfaces collection<TypeModel>
Attributes collection<AttributeModel>
MethodModel
Name string
FullName string
ShortName string
AccessModifier string
IsAsync bool
IsStatic bool
IsOverride bool
IsInterfaceImplementation bool
IsConstructor bool
IsExtensionMethod bool
IsVirtual bool
ReturnType string
ReturnTypeShortName string
Parameters collection<ParameterModel>
LinesOfCode int
CognitiveComplexity int
CyclomaticComplexity int
NestingDepth int
NumberOfLocalVariables int
NumberOfParameters int
DeclaringType TypeModel
CalledMethods collection<MethodModel>
CalledByMethods collection<MethodModel>
Attributes collection<AttributeModel>
ParameterModel
Name string
Type TypeModel
TypeShortName string # e.g. "CancellationToken"
HasDefaultValue bool
PropertyModel and FieldModel
Name string
Type TypeModel
TypeShortName string
AccessModifier string
IsStatic bool
HasGetter bool # PropertyModel only
HasSetter bool # PropertyModel only
IsReadOnly bool # FieldModel only
SyntaxIssue
SyntaxIssues is a global list of pre-analysed patterns. Each issue
has a Kind and is attached to a MethodModel. Known kinds:
"DateTimeDirectUsage"
"EmptyCatch"
"ExplicitTypeInsteadOfVar"
"FireAndForgetAsync"
"GenericExceptionCatch"
"MagicNumber"
"MissingGuardClause"
"MissingInheritDoc"
"MissingParamDoc"
"MissingXmlDoc"
"NewInConstructor"
"NullEqualityCheck"
"StringConcatenation"
"TodoComment"
"UnusedParameter"
"UnusedUsing"
Example usage:
from m in Methods
where m.SyntaxIssues.Any(i => i.Kind == "EmptyCatch")
select m
String helpers
When you read a string property you can chain:
.StartsWith("...")
.EndsWith("...")
.Contains("...")
.Matches("regex")
Comparisons are case-sensitive unless the helper documents otherwise.
Collection helpers
All root collections and sub-collections (Methods, Parameters,
Properties, ...) support the usual LINQ surface:
.Where(x => ...)
.Any(x => ...)
.All(x => ...)
.Count # property, not a method
.First()
.Sum(x => ...)
.Min(x => ...)
.Max(x => ...)
.OrderBy(x => ...)
.OrderByDescending(x => ...)
Common pitfalls
.Countinstead of.Count(): sub-collections useCountas a property.Kind == "Class"is case-sensitive: the capital letter is required.AccessModifier == "Public": we follow the C# Pascal-case convention.Parametersdoes not contain thethisreceiver for instance methods.
What is missing
If your use case needs a property that is not listed here, please file an issue. The DSL grows on demand, not on speculation.
Where to go next
- DSL grammar: how the language is structurally put together.
- Rule examples: practical applications of the predicates.
- Syntax overview: more compact variant of this catalog.