public override object Parse(ParserContext context) { if (string.IsNullOrWhiteSpace(context.Text)) { throw new PluginException("Can not parse for the predication because the parser text is empty."); } var matches = _regex.Matches(context.Text); if (matches.Count < 1) { throw new PluginException("Can not parse for the predication."); } var parts = matches[0].Value.Split('.'); if (parts.Length != 2) { throw new PluginException("Can not parse for the predication because of a syntax error."); } IPredication predication = null; if (parts.Length == 1) { predication = context.PluginContext.ApplicationContext.ServiceFactory.Default.Resolve(parts[0]) as IPredication; } else { var serviceProvider = context.PluginContext.ApplicationContext.ServiceFactory.GetProvider(parts[0]); if (serviceProvider == null) { throw new PluginException(string.Format("The '{0}' ServiceProvider is not exists on the predication parsing.", parts[0])); } predication = serviceProvider.Resolve(parts[1]) as IPredication; } if (predication != null) { string text = matches.Count <= 1 ? null : context.Text.Substring(matches[1].Index); object parameter = text; if (Zongsoft.Common.TypeExtension.IsAssignableFrom(typeof(IPredication <PluginPredicationContext>), predication.GetType())) { parameter = new PluginPredicationContext(text, context.Builtin, context.Node, context.Plugin); } return(predication.Predicate(parameter)); } return(false); }
public virtual bool CanHandle(IExecutionPipelineContext context) { //如果断言对象是空则返回是否可用变量的值 if (_predication == null) { return(_enabled); } //返回断言对象的断言测试的值 return(_enabled && _predication.Predicate(context)); }