Syntriax.Engine/Engine.Core/Exceptions/NotAssignedException.cs

22 lines
691 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($"{value?.GetType().FullName ?? "\"null\""} has not been assigned to {to?.GetType().FullName ?? "\"null\""}");
public static void Check<T1, T2>(T1 to, T2? value) where T1 : IAssignable
{
if (value is not null)
return;
throw From(to, value);
}
}