龙腾猫跃 hai 5 meses
pai
achega
641b11dd26
Modificáronse 5 ficheiros con 107 adicións e 18 borrados
  1. 0 5
      .editorconfig
  2. 83 0
      Shared/.editorconfig
  3. 5 0
      Shared/General/OneOf.cs
  4. 10 6
      Shared/Utils/DirectoryUtils.cs
  5. 9 7
      Shared/Utils/FileUtils.cs

+ 0 - 5
.editorconfig

@@ -1,5 +0,0 @@
-
-[*.{cs,vb}]
-
-# CA1710: 标识符应具有正确的后缀
-dotnet_diagnostic.CA1710.severity = none

+ 83 - 0
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

+ 5 - 0
Shared/General/OneOf.cs

@@ -5,6 +5,8 @@ public readonly struct OneOf<T0, T1> {
     private readonly T1? _value1;
     public static implicit operator OneOf<T0, T1>(T0 value) => new(0, value, default);
     public static implicit operator OneOf<T0, T1>(T1 value) => new(1, default, value);
+    public static implicit operator T0(OneOf<T0, T1> value) => value.As<T0>();
+    public static implicit operator T1(OneOf<T0, T1> value) => value.As<T1>();
     private OneOf(int index, T0? value0, T1? value1) {
         _index = index;
         _value0 = value0;
@@ -51,6 +53,9 @@ public readonly struct OneOf<T0, T1, T2> {
     public static implicit operator OneOf<T0, T1, T2>(T0 value) => new(0, value, default, default);
     public static implicit operator OneOf<T0, T1, T2>(T1 value) => new(1, default, value, default);
     public static implicit operator OneOf<T0, T1, T2>(T2 value) => new(2, default, default, value);
+    public static implicit operator T0(OneOf<T0, T1, T2> value) => value.As<T0>();
+    public static implicit operator T1(OneOf<T0, T1, T2> value) => value.As<T1>();
+    public static implicit operator T2(OneOf<T0, T1, T2> value) => value.As<T2>();
     private OneOf(int index, T0? value0, T1? value1, T2? value2) {
         _index = index;
         _value0 = value0;

+ 10 - 6
Shared/Utils/DirectoryUtils.cs

@@ -13,21 +13,24 @@ public static class DirectoryUtils {
     /// <summary>
     /// 判断文件夹是否存在。
     /// </summary>
-    public static bool Exists(string path) => 
-        Directory.Exists(PathUtils.WithLongPath(path));
+    public static bool Exists(string path) {
+        return Directory.Exists(PathUtils.WithLongPath(path));
+    }
 
     /// <summary>
     /// 创建 <see cref="DirectoryInfo"/> 对象。
     /// </summary>
-    public static DirectoryInfo GetInfo(string path) => 
-        new(PathUtils.WithLongPath(path));
+    public static DirectoryInfo GetInfo(string path) {
+        return new(PathUtils.WithLongPath(path));
+    }
 
     /// <summary>
     /// 返回指定路径下的所有文件,不以 \\?\ 开头。
     /// </summary>
     public static IEnumerable<string> 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);
     }
 
     /// <summary>
@@ -35,7 +38,8 @@ public static class DirectoryUtils {
     /// </summary>
     public static IEnumerable<string> 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);
     }
 
     /// <summary>

+ 9 - 7
Shared/Utils/FileUtils.cs

@@ -38,7 +38,6 @@ public static class FileUtils {
     /// 如果文件或文件夹不存在,则会自动创建。若已存在,则会覆盖原文件。
     /// </summary>
     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 {
     /// <summary>
     /// 打开该文件的只读 <see cref="FileStream"/>。
     /// </summary>
-    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);
+    }
 
     /// <summary>
     /// 在指定路径创建文件,并打开 <see cref="FileStream"/>。
@@ -147,14 +147,16 @@ public static class FileUtils {
     /// <summary>
     /// 确定指定的文件是否存在。
     /// </summary>
-    public static bool Exists(string filePath) => 
-        File.Exists(PathUtils.WithLongPath(filePath));
+    public static bool Exists(string filePath) {
+        return File.Exists(PathUtils.WithLongPath(filePath));
+    }
 
     /// <summary>
     /// 创建 <see cref="FileInfo"/> 对象。
     /// </summary>
-    public static FileInfo GetInfo(string path) => 
-        new(PathUtils.WithLongPath(path));
+    public static FileInfo GetInfo(string path) {
+        return new(PathUtils.WithLongPath(path));
+    }
 
     /// <summary>
     /// 复制文件。