internal static string GetDescriptionString(this DiceErrorCode code) { return(typeof(DiceErrorCode) .GetMember(code.ToString())[0] .GetCustomAttributes(typeof(DescriptionAttribute), false) .Cast <DescriptionAttribute>() .Single() .Description); }
protected static void EatExceptions(DiceErrorCode errorCode, Action action) { try { action(); } catch (DiceException e) { if (e.ErrorCode != errorCode) { throw; } } }
protected static void EvaluateRoll(string diceExpr, RollerConfig conf, DiceErrorCode error) { try { Roller.Roll(diceExpr, conf); Assert.Fail("Expected DiceException with error code {0}, but did not receive an exception.", error.ToString()); } catch (DiceException e) { if (e.ErrorCode != error) { Assert.Fail("Expected DiceException with error code {0}, but got error code {1}.", error.ToString(), e.ErrorCode.ToString()); } } }
/// <summary> /// Evaluates the node and asserts that a DiceException was thrown with the specified error code. /// </summary> /// <param name="node"></param> /// <param name="conf"></param> /// <param name="error"></param> protected static void EvaluateNode(DiceAST node, RollData data, DiceErrorCode error) { try { Roller.Roll(node, data); Assert.Fail("Expected DiceException with error code {0}, but did not receive an exception.", error.ToString()); } catch (DiceException e) { if (e.ErrorCode != error) { Assert.Fail("Expected DiceException with error code {0}, but got error code {1}.", error.ToString(), e.ErrorCode.ToString()); } } }
private static void EvaluatePost(string roll, DiceErrorCode error, RollPost post = null) { post = post ?? new RollPost(); try { post.AddRoll(roll); Assert.Fail("Expected DiceException with error code {0}, but did not receive an exception.", error.ToString()); } catch (DiceException e) { if (e.ErrorCode != error) { Assert.Fail("Expected DiceException with error code {0}, but got error code {1}.", error.ToString(), e.ErrorCode.ToString()); } } }
protected DiceException(SerializationInfo info, StreamingContext context) : base(info, context) { ErrorCode = (DiceErrorCode)info.GetValue("ErrorCode", typeof(int)); }
public DiceException(DiceErrorCode error, object param, Exception innerException) : base(String.Format(error.GetDescriptionString(), param), innerException) { ErrorCode = error; }
public DiceException(DiceErrorCode error, Exception innerException) : base(error.GetDescriptionString(), innerException) { ErrorCode = error; }
public DiceException(DiceErrorCode error) : base(error.GetDescriptionString()) { ErrorCode = error; }