Skip to content

Commit 9c57163

Browse files
committed
revised code convention for C# for 2017
1 parent 9ace861 commit 9c57163

File tree

2 files changed

+130
-6
lines changed

2 files changed

+130
-6
lines changed

.editorconfig

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[*]
2+
end_of_line = crlf
3+
4+
[*.xml]
5+
indent_style = space
6+
7+
[*.cs]
8+
charset = utf-8
9+
indent_style = space
10+
indent_size = 4
11+
trim_trailing_whitespace = false
12+
insert_final_newline = true
13+
csharp_style_conditional_delegate_call = true:warning
14+
csharp_style_expression_bodied_accessors = when_on_single_line:warning
15+
csharp_style_expression_bodied_constructors = when_on_single_line:suggestion
16+
csharp_style_expression_bodied_indexers = when_on_single_line:warning
17+
csharp_style_expression_bodied_methods = when_on_single_line:suggestion
18+
csharp_style_expression_bodied_operators = when_on_single_line:suggestion
19+
csharp_style_expression_bodied_properties = when_on_single_line:warning
20+
csharp_style_inlined_variable_declaration = true:warning
21+
csharp_style_pattern_matching_over_as_with_null_check = true:warning
22+
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
23+
csharp_style_throw_expression = true:suggestion
24+
csharp_style_var_elsewhere = false:error
25+
csharp_style_var_for_built_in_types = false:error
26+
csharp_style_var_when_type_is_apparent = true:suggestion
27+
csharp_new_line_before_catch = true
28+
csharp_new_line_before_else = true
29+
csharp_new_line_before_finally = true
30+
csharp_new_line_before_members_in_anonymous_types = true
31+
csharp_new_line_before_members_in_object_initializers = true
32+
csharp_new_line_before_open_brace = all
33+
csharp_new_line_between_query_expression_clauses = true
34+
csharp_indent_case_contents = true
35+
csharp_indent_labels = one_less_than_current
36+
csharp_indent_switch_labels = false
37+
csharp_preserve_single_line_blocks = true
38+
csharp_preserve_single_line_statements = true
39+
csharp_space_after_cast = false
40+
csharp_space_after_keywords_in_control_flow_statements = false
41+
csharp_space_between_method_call_parameter_list_parentheses = true
42+
csharp_space_between_method_declaration_parameter_list_parentheses = true
43+
csharp_space_between_parentheses = expressions
44+
csharp_prefer_braces = true
45+
csharp_prefer_simple_default_expression = true
46+
dotnet_sort_system_directives_first = true
47+
dotnet_style_coalesce_expression = true:error
48+
dotnet_style_collection_initializer = true:warning
49+
dotnet_style_explicit_tuple_names = true:error
50+
dotnet_style_null_propagation = true:error
51+
dotnet_style_object_initializer = true:warning
52+
dotnet_style_predefined_type_for_locals_parameters_members = true:error
53+
dotnet_style_predefined_type_for_member_access = true:error
54+
dotnet_style_qualification_for_event = false:suggestion
55+
dotnet_style_qualification_for_field = false:suggestion
56+
dotnet_style_qualification_for_method = false:suggestion
57+
dotnet_style_qualification_for_property = false:suggestion
58+
dotnet_naming_rule.public_member_PascalCase.symbols = public_symbols
59+
dotnet_naming_symbols.public_symbols.applicable_kinds = property,method,field,event
60+
dotnet_naming_symbols.public_symbols.applicable_accessibilities = public
61+
dotnet_naming_style.PascalCase.capitalization = pascal_case
62+
dotnet_naming_rule.public_member_PascalCase.style = PascalCase

convention.tex

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ \section{Naming}
5050
var foo = ( _a, _b ) => _a + _b;
5151
\end{verbatim}
5252

53+
\domark Use the variable name \_ (a single underscore) to denote variables in lambda expressions, which is irrelevant in the current context.
54+
\begin{verbatim}
55+
(_, _b) => _b + 1
56+
\end{verbatim}
57+
5358
\domark Use pascal case in the name of namespaces, classes, interfaces, structures, enumerations and members of enumerations.
5459

5560
\domark Start name of interfaces with a capital I.
@@ -76,6 +81,39 @@ \section{Naming}
7681
float f_foo;
7782
\end{verbatim}
7883

