Ejemplo n.º 1
0
        static JSNode()
        {
            var tNode         = typeof(JSNode);
            var typesToWalk   = (from t in tNode.Assembly.GetTypes() where tNode.IsAssignableFrom(t) select t).ToArray();
            var nodeTypesById = new List <Type>();

            // Assign a unique ID to all node types in the type hierarchy
            foreach (var nodeType in typesToWalk)
            {
                var type = nodeType;

                while (type != null)
                {
                    if (!TypeIds.ContainsKey(type))
                    {
                        TypeIds.Add(type, nodeTypesById.Count);
                        nodeTypesById.Add(type);
                    }

                    if (type == tNode)
                    {
                        break;
                    }

                    type = type.BaseType;
                }
            }

            NodeTypes = nodeTypesById.ToArray();
            NodeSelfAndBaseTypeIds = new int[NodeTypes.Length][];

            var ids = new List <int>();

            for (var i = 0; i < NodeTypes.Length; i++)
            {
                ids.Clear();

                var type = NodeTypes[i];
                while (type != null)
                {
                    ids.Add(GetTypeId(type));
                    if (type == tNode)
                    {
                        break;
                    }

                    type = type.BaseType;
                }

                NodeSelfAndBaseTypeIds[i] = ids.ToArray();
            }

            JSExpression.Initialize();
            JSNodeTraversalData.Initialize();
        }
Ejemplo n.º 2
0
        protected JSNode()
        {
            TypeId = GetTypeId(GetType());

            var td = JSNodeTraversalData.Get(TypeId);

            Children                 = new JSNodeChildren(this, td, false);
            SelfAndChildren          = new JSNodeChildren(this, td, true);
            AllChildrenRecursive     = new JSNodeChildrenRecursive(this, td, false);
            SelfAndChildrenRecursive = new JSNodeChildrenRecursive(this, td, true);
        }
Ejemplo n.º 3
0
        public JSNode()
        {
            TypeId = TypeIds[GetType()];

            var td = JSNodeTraversalData.Get(TypeId);

            Children                 = new JSNodeChildren(this, td, false);
            SelfAndChildren          = new JSNodeChildren(this, td, true);
            AllChildrenRecursive     = new JSNodeChildrenRecursive(this, td, false);
            SelfAndChildrenRecursive = new JSNodeChildrenRecursive(this, td, true);
        }
Ejemplo n.º 4
0
 public JSNodeChildEnumerator(JSNode node, JSNodeTraversalData traversalData, bool includeSelf)
 {
     TraversalData     = traversalData;
     Node              = node;
     IncludeSelf       = includeSelf;
     _Index            = IncludeSelf ? -2 : -1;
     _ArrayRecord      = null;
     _ArrayRecordState = default(JSNodeTraversalArrayRecordState);
     _Current          = null;
     _CurrentName      = null;
 }
Ejemplo n.º 5
0
        public static void EnsureTypeIdsAreAssigned()
        {
            if (AreTypeIdsAssigned)
            {
                return;
            }

            AreTypeIdsAssigned = true;

            var tNode       = typeof(JSNode);
            var typesToWalk = (
                from a in NodeAssemblies
                from t in TypesToWalk(a)
                where tNode.IsAssignableFrom(t)
                select t
                ).ToList();
            var nodeTypesById = new List <Type>();

            // Assign a unique ID to all node types in the type hierarchy
            foreach (var nodeType in typesToWalk)
            {
                var type = nodeType;

                while (type != null)
                {
                    if (!TypeIds.ContainsKey(type))
                    {
                        TypeIds.Add(type, nodeTypesById.Count);
                        nodeTypesById.Add(type);
                    }

                    if (type == tNode)
                    {
                        break;
                    }

                    type = type.BaseType;
                }
            }

            _NodeTypes = nodeTypesById.ToArray();
            _NodeSelfAndBaseTypeIds = new int[_NodeTypes.Length][];

            var ids = new List <int>();

            for (var i = 0; i < _NodeTypes.Length; i++)
            {
                ids.Clear();

                var type = _NodeTypes[i];
                while (type != null)
                {
                    ids.Add(GetTypeId(type));
                    if (type == tNode)
                    {
                        break;
                    }

                    type = type.BaseType;
                }

                _NodeSelfAndBaseTypeIds[i] = ids.ToArray();
            }

            JSExpression.Initialize();
            JSNodeTraversalData.Initialize();
        }
Ejemplo n.º 6
0
 public JSNodeChildrenRecursive(JSNode node, JSNodeTraversalData traversalData, bool includeSelf)
 {
     Node          = node;
     TraversalData = traversalData;
     IncludeSelf   = includeSelf;
 }
Ejemplo n.º 7
0
 public JSNodeChildren(JSNode node, JSNodeTraversalData traversalData, bool includeSelf)
 {
     EnumeratorTemplate = new JSNodeChildEnumerator(node, traversalData, includeSelf);
 }