초기커밋
This commit is contained in:
69
ServerBase/Meta/MetaValidation/ValidattionErrorCollection.cs
Normal file
69
ServerBase/Meta/MetaValidation/ValidattionErrorCollection.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System.Text;
|
||||
|
||||
|
||||
|
||||
using ServerCore;
|
||||
|
||||
namespace ServerBase;
|
||||
|
||||
public class ValidattionError
|
||||
{
|
||||
public string Name { get; set; } = "";
|
||||
public int ArrayIndex { get; set; }
|
||||
public string Message { get; set; } = "";
|
||||
|
||||
public string toDetailString()
|
||||
{
|
||||
return $"[{Name}, array: {ArrayIndex}] {Message}";
|
||||
}
|
||||
|
||||
public string toSimpleString()
|
||||
{
|
||||
return $"[array: {ArrayIndex}] {Message}";
|
||||
}
|
||||
}
|
||||
|
||||
public class ValidatorErrorCollection
|
||||
{
|
||||
public string CurrentName { get; set; } = "";
|
||||
public int CurrentArrayIndex { get; set; }
|
||||
|
||||
public Dictionary<string, List<ValidattionError>> Errors = new();
|
||||
|
||||
public bool HasError => Errors.Count > 0;
|
||||
|
||||
public void add(string message)
|
||||
{
|
||||
Errors.TryGetValue(CurrentName, out var list);
|
||||
if (list == null)
|
||||
{
|
||||
list = new List<ValidattionError>();
|
||||
Errors.Add(CurrentName, list);
|
||||
}
|
||||
|
||||
list.Add(new ValidattionError
|
||||
{
|
||||
Name = CurrentName,
|
||||
ArrayIndex = CurrentArrayIndex,
|
||||
Message = message
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void log()
|
||||
{
|
||||
foreach (var item in Errors)
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
|
||||
sb.AppendLine($"[{item.Key}]");
|
||||
foreach (var error in item.Value)
|
||||
{
|
||||
sb.AppendLine($"\t {error.toSimpleString()}");
|
||||
}
|
||||
sb.AppendLine($"[{item.Key}] validaton error. errorCount: {item.Value.Count}");
|
||||
|
||||
Log.getLogger().error(sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user