84+
\whymark It usually results cryptic abbreviation and types are noted and shown by Visual Studio or any other IDE.
85+
86+
\avoidmark Avoid using single letter variable names.
87+
\begin{verbatim}
88+
//avoid
89+
int a;
90+
int b;
91+
92+
//do
93+
int componentA;
94+
int componentB;
95+
\end{verbatim}
96+
97+
\notmark Do not mark member with m\_ prefix.
98+
\begin{verbatim}
99+
int m_length //wrong
100+
101+
int length //right
102+
\end{verbatim}
103+
104+
\notmark Do not use white-spaces to construct columns in the source code.
105+
\begin{verbatim}
106+
//do
107+
int length = 10;
108+
string name = "Thangorodrim;
109+
110+
//wrong
111+
int length = 10;
112+
string name = "Thangorodrim;
113+
\end{verbatim}
114+
115+
\whymark It suggest structures which do not exist.
116+
79117
\avoidmark Avoid uncommon abbreviation. Use abbreviation, when you have no other choice.
80118
\begin{verbatim}
81119
string Idkwit = "true"; //I Don't Know What Is This
@@ -102,7 +140,7 @@ \section{Naming}
102140
void UmlReader()
103141
\end{verbatim}
104142

105-
\avoidmark Avoid the using the following words, because they are too general to provide useful information.
143+
\avoidmark Avoid the using the following words.
106144
\begin{compactitem}
107145
\item data
108146
\item information
@@ -111,20 +149,29 @@ \section{Naming}
111149
\item make
112150
\end{compactitem}
113151

152+
\whymark Because they are too general to provide useful information.
153+
114154
\notmark Do not use plural form in the name of namespaces, classes, interfaces, structures, enumerations and members of enumerations.
115155
\begin{verbatim}
156+
//wrong
116157
items
117158
men
159+
160+
//right
161+
itemCollection
162+
manCollection
118163
\end{verbatim}
119164

120-
\notmark Do not put spaces inside empty parentheses.
165+
\whymark It is easy to misread the plural and singular forms. Can not find irregular forms by searching singulars.
121166

122167
\section{Layout}
123168

124169
\avoidmark Avoid lines longer then 80 characters. Prefer shorter lines as much as possible.
125170

126171
\subsection{Horizontal spacing}
127172

173+
\notmark Do not put spaces inside empty parentheses.
174+
128175
\domark Use spaces at the inner side of all parentheses, except curly braces.
129176
\begin{verbatim}
130177
( Something< int >( _foo[ bla ] ) ) * 10
@@ -136,7 +183,9 @@ \subsection{Horizontal spacing}
136183
foo++;
137184
\end{verbatim}
138185

139-
\domark Use tabs instead of spaces at the beginning of the line.
186+
\domark Use spaces instead of tabs at the beginning of the line.
187+
188+
\domark Use four spaces per each indentation level. 4 spaces = 1 tab
140189

141190
\notmark Do not mix tabs and spaces at the beginning of the line.
142191

@@ -176,7 +225,7 @@ \subsection{Line-breaks}
176225
x + 567567563 / 2121231 + foobar;
177226
\end{verbatim}
178227

179-
\domark If necessary break line before operators, except parentheses.
228+
\domark If necessary break line before operators, except parentheses and assignment (=).
180229
\begin{verbatim}
181230
string _text =
182231
"this is a long string need to be"
@@ -188,6 +237,13 @@ \subsection{Line-breaks}
188237
\end{verbatim}
189238

190239
\domark Put the closing parentheses in the same line with the last parameter, except curly braces.
240+
\begin{verbatim}
241+
int grantPermissions(
242+
string user,
243+
string password,
244+
int id,
245+
PersmissionSet permission )
246+
\end{verbatim}
191247

192248
\domark If necessary prefer to start method calls in a new line.
193249

@@ -202,8 +258,6 @@ \subsection{Line-breaks}
202258

203259
\subsection{Vertical spaces}
204260

205-
\notmark Do not put empty line around opening parentheses.
206-
207261
\domark Separate members in classes with an empty lines.
208262
\begin{verbatim}
209263
private
@@ -219,4 +273,12 @@ \section{Commenting}
219273

220274
\notmark Do not use block comments (/* */).
221275

276+
\appendix
277+
278+
\chapter{C\#}
279+
280+
\section{EditorConfig for Visual Studio}
281+
282+
For further details and \emph{some} automatic style and convention settings please use the \texttt{.editorcongif} file next to this document. It only contains Visual Studio and C\#{} specific settings. This file do not cover every details present in this documents and provided \emph{as is}.
283+
222284
\end{document}

0 commit comments

Comments
 (0)