コード例 #1
0
ファイル: Context.cs プロジェクト: yorek/dotliquid
        /// <summary>
        /// Fetches an object starting at the local scope and then moving up
        /// the hierarchy
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private object FindVariable(string key)
        {
            Hash   scope    = Scopes.FirstOrDefault(s => s.ContainsKey(key));
            object variable = null;

            if (scope == null)
            {
                foreach (Hash e in Environments)
                {
                    if ((variable = LookupAndEvaluate(e, key)) != null)
                    {
                        scope = e;
                        break;
                    }
                }
            }
            scope    = scope ?? Environments.LastOrDefault() ?? Scopes.Last();
            variable = variable ?? LookupAndEvaluate(scope, key);

            variable = Liquidize(variable);
            if (variable is IContextAware)
            {
                ((IContextAware)variable).Context = this;
            }
            return(variable);
        }
コード例 #2
0
        public void RemoveScope(int scopeId)
        {
            var scopeToRemove = Scopes.FirstOrDefault(s => s.ScopeId == scopeId);

            if (scopeToRemove != null)
            {
                Scopes.Remove(scopeToRemove);
            }
        }
コード例 #3
0
 public void AddScope(int scopeId)
 {
     if (Scopes.FirstOrDefault(s => s.ScopeId == scopeId) == null)
     {
         Scope s = new Scope(scopeId);
         if (s.ScopeId > 0)
         {
             Scopes.Add(s);
         }
         else
         {
             throw new ArgumentException("Scope not found.", "scopeId");
         }
     }
 }
コード例 #4
0
        // Get existing scope or add new one from symbol
        public Scope GetScope(string symbol)
        {
            var existing = Scopes.FirstOrDefault(x => x.Name
                                                 == Scope.ExtractScope(symbol));

            if (existing != null)
            {
                return(existing);
            }
            else
            {
                var newScope = Scope.ParseSymbol(this, symbol);
                Scopes.Add(newScope);
                return(newScope);
            }
        }
コード例 #5
0
ファイル: Context.cs プロジェクト: robin-parker/dotliquid
        /// <summary>
        /// Fetches an object starting at the local scope and then moving up
        /// the hierarchy
        /// </summary>
        /// <param name="key"></param>
        /// <param name="variable"></param>
        /// <returns></returns>
        private bool TryFindVariable(string key, out object variable)
        {
            bool   foundVariable = false;
            object foundValue    = null;
            Hash   scope         = Scopes.FirstOrDefault(s => s.ContainsKey(key));

            if (scope == null)
            {
                foreach (Hash environment in Environments)
                {
                    foundVariable = TryEvaluateHashOrArrayLikeObject(environment, key, out foundValue);
                    if (foundVariable)
                    {
                        scope = environment;
                        break;
                    }
                }

                if (scope == null)
                {
                    scope         = Environments.LastOrDefault() ?? Scopes.Last();
                    foundVariable = TryEvaluateHashOrArrayLikeObject(scope, key, out foundValue);
                }
            }
            else
            {
                foundVariable = TryEvaluateHashOrArrayLikeObject(scope, key, out foundValue);
            }

            variable = Liquidize(foundValue);
            if (variable is IContextAware contextAwareVariable)
            {
                contextAwareVariable.Context = this;
            }
            return(foundVariable);
        }
コード例 #6
0
 public virtual ApiScopeDto FindScope(string name)
 {
     return(Scopes.FirstOrDefault(r => r.Name == name));
 }
コード例 #7
0
 /// <summary>
 /// Searches <see cref="Scopes"/> list for the given scope name.
 /// </summary>
 /// <param name="scopeName">The scope name to look for. Must be fully qualified (e.x. facade:customers).</param>
 public Scope GetScope(string scopeName) => Scopes?.FirstOrDefault(x => x.Name == scopeName);
コード例 #8
0
 public virtual ApiResourceScope FindScope(string scope)
 {
     return(Scopes.FirstOrDefault(r => r.Scope == scope));
 }