From 641b11dd263f6780395588ed7d7359fa45724089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E8=85=BE=E7=8C=AB=E8=B7=83?= <1043137532@qq.com> Date: Tue, 5 May 2026 06:04:10 +0800 Subject: [PATCH] * --- .editorconfig | 5 -- Shared/.editorconfig | 83 ++++++++++++++++++++++++++++++++++ Shared/General/OneOf.cs | 5 ++ Shared/Utils/DirectoryUtils.cs | 16 ++++--- Shared/Utils/FileUtils.cs | 16 ++++--- 5 files changed, 107 insertions(+), 18 deletions(-) delete mode 100644 .editorconfig create mode 100644 Shared/.editorconfig diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index bc23fdc..0000000 --- a/.editorconfig +++ /dev/null @@ -1,5 +0,0 @@ - -[*.{cs,vb}] - -# CA1710: 标识符应具有正确的后缀 -dotnet_diagnostic.CA1710.severity = none diff --git a/Shared/.editorconfig b/Shared/.editorconfig new file mode 100644 index 0000000..10727ca --- /dev/null +++ b/Shared/.editorconfig @@ -0,0 +1,83 @@ + +[*.{cs,vb}] + +# CA1710: 标识符应具有正确的后缀 +dotnet_diagnostic.CA1710.severity = none + +[*.{cs,vb}] +#### 命名样式 #### + +# 命名规则 + +dotnet_naming_rule.interface_should_be_以_i_开始.severity = suggestion +dotnet_naming_rule.interface_should_be_以_i_开始.symbols = interface +dotnet_naming_rule.interface_should_be_以_i_开始.style = 以_i_开始 + +dotnet_naming_rule.类型_should_be_帕斯卡拼写法.severity = suggestion +dotnet_naming_rule.类型_should_be_帕斯卡拼写法.symbols = 类型 +dotnet_naming_rule.类型_should_be_帕斯卡拼写法.style = 帕斯卡拼写法 + +dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.severity = suggestion +dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.symbols = 非字段成员 +dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.style = 帕斯卡拼写法 + +# 符号规范 + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.类型.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.类型.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.类型.required_modifiers = + +dotnet_naming_symbols.非字段成员.applicable_kinds = property, event, method +dotnet_naming_symbols.非字段成员.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.非字段成员.required_modifiers = + +# 命名样式 + +dotnet_naming_style.以_i_开始.required_prefix = I +dotnet_naming_style.以_i_开始.required_suffix = +dotnet_naming_style.以_i_开始.word_separator = +dotnet_naming_style.以_i_开始.capitalization = pascal_case + +dotnet_naming_style.帕斯卡拼写法.required_prefix = +dotnet_naming_style.帕斯卡拼写法.required_suffix = +dotnet_naming_style.帕斯卡拼写法.word_separator = +dotnet_naming_style.帕斯卡拼写法.capitalization = pascal_case + +dotnet_naming_style.帕斯卡拼写法.required_prefix = +dotnet_naming_style.帕斯卡拼写法.required_suffix = +dotnet_naming_style.帕斯卡拼写法.word_separator = +dotnet_naming_style.帕斯卡拼写法.capitalization = pascal_case +end_of_line = crlf +dotnet_style_qualification_for_field = false:silent +dotnet_style_qualification_for_property = false:silent +dotnet_style_qualification_for_method = false:silent +dotnet_style_qualification_for_event = false:silent +dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent +dotnet_diagnostic.CA1051.severity = none + +[*.cs] +csharp_using_directive_placement = outside_namespace:silent +csharp_style_expression_bodied_methods = false:silent +csharp_style_expression_bodied_constructors = false:silent +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_properties = true:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = false:silent +csharp_style_conditional_delegate_call = true:suggestion +csharp_style_var_for_built_in_types = false:silent +csharp_style_var_when_type_is_apparent = false:silent +csharp_style_var_elsewhere = false:silent +csharp_prefer_simple_using_statement = true:suggestion +csharp_prefer_braces = true:silent +csharp_style_namespace_declarations = file_scoped:suggestion +csharp_style_prefer_method_group_conversion = true:silent +csharp_style_prefer_top_level_statements = true:silent +csharp_style_prefer_primary_constructors = true:suggestion +csharp_prefer_system_threading_lock = true:suggestion +csharp_prefer_static_local_function = true:suggestion \ No newline at end of file diff --git a/Shared/General/OneOf.cs b/Shared/General/OneOf.cs index 830b937..2bd56be 100644 --- a/Shared/General/OneOf.cs +++ b/Shared/General/OneOf.cs @@ -5,6 +5,8 @@ public readonly struct OneOf { private readonly T1? _value1; public static implicit operator OneOf(T0 value) => new(0, value, default); public static implicit operator OneOf(T1 value) => new(1, default, value); + public static implicit operator T0(OneOf value) => value.As(); + public static implicit operator T1(OneOf value) => value.As(); private OneOf(int index, T0? value0, T1? value1) { _index = index; _value0 = value0; @@ -51,6 +53,9 @@ public readonly struct OneOf { public static implicit operator OneOf(T0 value) => new(0, value, default, default); public static implicit operator OneOf(T1 value) => new(1, default, value, default); public static implicit operator OneOf(T2 value) => new(2, default, default, value); + public static implicit operator T0(OneOf value) => value.As(); + public static implicit operator T1(OneOf value) => value.As(); + public static implicit operator T2(OneOf value) => value.As(); private OneOf(int index, T0? value0, T1? value1, T2? value2) { _index = index; _value0 = value0; diff --git a/Shared/Utils/DirectoryUtils.cs b/Shared/Utils/DirectoryUtils.cs index 94736b4..bbbbcd3 100644 --- a/Shared/Utils/DirectoryUtils.cs +++ b/Shared/Utils/DirectoryUtils.cs @@ -13,21 +13,24 @@ public static class DirectoryUtils { /// /// 判断文件夹是否存在。 /// - public static bool Exists(string path) => - Directory.Exists(PathUtils.WithLongPath(path)); + public static bool Exists(string path) { + return Directory.Exists(PathUtils.WithLongPath(path)); + } /// /// 创建 对象。 /// - public static DirectoryInfo GetInfo(string path) => - new(PathUtils.WithLongPath(path)); + public static DirectoryInfo GetInfo(string path) { + return new(PathUtils.WithLongPath(path)); + } /// /// 返回指定路径下的所有文件,不以 \\?\ 开头。 /// public static IEnumerable GetFiles(string path, bool topDirectoryOnly = false, string searchPattern = "*") { if (!Exists(path)) return []; - return Directory.EnumerateFiles(PathUtils.WithLongPath(path), searchPattern, topDirectoryOnly ? SearchOption.TopDirectoryOnly : SearchOption.AllDirectories).Select(PathUtils.WithoutLongPath); + return Directory.EnumerateFiles(PathUtils.WithLongPath(path), searchPattern, topDirectoryOnly ? SearchOption.TopDirectoryOnly : SearchOption.AllDirectories). + Select(PathUtils.WithoutLongPath); } /// @@ -35,7 +38,8 @@ public static class DirectoryUtils { /// public static IEnumerable GetDirectories(string path, bool topDirectoryOnly = false, string searchPattern = "*") { if (!Exists(path)) return []; - return Directory.EnumerateDirectories(PathUtils.WithLongPath(path), searchPattern, topDirectoryOnly ? SearchOption.TopDirectoryOnly : SearchOption.AllDirectories).Select(PathUtils.WithoutLongPath); + return Directory.EnumerateDirectories(PathUtils.WithLongPath(path), searchPattern, topDirectoryOnly ? SearchOption.TopDirectoryOnly : SearchOption.AllDirectories). + Select(PathUtils.WithoutLongPath); } /// diff --git a/Shared/Utils/FileUtils.cs b/Shared/Utils/FileUtils.cs index b05e288..6316434 100644 --- a/Shared/Utils/FileUtils.cs +++ b/Shared/Utils/FileUtils.cs @@ -38,7 +38,6 @@ public static class FileUtils { /// 如果文件或文件夹不存在,则会自动创建。若已存在,则会覆盖原文件。 /// public static void Write(string filePath, Stream stream) { - DirectoryUtils.Create(filePath, isFilePath: true); using FileStream fileStream = OpenCreate(PathUtils.WithLongPath(filePath)); if (stream.CanSeek && stream.Position != 0) stream.Seek(0, SeekOrigin.Begin); stream.CopyTo(fileStream); @@ -131,8 +130,9 @@ public static class FileUtils { /// /// 打开该文件的只读 。 /// - public static FileStream OpenRead(string filePath) => - new(PathUtils.WithLongPath(filePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + public static FileStream OpenRead(string filePath) { + return new(PathUtils.WithLongPath(filePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + } /// /// 在指定路径创建文件,并打开 。 @@ -147,14 +147,16 @@ public static class FileUtils { /// /// 确定指定的文件是否存在。 /// - public static bool Exists(string filePath) => - File.Exists(PathUtils.WithLongPath(filePath)); + public static bool Exists(string filePath) { + return File.Exists(PathUtils.WithLongPath(filePath)); + } /// /// 创建 对象。 /// - public static FileInfo GetInfo(string path) => - new(PathUtils.WithLongPath(path)); + public static FileInfo GetInfo(string path) { + return new(PathUtils.WithLongPath(path)); + } /// /// 复制文件。