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

22 lines
667 B
C#
Raw Permalink Normal View History

2023-11-23 22:07:49 +03:00
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);
}
}