custom exceptions, methods to create modules and states of specific type from generic ones

This commit is contained in:
2022-11-20 22:17:32 +01:00
parent 8ee43d6823
commit b0df3f303a
9 changed files with 92 additions and 54 deletions

View File

@@ -0,0 +1,21 @@
using System;
namespace EscapeRoomEngine.Engine.Runtime.Utilities
{
public class EngineException : Exception
{
public EngineException(string message) : base($"<b>[EngineException]</b> {message}") {}
}
public class WrongTypeException : EngineException
{
public WrongTypeException(Type expected, Type found, Type baseType) : base($"Wrong type of {baseType} ({found} instead of {expected})") {}
public WrongTypeException(string message) : base(message) {}
}
public class OptionException : Exception
{
public OptionException(string message) : base(message) {}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e84dc071915b429ba633c9541d3411ac
timeCreated: 1668964775

View File

@@ -49,8 +49,8 @@ namespace EscapeRoomEngine.Engine.Runtime.Utilities
{
public bool IsSome() => false;
public bool IsNone() => true;
public T Expect(string message) => throw new Exception(message);
public T Unwrap() => throw new Exception("Tried to unwrap None.");
public T Expect(string message) => throw new OptionException(message);
public T Unwrap() => throw new OptionException("Tried to unwrap None.");
public T UnwrapOr(T def) => def;
public T UnwrapOrElse(Func<T> f) => f();
public IOption<T> And(IOption<T> other) => this;