72 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			72 lines
		
	
	
		
			1.9 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} is null, Please check ");
 | |
|             }
 | |
|             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} is null,  Please check ");
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 return (TEntity)businessStruct;
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         [DoesNotReturn]
 | |
|         public static TEntity IfNullThrowConvertException<TEntity>(this TEntity businessObject) where TEntity : class
 | |
|         {
 | |
|             if (businessObject == null)
 | |
|             {
 | |
|                 throw new QueryBusinessObjectNotExistException($"  {typeof(TEntity).Name} Type  object  should not null,  Please check ");
 | |
|             }
 | |
|             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)
 | |
|         {
 | |
|         }
 | |
|     }
 | |
| }
 |