var types = typeof(ApiErrors).Assembly.GetTypes().Where(t => t.FullName.Contains(nameof(ApiErrors)));
var codes = new Dictionary<int, FieldInfo>();
foreach (Type type in types)
foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Public).Where(f => f.FieldType == typeof(Error)))
{
var field_value = (Error)field.GetValue(null)!;
var code = field_value.Code;
if (codes.ContainsKey(code))
throw new InvalidOperationException($"Ошибка - дублирование статусного кода {field.DeclaringType.Name}.{field.Name} с кодом {codes[code].DeclaringType.Name}.{codes[code].Name}");
codes.Add(code, field);
}
Примерная логика теста