Refactor SelectorNotAvailableException.

This commit is contained in:
2023-01-20 22:50:31 +08:00
parent a7608bcd7e
commit c5dab3a232
2 changed files with 12 additions and 13 deletions

View File

@@ -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 }
);

View File

@@ -61,8 +61,8 @@ namespace Cryville.Crtr {
public abstract class SkinSelector {
protected SkinSelector() { }
public virtual void Optimize(PdtEvaluatorBase etor) { }
public virtual IEnumerable<SkinContext> MatchStatic(ContainerState h, SkinContext c) { throw new SelectorNotStaticException(); }
public virtual SkinContext MatchDynamic(ContainerState h, SkinContext c) { throw new NotSupportedException(); }
public virtual IEnumerable<SkinContext> 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<SkinContext>();
}
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) { }
}
}