Skip to content

Commit c112fcf

Browse files
committed
Add CC0024, StaticConstructorExceptionAnalyzer
1 parent 4f7ded5 commit c112fcf

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

assets/images/CC0024/codefix0.png

12 KB
Loading

diagnostics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ tagline: All our diagnostics, ordered by category
1111
|[CC0004](/diagnostics/CC0004.html)|EmptyCatchBlockAnalyzer|
1212
|[CC0016](/diagnostics/CC0016.html)|CopyEventToVariableBeforeFireAnalyzer|
1313
|[CC0021](/diagnostics/CC0021.html)|NameOfAnalyzer|
14+
|[CC0024](/diagnostics/CC0024.html)|StaticConstructorExceptionAnalyzer|
1415

1516
## Naming
1617

diagnostics/CC0024.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
layout: page
3+
title: CC0024
4+
tagline: StaticConstructorExceptionAnalyzer
5+
---
6+
7+
|TypeName|StaticConstructorExceptionAnalyzer |
8+
|Check Id | CC0024 |
9+
|Category | Design |
10+
|Severity | Warning |
11+
12+
# Cause
13+
14+
Static constructor are called before the first time a class is used but the caller doesn't control when exactly.
15+
Exception thrown in this context force callers to use 'try' block around any useage of the class and should be avoided.
16+
17+
# Example
18+
19+
{% highlight csharp %}
20+
public class MyClass
21+
{
22+
static MyClass()
23+
{
24+
throw new System.Exception("error message");
25+
}
26+
}
27+
{% endhighlight %}
28+
29+
# Code fix
30+
31+
A code fix will be presented to you that will transform the code:
32+
33+
{% highlight csharp %}
34+
public class MyClass
35+
{
36+
static MyClass()
37+
{
38+
}
39+
}
40+
{% endhighlight %}
41+
42+
![Code fix]({{ BASE_PATH }}/assets/images/CC0024/codefix0.png)
43+
44+
# Related rules
45+
46+
None
47+
48+
# See also
49+
50+
TBD

0 commit comments

Comments
 (0)