feat!: GetRequiredBehaviour/HierarchyObject methods added for cleaner null handling
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core.Exceptions;
|
||||
|
||||
public class AssignException : Exception
|
||||
{
|
||||
public AssignException() : base("Assign operation has failed.") { }
|
||||
public AssignException(string? message) : base(message) { }
|
||||
|
||||
public static AssignException From<T, T2>(T to, T2? value)
|
||||
=> new($"Assign operation has failed on T: {to?.GetType().FullName ?? "\"null\""}, value: {value?.GetType().ToString() ?? "\"null\""}");
|
||||
}
|
9
Engine.Core/Exceptions/AssignFailedException.cs
Normal file
9
Engine.Core/Exceptions/AssignFailedException.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core.Exceptions;
|
||||
|
||||
public class AssignFailedException(string? message) : Exception(message)
|
||||
{
|
||||
public static AssignFailedException From<T, T2>(T to, T2? value)
|
||||
=> new($"Assign operation has failed on T: {to?.GetType().FullName ?? "\"null\""}, value: {value?.GetType().ToString() ?? "\"null\""}");
|
||||
}
|
9
Engine.Core/Exceptions/BehaviourNotFoundException.cs
Normal file
9
Engine.Core/Exceptions/BehaviourNotFoundException.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core.Exceptions;
|
||||
|
||||
public class BehaviourNotFoundException(string? message) : Exception(message)
|
||||
{
|
||||
public static NotAssignedException FromType<TBehaviour>()
|
||||
=> new($"{typeof(TBehaviour).FullName} was not found");
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Core.Exceptions;
|
||||
|
||||
public class HierarchyObjectNotFoundException(string? message) : Exception(message)
|
||||
{
|
||||
public static NotAssignedException FromType<THierarchyObject>()
|
||||
=> new($"{typeof(THierarchyObject).FullName} was not found");
|
||||
}
|
@@ -1,21 +1,9 @@
|
||||
using System;
|
||||
using Syntriax.Engine.Core.Abstract;
|
||||
|
||||
namespace Syntriax.Engine.Core.Exceptions;
|
||||
|
||||
public class NotAssignedException : Exception
|
||||
public class NotAssignedException(string? message) : Exception(message)
|
||||
{
|
||||
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)
|
||||
=> new($"{value?.GetType().FullName ?? "\"null\""} has not been assigned to {to?.GetType().FullName ?? "\"null\""}");
|
||||
|
||||
public static void Check<T1, T2>(T1 to, T2? value)
|
||||
{
|
||||
if (value is not null)
|
||||
return;
|
||||
|
||||
throw From(to, value);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user