Skip to content

Commit 8c63c25

Browse files
committed
Updated readme
1 parent 20f38d6 commit 8c63c25

File tree

1 file changed

+100
-54
lines changed

1 file changed

+100
-54
lines changed

README.md

Lines changed: 100 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,154 @@
11
# Dataverse Analyzer
22

3-
A Roslyn analyzer for .NET Core projects that enforces specific coding standards and best practices.
3+
A Roslyn analyzer enforcing coding standards for Dataverse/.NET projects.
44

5-
## Rule CT0001: Control Flow Braces Rule
5+
## Rules Overview
66

7-
This analyzer enforces that `if` and `else` control flow statements without braces can only contain:
8-
- `return` statements
9-
- `throw` statements
10-
- `continue` statements
11-
- `break` statements
12-
- `yield break` statements
7+
| ID | Rule | Category | Severity |
8+
|----|------|----------|----------|
9+
| CT0001 | Braceless control flow must be return/throw/continue/break/yield break | Style | Error |
10+
| CT0002 | Enum properties should not be assigned literal values | Usage | Warning |
11+
| CT0003 | Remove empty parentheses from object initialization | Style | Error |
12+
| CT0004 | Remove braces from single control flow statements | Style | Error |
13+
| CT0005 | Constructor has duplicate DI parameter types | Usage | Warning |
14+
| CT0006 | Plugin class missing XML documentation | Documentation | Warning |
15+
| CT0007 | Use ContainsAttributes instead of Contains on Entity | Usage | Warning |
16+
| CT0008 | AddFilteredAttributes not allowed on Create | Usage | Error |
17+
| CT0009 | PreImage not allowed on Create | Usage | Error |
18+
| CT0010 | PostImage not allowed on Delete | Usage | Error |
1319

14-
### Examples
20+
## Style Rules
21+
22+
### CT0001: Braceless Control Flow
23+
24+
Control flow statements without braces can only contain: `return`, `throw`, `continue`, `break`, or `yield break`.
1525

16-
**Allowed** (no braces needed):
1726
```csharp
27+
// Allowed
1828
if (condition)
1929
return;
2030

21-
if (error)
22-
throw new Exception();
31+
// Not allowed - triggers CT0001
32+
if (condition)
33+
DoSomething();
34+
```
35+
36+
### CT0003: Object Initialization Parentheses
2337

24-
while (true)
25-
break;
38+
Remove empty parentheses when using object initializers.
2639

27-
foreach (var item in items)
28-
continue;
40+
```csharp
41+
// Allowed
42+
var account = new Account { Name = "Test" };
2943

30-
if (done)
31-
yield break;
44+
// Not allowed - triggers CT0003
45+
var account = new Account() { Name = "Test" };
3246
```
3347

34-
**Not allowed** (braces required):
48+
### CT0004: Braced Control Flow
49+
50+
Remove braces when a block contains only a single control flow statement.
51+
3552
```csharp
36-
// This will trigger CT0001
53+
// Allowed
3754
if (condition)
38-
DoSomething();
55+
return;
56+
57+
// Not allowed - triggers CT0004
58+
if (condition)
59+
{
60+
return;
61+
}
3962
```
4063

41-
## Rule CT0002: Enum Assignment Rule
64+
## Usage Rules
4265

43-
This analyzer prevents assigning literal values to enum properties, requiring the use of proper enum values instead.
66+
### CT0002: Enum Assignment
4467

45-
### Examples
68+
Enum properties should use enum values, not literals.
4669

47-
**Allowed**:
4870
```csharp
71+
// Allowed
4972
AccountCategoryCode = AccountCategoryCode.Standard;
73+
74+
// Not allowed - triggers CT0002
75+
AccountCategoryCode = 1;
5076
```
5177

52-
**Not allowed**:
78+
### CT0005: Duplicate DI Parameters
79+
80+
Constructors shouldn't have multiple parameters of the same DI type (Service, Repository, Handler, Provider, Factory, Manager, Client).
81+
5382
```csharp
54-
// This will trigger CT0002
55-
AccountCategoryCode = 1;
83+
// Not allowed - triggers CT0005
84+
public MyClass(IUserService userService, IUserService adminService) { }
5685
```
5786

58-
## Rule CT0003: Object Initialization Rule
87+
### CT0007: Entity Contains
88+
89+
Use type-safe `ContainsAttributes` instead of string-based `Contains` on Entity types.
5990

60-
This analyzer prevents the use of empty parentheses in object initialization when using object initializers.
91+
```csharp
92+
// Allowed
93+
if (account.ContainsAttributes(x => x.Name))
94+
95+
// Not allowed - triggers CT0007
96+
if (account.Contains("name"))
97+
```
6198

62-
### Examples
99+
### CT0008-CT0010: Plugin Step Configuration
100+
101+
These rules prevent invalid plugin step configurations in Dataverse:
102+
103+
| Rule | Restriction | Reason |
104+
|------|-------------|--------|
105+
| CT0008 | No `AddFilteredAttributes` on Create | Filtered attributes have no effect on Create |
106+
| CT0009 | No PreImage on Create | No previous record state exists |
107+
| CT0010 | No PostImage on Delete | No record state exists after deletion |
63108

64-
**Allowed**:
65109
```csharp
66-
var account = new Account
67-
{
68-
Name = "MoneyMan",
69-
};
110+
// Not allowed - triggers CT0008
111+
RegisterPluginStep<Account>(EventOperation.Create)
112+
.AddFilteredAttributes(a => a.Name);
70113

71-
var account = new Account(accountId)
72-
{
73-
Name = "MoneyMan",
74-
};
114+
// Not allowed - triggers CT0009
115+
RegisterPluginStep<Account>(EventOperation.Create)
116+
.AddImage(ImageType.PreImage);
117+
118+
// Not allowed - triggers CT0010
119+
RegisterPluginStep<Account>(EventOperation.Delete)
120+
.AddImage(ImageType.PostImage);
75121
```
76122

77-
**Not allowed**:
123+
## Documentation Rules
124+
125+
### CT0006: Plugin Documentation
126+
127+
Classes implementing `IPlugin` must have XML documentation.
128+
78129
```csharp
79-
// This will trigger CT0003
80-
var account = new Account()
81-
{
82-
Name = "MoneyMan",
83-
};
130+
// Allowed
131+
/// <summary>Updates account name on create.</summary>
132+
public class UpdateAccountPlugin : IPlugin { }
133+
134+
// Not allowed - triggers CT0006
135+
public class UpdateAccountPlugin : IPlugin { }
84136
```
85137

86138
## Usage
87139

88-
The analyzer is designed to be consumed as a project reference or NuGet package in other .NET projects. When integrated, it will automatically analyze your code and report violations of the rules.
89-
90140
### Building
91141

92142
```bash
93143
dotnet build src\DataverseAnalyzer\DataverseAnalyzer.csproj --configuration Release
94144
```
95145

96-
The built analyzer DLL will be available in `src\DataverseAnalyzer\bin\Release\netstandard2.0\DataverseAnalyzer.dll`.
146+
### Integration
97147

98-
## Integration
99-
100-
To use this analyzer in your projects, reference the built DLL as an analyzer:
148+
Reference the analyzer in your project:
101149

102150
```xml
103151
<ItemGroup>
104152
<Analyzer Include="path\to\DataverseAnalyzer.dll" />
105153
</ItemGroup>
106154
```
107-
108-
The analyzer includes an automatic code fix provider that can add braces when violations are detected.

0 commit comments

Comments
 (0)