250501 커밋
This commit is contained in:
@@ -10,7 +10,7 @@ namespace ServerCore;
|
||||
|
||||
|
||||
//=============================================================================================
|
||||
// 조건 체크 관련 예외 지원 함수
|
||||
// 조건별 체크 관련 예외 지원 함수
|
||||
//
|
||||
// author : kangms
|
||||
//
|
||||
@@ -19,25 +19,57 @@ namespace ServerCore;
|
||||
public static class ConditionValidCheckHelper
|
||||
{
|
||||
public static void throwIfFalse( bool isCondition
|
||||
, string errMsg )
|
||||
, string errMsg
|
||||
, Func<string, Exception>? overrideException = null )
|
||||
{
|
||||
if (false == isCondition)
|
||||
if (isCondition)
|
||||
return;
|
||||
|
||||
if (overrideException != null)
|
||||
{
|
||||
throw new InvalidOperationException(errMsg);
|
||||
throw overrideException(errMsg);
|
||||
}
|
||||
|
||||
throw new InvalidOperationException(errMsg);
|
||||
}
|
||||
|
||||
public static void throwIfFalseWithCondition( Expression<Func<bool>> conditionExpression
|
||||
, Func<string>? fnLog = null )
|
||||
, Func<string>? fnLog = null
|
||||
, Func<string, Exception>? overrideException = null )
|
||||
{
|
||||
var compiled_expression = conditionExpression.Compile();
|
||||
if (false == compiled_expression())
|
||||
if (compiled_expression())
|
||||
return;
|
||||
|
||||
string condition_text = conditionExpression.Body.ToString();
|
||||
string errMsg = fnLog?.Invoke() ?? $"Failed to check condition: '{condition_text}'";
|
||||
|
||||
if (overrideException != null)
|
||||
{
|
||||
string condition_text = conditionExpression.Body.ToString();
|
||||
|
||||
var err_msg = fnLog?.Invoke() ?? $"Failed to check Condition: '{condition_text}'";
|
||||
|
||||
throw new InvalidOperationException(err_msg);
|
||||
throw overrideException(errMsg);
|
||||
}
|
||||
|
||||
throw new InvalidOperationException(errMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class RangeCheckHelper
|
||||
{
|
||||
public static void throwIfOutOfRange( int value, int min, int max
|
||||
, Func<string>? fnLog = null
|
||||
, Func<string, Exception>? overrideException = null )
|
||||
{
|
||||
if (value >= min && value <= max)
|
||||
return;
|
||||
|
||||
string message = fnLog?.Invoke() ?? $"Value {value} is out of range [{min}, {max}]";
|
||||
|
||||
if (overrideException != null)
|
||||
{
|
||||
throw overrideException(message);
|
||||
}
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(value), message);
|
||||
}
|
||||
}
|
||||
@@ -23,22 +23,20 @@ public static class ArgumentNullReferenceCheckHelper
|
||||
{
|
||||
public static void throwIfNull( [NotNull] object? argument
|
||||
, Func<string>? fnLog = null
|
||||
, [CallerArgumentExpression(nameof(argument))] string? paramName = null )
|
||||
, [CallerArgumentExpression(nameof(argument))] string? paramName = null
|
||||
, Func<string, Exception>? overrideException = null )
|
||||
{
|
||||
if (argument != null)
|
||||
return;
|
||||
|
||||
if (fnLog != null)
|
||||
string message = fnLog?.Invoke() ?? $"Argument '{paramName}' cannot be null !!!";
|
||||
|
||||
if (overrideException != null)
|
||||
{
|
||||
throw new ArgumentNullException(paramName, fnLog());
|
||||
throw overrideException(message);
|
||||
}
|
||||
|
||||
if (paramName != null)
|
||||
{
|
||||
throw new ArgumentNullException(paramName, $"Argument '{paramName}' cannot be null !!!");
|
||||
}
|
||||
|
||||
throw new ArgumentNullException("Cannot generate null-check error message: both 'fnLog' and 'paramName' are null !!!");
|
||||
throw new ArgumentNullException(paramName, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,21 +44,19 @@ public static class NullReferenceCheckHelper
|
||||
{
|
||||
public static void throwIfNull( [NotNull] object? argument
|
||||
, Func<string>? fnLog = null
|
||||
, [CallerArgumentExpression(nameof(argument))] string? paramName = null )
|
||||
, [CallerArgumentExpression(nameof(argument))] string? paramName = null
|
||||
, Func<string, Exception>? overrideException = null )
|
||||
{
|
||||
if (argument != null)
|
||||
return;
|
||||
|
||||
if (fnLog != null)
|
||||
string message = fnLog?.Invoke() ?? $"'{paramName}' object cannot be null !!!";
|
||||
|
||||
if (overrideException != null)
|
||||
{
|
||||
throw new NullReferenceException(fnLog());
|
||||
throw overrideException(message);
|
||||
}
|
||||
|
||||
if (paramName != null)
|
||||
{
|
||||
throw new NullReferenceException($"'{paramName}' object cannot be null !!!");
|
||||
}
|
||||
|
||||
throw new NullReferenceException("Cannot generate null-check error message: both 'fnLog' and 'paramName' are null !!!");
|
||||
throw new NullReferenceException(message);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user