SHA256
forked from ADOFAIEditorForum/ADOFAIRenderer
Refactor Every namespace Keyword Usage
This commit is contained in:
1 parent
4e67cb9b09
commit
27be2141f7
44 files changed
+4619
-4545
No files matched your search
+69
-68
@@ -1,78 +1,79 @@
|
||||
namespace ADOFAIRenderer.Data
|
||||
namespace ADOFAIRenderer.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for integer input validation limits.
|
||||
/// Multiple limits can be composed on a single input field — all are checked in order.
|
||||
/// </summary>
|
||||
internal abstract class IntegerLimit
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for integer input validation limits.
|
||||
/// Multiple limits can be composed on a single input field — all are checked in order.
|
||||
/// Validates the given integer value against this limit.
|
||||
/// </summary>
|
||||
internal abstract class IntegerLimit
|
||||
/// <param name="value">The parsed integer value to validate.</param>
|
||||
/// <param name="errorMessage">
|
||||
/// When validation fails, set to a human-readable error message.
|
||||
/// When validation succeeds, set to null.
|
||||
/// </param>
|
||||
/// <returns>true if the value satisfies this limit; false otherwise.</returns>
|
||||
public abstract bool Validate(int value, out string errorMessage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Requires the integer value to be strictly positive (> 0).
|
||||
/// </summary>
|
||||
internal class PositiveOnlyIntegerLimit : IntegerLimit
|
||||
{
|
||||
public override bool Validate(int value, out string errorMessage)
|
||||
{
|
||||
/// <summary>
|
||||
/// Validates the given integer value against this limit.
|
||||
/// </summary>
|
||||
/// <param name="value">The parsed integer value to validate.</param>
|
||||
/// <param name="errorMessage">
|
||||
/// When validation fails, set to a human-readable error message.
|
||||
/// When validation succeeds, set to null.
|
||||
/// </param>
|
||||
/// <returns>true if the value satisfies this limit; false otherwise.</returns>
|
||||
public abstract bool Validate(int value, out string errorMessage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Requires the integer value to be strictly positive (> 0).
|
||||
/// </summary>
|
||||
internal class PositiveOnlyIntegerLimit : IntegerLimit
|
||||
{
|
||||
public override bool Validate(int value, out string errorMessage)
|
||||
if (value > 0)
|
||||
{
|
||||
if (value > 0)
|
||||
{
|
||||
errorMessage = null!;
|
||||
return true;
|
||||
}
|
||||
|
||||
errorMessage = "값은 0보다 큰 양의 정수여야 합니다.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Requires the integer value to be within an inclusive [Min, Max] range.
|
||||
/// Either bound can be null to represent an unbounded side.
|
||||
/// </summary>
|
||||
internal class RangeIntegerLimit : IntegerLimit
|
||||
{
|
||||
public int? Min { get; }
|
||||
public int? Max { get; }
|
||||
|
||||
/// <param name="min">Inclusive lower bound, or null for no lower bound.</param>
|
||||
/// <param name="max">Inclusive upper bound, or null for no upper bound.</param>
|
||||
public RangeIntegerLimit(int? min, int? max)
|
||||
{
|
||||
Min = min;
|
||||
Max = max;
|
||||
}
|
||||
|
||||
public override bool Validate(int value, out string errorMessage)
|
||||
{
|
||||
if (Min.HasValue && value < Min.Value)
|
||||
{
|
||||
errorMessage = Max.HasValue
|
||||
? $"값은 {Min.Value}에서 {Max.Value} 사이의 정수여야 합니다."
|
||||
: $"값은 {Min.Value} 이상의 정수여야 합니다.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Max.HasValue && value > Max.Value)
|
||||
{
|
||||
errorMessage = Min.HasValue
|
||||
? $"값은 {Min.Value}에서 {Max.Value} 사이의 정수여야 합니다."
|
||||
: $"값은 {Max.Value} 이하의 정수여야 합니다.";
|
||||
return false;
|
||||
}
|
||||
|
||||
errorMessage = null!;
|
||||
return true;
|
||||
}
|
||||
|
||||
errorMessage = "값은 0보다 큰 양의 정수여야 합니다.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Requires the integer value to be within an inclusive [Min, Max] range.
|
||||
/// Either bound can be null to represent an unbounded side.
|
||||
/// </summary>
|
||||
internal class RangeIntegerLimit : IntegerLimit
|
||||
{
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
public int? Min { get; }
|
||||
public int? Max { get; }
|
||||
// ReSharper restore MemberCanBePrivate.Global
|
||||
|
||||
/// <param name="min">Inclusive lower bound, or null for no lower bound.</param>
|
||||
/// <param name="max">Inclusive upper bound, or null for no upper bound.</param>
|
||||
public RangeIntegerLimit(int? min, int? max)
|
||||
{
|
||||
Min = min;
|
||||
Max = max;
|
||||
}
|
||||
|
||||
public override bool Validate(int value, out string errorMessage)
|
||||
{
|
||||
if (value < Min)
|
||||
{
|
||||
errorMessage = Max.HasValue
|
||||
? $"값은 {Min.Value}에서 {Max.Value} 사이의 정수여야 합니다."
|
||||
: $"값은 {Min.Value} 이상의 정수여야 합니다.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value > Max)
|
||||
{
|
||||
errorMessage = Min.HasValue
|
||||
? $"값은 {Min.Value}에서 {Max.Value} 사이의 정수여야 합니다."
|
||||
: $"값은 {Max.Value} 이하의 정수여야 합니다.";
|
||||
return false;
|
||||
}
|
||||
|
||||
errorMessage = null!;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user