22 lines
667 B
C#
22 lines
667 B
C#
|
using System;
|
||
|
using Syntriax.Engine.Core.Abstract;
|
||
|
|
||
|
namespace Syntriax.Engine.Core.Exceptions;
|
||
|
|
||
|
public class NotAssignedException : Exception
|
||
|
{
|
||
|
public NotAssignedException() : base("The object has not been assigned.") { }
|
||
|
public NotAssignedException(string? message) : base(message) { }
|
||
|
|
||
|
public static NotAssignedException From<T1, T2>(T1 to, T2? value) where T1 : IAssignable
|
||
|
=> new NotAssignedException($"{typeof(T2).Name} has not been assigned to {typeof(T1).Name}");
|
||
|
|
||
|
public static void Check<T1, T2>(T1 to, T2? value) where T1 : IAssignable
|
||
|
{
|
||
|
if (value is not null)
|
||
|
return;
|
||
|
|
||
|
throw From(to, value);
|
||
|
}
|
||
|
}
|