초기커밋
This commit is contained in:
43
ServerCore/Exception/ConditionCheckHelper.cs
Normal file
43
ServerCore/Exception/ConditionCheckHelper.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace ServerCore;
|
||||
|
||||
|
||||
//=============================================================================================
|
||||
// 조건 체크 관련 예외 지원 함수
|
||||
//
|
||||
// author : kangms
|
||||
//
|
||||
//=============================================================================================
|
||||
|
||||
public static class ConditionValidCheckHelper
|
||||
{
|
||||
public static void throwIfFalse( bool isCondition
|
||||
, string errMsg )
|
||||
{
|
||||
if (false == isCondition)
|
||||
{
|
||||
throw new InvalidOperationException(errMsg);
|
||||
}
|
||||
}
|
||||
|
||||
public static void throwIfFalseWithCondition( Expression<Func<bool>> conditionExpression
|
||||
, Func<string>? fnLog = null )
|
||||
{
|
||||
var compiled_expression = conditionExpression.Compile();
|
||||
if (false == compiled_expression())
|
||||
{
|
||||
string condition_text = conditionExpression.Body.ToString();
|
||||
|
||||
var err_msg = fnLog?.Invoke() ?? $"Failed to check Condition: '{condition_text}'";
|
||||
|
||||
throw new InvalidOperationException(err_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
66
ServerCore/Exception/NullReferenceCheckHelper.cs
Normal file
66
ServerCore/Exception/NullReferenceCheckHelper.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
|
||||
namespace ServerCore;
|
||||
|
||||
|
||||
//=============================================================================================
|
||||
// 객체 Null 체크 관련 예외 지원 함수
|
||||
//
|
||||
// author : kangms
|
||||
//
|
||||
//=============================================================================================
|
||||
|
||||
public static class ArgumentNullReferenceCheckHelper
|
||||
{
|
||||
public static void throwIfNull( [NotNull] object? argument
|
||||
, Func<string>? fnLog = null
|
||||
, [CallerArgumentExpression(nameof(argument))] string? paramName = null )
|
||||
{
|
||||
if (argument != null)
|
||||
return;
|
||||
|
||||
if (fnLog != null)
|
||||
{
|
||||
throw new ArgumentNullException(paramName, fnLog());
|
||||
}
|
||||
|
||||
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 !!!");
|
||||
}
|
||||
}
|
||||
|
||||
public static class NullReferenceCheckHelper
|
||||
{
|
||||
public static void throwIfNull( [NotNull] object? argument
|
||||
, Func<string>? fnLog = null
|
||||
, [CallerArgumentExpression(nameof(argument))] string? paramName = null )
|
||||
{
|
||||
if (argument != null)
|
||||
return;
|
||||
|
||||
if (fnLog != null)
|
||||
{
|
||||
throw new NullReferenceException(fnLog());
|
||||
}
|
||||
|
||||
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 !!!");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user