72 lines
2.0 KiB
C#
72 lines
2.0 KiB
C#
using System;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace IRaCIS.Core.Infrastructure.Extention
|
|
{
|
|
public static class NUllCheckExtension
|
|
{
|
|
|
|
|
|
[DoesNotReturn]
|
|
public static TEntity IfNullThrowException<TEntity>(this TEntity businessObject) where TEntity : class
|
|
{
|
|
if(businessObject == null)
|
|
{
|
|
throw new QueryBusinessObjectNotExistException($"The query object {typeof(TEntity).Name} does not exist in database, Please check the query parameters");
|
|
}
|
|
else
|
|
{
|
|
return businessObject!;
|
|
}
|
|
}
|
|
|
|
[DoesNotReturn]
|
|
public static TEntity IfNullThrowException<TEntity>(this TEntity? businessStruct) where TEntity : struct
|
|
{
|
|
if (businessStruct == null)
|
|
{
|
|
throw new QueryBusinessObjectNotExistException($"The query object {typeof(TEntity).Name} does not exist in database, Please check the query parameters");
|
|
}
|
|
else
|
|
{
|
|
return (TEntity)businessStruct;
|
|
}
|
|
}
|
|
|
|
[DoesNotReturn]
|
|
public static TEntity IfNullThrowConvertException<TEntity>(this TEntity businessObject) where TEntity : class
|
|
{
|
|
if (businessObject == null)
|
|
{
|
|
throw new QueryBusinessObjectNotExistException($" Can not Convert to {typeof(TEntity).Name} Type, Please check parameter");
|
|
}
|
|
else
|
|
{
|
|
return businessObject!;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public class QueryBusinessObjectNotExistException : Exception
|
|
{
|
|
|
|
public QueryBusinessObjectNotExistException()
|
|
{
|
|
|
|
}
|
|
|
|
public QueryBusinessObjectNotExistException(string message) : base(message)
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
public class ConversionException : Exception
|
|
{
|
|
public ConversionException(string message) : base(message)
|
|
{
|
|
}
|
|
}
|
|
}
|