예제 #1
0
            public static void Tranverse(Action <Property, int> action, VariableDependencyNode node, int depth)
            {
                action(node.Variable, depth);

                if (node.Children != null)
                {
                    foreach (var child in node.Children)
                    {
                        Tranverse(action, child, depth + 1);
                    }
                }
            }
예제 #2
0
        static VariableDependencyNode BuildVariableDependencies(Property var, Dictionary <string, Property> variables, ref Dictionary <string, VariableDependencyNode> dependencies)
        {
            VariableDependencyNode varNode = null;

            if (dependencies.TryGetValue(var.Name, out varNode) == false)
            {
                varNode = dependencies[var.Name] = new VariableDependencyNode(var);

                foreach (var value in var.Values)
                {
                    if (IsVariableValue(value))
                    {
                        Property variableProperty = null;

                        if (value.ValueType == StyleValueType.Function)
                        {
                            var functionValue = value as Function;

                            if (functionValue != null)
                            {
                                variables.TryGetValue(functionValue.args[0][0].AsString(), out variableProperty);
                            }
                        }
                        else
                        {
                            variables.TryGetValue(value.AsString(), out variableProperty);
                        }

                        if (variableProperty == null)
                        {
                            continue;
                        }

                        var referredVarNode = BuildVariableDependencies(variableProperty, variables, ref dependencies);

                        if (varNode.Parent == null) // in case the the variable is referred multiple times.
                        {
                            if (referredVarNode.Children == null)
                            {
                                referredVarNode.Children = new List <VariableDependencyNode>();
                            }
                            referredVarNode.Children.Add(varNode);
                            varNode.Parent = referredVarNode;
                        }
                    }
                }
            }
            return(varNode);
        }