63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
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
|
|
, Func<string, Exception>? overrideException = null )
|
|
{
|
|
if (argument != null)
|
|
return;
|
|
|
|
string message = fnLog?.Invoke() ?? $"Argument '{paramName}' cannot be null !!!";
|
|
|
|
if (overrideException != null)
|
|
{
|
|
throw overrideException(message);
|
|
}
|
|
|
|
throw new ArgumentNullException(paramName, message);
|
|
}
|
|
}
|
|
|
|
public static class NullReferenceCheckHelper
|
|
{
|
|
public static void throwIfNull( [NotNull] object? argument
|
|
, Func<string>? fnLog = null
|
|
, [CallerArgumentExpression(nameof(argument))] string? paramName = null
|
|
, Func<string, Exception>? overrideException = null )
|
|
{
|
|
if (argument != null)
|
|
return;
|
|
|
|
string message = fnLog?.Invoke() ?? $"'{paramName}' object cannot be null !!!";
|
|
|
|
if (overrideException != null)
|
|
{
|
|
throw overrideException(message);
|
|
}
|
|
|
|
throw new NullReferenceException(message);
|
|
}
|
|
}
|