EditorConfig 以纯原生无需任何插件支持 EditorConfig 代码风格配置的编辑器:
Visual Studio 2017 开始添加了对 EditorConfig 的原生支持。Visual Studio 一旦检测到 .editorconfig 文件的存在,格式约定就会自动生效。
Visual Studio 中 .NET 相关语言(C# VB)的 EditorConfig 属性,可以参考 .NET coding convention settings For EditorConfig。
设置EditorConfig所需插件: EditorConfig Language Service 和 Visual Studio IntelliCode。
EditorConfig Language Service 生成的 .editorconfig 文件是空的。
IntelliCode 一经添加便提供了丰富的 C# 语言约定的属性设置。不过,IntelliCode 提供的设置多少取决于你目前解决方案中的项目类型。
如果你使用 EditorConfig Language Service 生成了 .editorconfig 文件,则可以继续点击小灯泡生成按照微软约定的编程规范。
C#简单配置:
[*] end_of_line = crlf charset = utf-8 indent_size = 4 insert_final_newline = true trim_trailing_whitespace = true indent_style = space [*.cs] csharp_indent_case_contents = true csharp_indent_case_contents_when_block = true csharp_indent_labels = flush_left csharp_indent_switch_labels = true csharp_new_line_before_catch = true csharp_new_line_before_else = true csharp_new_line_before_finally = true csharp_new_line_before_members_in_anonymous_types = true csharp_new_line_before_members_in_object_initializers = true csharp_new_line_before_open_brace = all csharp_new_line_between_query_expression_clauses = true csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion csharp_prefer_braces = true:silent csharp_prefer_simple_default_expression = true:suggestion csharp_style_deconstructed_variable_declaration = true:suggestion csharp_preserve_single_line_blocks = true csharp_preserve_single_line_statements = true csharp_space_after_cast = false csharp_space_after_colon_in_inheritance_clause = true csharp_space_after_keywords_in_control_flow_statements = true csharp_space_around_binary_operators = before_and_after csharp_space_before_colon_in_inheritance_clause = true csharp_space_between_method_call_empty_parameter_list_parentheses = false csharp_space_between_method_call_name_and_opening_parenthesis = false csharp_space_between_method_call_parameter_list_parentheses = false csharp_space_between_method_declaration_empty_parameter_list_parentheses = false csharp_space_between_method_declaration_parameter_list_parentheses = false csharp_space_between_parentheses = false csharp_style_conditional_delegate_call = true:suggestion csharp_style_expression_bodied_accessors = true:silent csharp_style_expression_bodied_constructors = false:silent csharp_style_expression_bodied_indexers = true:silent csharp_style_expression_bodied_methods = false:silent csharp_style_expression_bodied_operators = false:silent csharp_style_expression_bodied_properties = true:silent csharp_style_inlined_variable_declaration = true:suggestion csharp_style_pattern_local_over_anonymous_function = true:suggestion csharp_style_pattern_matching_over_as_with_null_check = true:suggestion csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion csharp_style_throw_expression = true:suggestion csharp_style_var_elsewhere = true:silent csharp_style_var_for_built_in_types = true:silent csharp_style_var_when_type_is_apparent = true:silent
每天成就一小步,积累下来就是一大步。
转发本文请注明出处,谢谢您的阅读与分享!