Exemplo n.º 1
0
        public virtual bool TryResolve(string expression, out object value)
        {
            value = expression;
            if (expression.IsNullOrEmpty())
            {
                return(false);
            }
            if (expression.IndexOf(".") < 0)
            {
                //默认给DefaultProvider
                expression = "Default.{0}".FormatTo(expression);
            }
            string[]             arrs     = expression.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
            string               prefix   = arrs[0];
            string               name     = arrs[1];
            IEnvironmentProvider provider = _providers.FirstOrDefault(o => o.Prefix.Split('|').Contains(prefix, StringComparer.OrdinalIgnoreCase));

            if (provider != null)
            {
                value = provider.Resolve(name);
                if (value == null)
                {
                    return(false);
                }
                return(true);
            }
            value = null;
            return(false);
        }