A:添加测试项目
This commit is contained in:
1 parent
25c4a663a5
commit
859814514b
12 files changed
+562
-3
No files matched your search
@@ -0,0 +1,31 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Sharp.Config;
|
||||
|
||||
public sealed class ConfigSource
|
||||
{
|
||||
public required string Path { get; init; }
|
||||
public required ConfigFormat Format { get; init; }
|
||||
public bool Optional { get; init; } = true;
|
||||
|
||||
public override string ToString() => $"{Format}:{Path} (Optional={Optional})";
|
||||
|
||||
public static bool TryGuess(string path, [NotNullWhen(true)] out ConfigSource? source)
|
||||
{
|
||||
source = null;
|
||||
var ext = System.IO.Path.GetExtension(path).ToLowerInvariant();
|
||||
var fmt = ext switch
|
||||
{
|
||||
".json" => ConfigFormat.Json,
|
||||
".ini" => ConfigFormat.Ini,
|
||||
".xml" => ConfigFormat.Xml,
|
||||
".toml" => ConfigFormat.Toml,
|
||||
_ => (ConfigFormat?)null
|
||||
};
|
||||
|
||||
if (fmt is null) return false;
|
||||
source = new ConfigSource { Path = path, Format = fmt.Value };
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user