From c5dab3a232d8c37a073d77a68e70bb2e4598ee91 Mon Sep 17 00:00:00 2001 From: PopSlime Date: Fri, 20 Jan 2023 22:50:31 +0800 Subject: [PATCH] Refactor SelectorNotAvailableException. --- Assets/Cryville/Crtr/SkinContainer.cs | 2 +- Assets/Cryville/Crtr/SkinSelectors.cs | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Assets/Cryville/Crtr/SkinContainer.cs b/Assets/Cryville/Crtr/SkinContainer.cs index fc1e51b..338fcd5 100644 --- a/Assets/Cryville/Crtr/SkinContainer.cs +++ b/Assets/Cryville/Crtr/SkinContainer.cs @@ -58,7 +58,7 @@ namespace Cryville.Crtr { MatchStatic(r.Value, state, nrctx); } } - catch (SelectorNotStaticException) { + catch (SelectorNotAvailableException) { dynelems.Add( new DynamicElement { Context = ctx, Selectors = r.Key, Element = r.Value } ); diff --git a/Assets/Cryville/Crtr/SkinSelectors.cs b/Assets/Cryville/Crtr/SkinSelectors.cs index 2821ed4..65a01c1 100644 --- a/Assets/Cryville/Crtr/SkinSelectors.cs +++ b/Assets/Cryville/Crtr/SkinSelectors.cs @@ -61,8 +61,8 @@ namespace Cryville.Crtr { public abstract class SkinSelector { protected SkinSelector() { } public virtual void Optimize(PdtEvaluatorBase etor) { } - public virtual IEnumerable MatchStatic(ContainerState h, SkinContext c) { throw new SelectorNotStaticException(); } - public virtual SkinContext MatchDynamic(ContainerState h, SkinContext c) { throw new NotSupportedException(); } + public virtual IEnumerable MatchStatic(ContainerState h, SkinContext c) { throw new SelectorNotAvailableException(); } + public virtual SkinContext MatchDynamic(ContainerState h, SkinContext c) { throw new SelectorNotAvailableException(); } public virtual bool IsUpdatable(ContainerState h) { return true; } @@ -121,17 +121,16 @@ namespace Cryville.Crtr { else return Enumerable.Empty(); } public override SkinContext MatchDynamic(ContainerState h, SkinContext c) { - return Match(c, true); + return Match(c); } - public SkinContext Match(SkinContext a, bool dyn = false) { + public SkinContext Match(SkinContext a) { ChartPlayer.etor.ContextTransform = a.Transform; try { ChartPlayer.etor.Evaluate(_op, _exp); return _flag ? a : null; } - catch (Exception) { - if (dyn) throw; - else throw new SelectorNotStaticException(); + catch (Exception ex) { + throw new SelectorNotAvailableException("The expression is not evaluatable under the current context", ex); } finally { ChartPlayer.etor.ContextTransform = null; @@ -152,10 +151,10 @@ namespace Cryville.Crtr { } } } - public class SelectorNotStaticException : Exception { - public SelectorNotStaticException() : base("The selector is not static") { } - public SelectorNotStaticException(string message) : base(message) { } - public SelectorNotStaticException(string message, Exception innerException) : base(message, innerException) { } - protected SelectorNotStaticException(SerializationInfo info, StreamingContext context) : base(info, context) { } + public class SelectorNotAvailableException : Exception { + public SelectorNotAvailableException() : base("The selector is not available under the current context") { } + public SelectorNotAvailableException(string message) : base(message) { } + public SelectorNotAvailableException(string message, Exception innerException) : base(message, innerException) { } + protected SelectorNotAvailableException(SerializationInfo info, StreamingContext context) : base(info, context) { } } }