//-----------------------------
        // internal methods
        //-----------------------------

        internal static void UpdateTree(
            BamlTree tree,
            BamlTreeMap treeMap,
            BamlLocalizationDictionary dictionary
            )
        {
            Debug.Assert(tree != null && tree.Root != null, "Empty Tree!");
            Debug.Assert(treeMap != null, "Empty map!");
            Debug.Assert(dictionary != null, "Empty dictionary");

            // no changes to do to the tree.
            if (dictionary.Count <= 0)
            {
                return;
            }

            // create a tree map to be used for update
            BamlTreeUpdateMap updateMap = new BamlTreeUpdateMap(treeMap, tree);

            //
            // a) Create baml tree nodes for missing child place holders and properties.
            //    Translations may require new nodes to be constructed. For example
            //    translation contains new child place holders
            //
            CreateMissingBamlTreeNode(dictionary, updateMap);


            //
            // b) Look through each translation and make modification to the tree
            //    At this step, new nodes are linked to the tree if applicable.
            //
            BamlLocalizationDictionaryEnumerator enumerator = dictionary.GetEnumerator();
            ArrayList deferredResources = new ArrayList();

            while (enumerator.MoveNext())
            {
                if (!ApplyChangeToBamlTree(enumerator.Key, enumerator.Value, updateMap))
                {
                    deferredResources.Add(enumerator.Entry);
                }
            }

            //
            // c) Hook up the property nodes that aren't hooked up yet
            //    Formatting tags inserted in the translation will only be created the
            //    previous step. Hook up properties to those nodes now if applicable
            //
            for (int i = 0; i < deferredResources.Count; i++)
            {
                DictionaryEntry entry = (DictionaryEntry)deferredResources[i];
                ApplyChangeToBamlTree(
                    (BamlLocalizableResourceKey)entry.Key,
                    (BamlLocalizableResource)entry.Value,
                    updateMap
                    );
            }
        }
        // Token: 0x06006EAB RID: 28331 RVA: 0x001FC55C File Offset: 0x001FA75C
        private static void CreateMissingBamlTreeNode(BamlLocalizationDictionary dictionary, BamlTreeUpdater.BamlTreeUpdateMap treeMap)
        {
            BamlLocalizationDictionaryEnumerator enumerator = dictionary.GetEnumerator();

            while (enumerator.MoveNext())
            {
                BamlLocalizableResourceKey key   = enumerator.Key;
                BamlLocalizableResource    value = enumerator.Value;
                if (treeMap.MapKeyToBamlTreeNode(key) == null)
                {
                    if (key.PropertyName == "$Content")
                    {
                        if (treeMap.MapUidToBamlTreeElementNode(key.Uid) == null)
                        {
                            BamlStartElementNode bamlStartElementNode = new BamlStartElementNode(treeMap.Resolver.ResolveAssemblyFromClass(key.ClassName), key.ClassName, false, false);
                            bamlStartElementNode.AddChild(new BamlDefAttributeNode("Uid", key.Uid));
                            BamlTreeUpdater.TryAddContentPropertyToNewElement(treeMap, bamlStartElementNode);
                            bamlStartElementNode.AddChild(new BamlEndElementNode());
                            treeMap.AddBamlTreeNode(key.Uid, key, bamlStartElementNode);
                        }
                    }
                    else
                    {
                        BamlTreeNode node;
                        if (key.PropertyName == "$LiteralContent")
                        {
                            node = new BamlLiteralContentNode(value.Content);
                        }
                        else
                        {
                            node = new BamlPropertyNode(treeMap.Resolver.ResolveAssemblyFromClass(key.ClassName), key.ClassName, key.PropertyName, value.Content, BamlAttributeUsage.Default);
                        }
                        treeMap.AddBamlTreeNode(null, key, node);
                    }
                }
            }
        }
        // Token: 0x06006EAA RID: 28330 RVA: 0x001FC4B8 File Offset: 0x001FA6B8
        internal static void UpdateTree(BamlTree tree, BamlTreeMap treeMap, BamlLocalizationDictionary dictionary)
        {
            if (dictionary.Count <= 0)
            {
                return;
            }
            BamlTreeUpdater.BamlTreeUpdateMap treeMap2 = new BamlTreeUpdater.BamlTreeUpdateMap(treeMap, tree);
            BamlTreeUpdater.CreateMissingBamlTreeNode(dictionary, treeMap2);
            BamlLocalizationDictionaryEnumerator enumerator = dictionary.GetEnumerator();
            ArrayList arrayList = new ArrayList();

            while (enumerator.MoveNext())
            {
                if (!BamlTreeUpdater.ApplyChangeToBamlTree(enumerator.Key, enumerator.Value, treeMap2))
                {
                    arrayList.Add(enumerator.Entry);
                }
            }
            for (int i = 0; i < arrayList.Count; i++)
            {
                DictionaryEntry dictionaryEntry = (DictionaryEntry)arrayList[i];
                BamlTreeUpdater.ApplyChangeToBamlTree((BamlLocalizableResourceKey)dictionaryEntry.Key, (BamlLocalizableResource)dictionaryEntry.Value, treeMap2);
            }
        }
        private static void CreateMissingBamlTreeNode(
            BamlLocalizationDictionary dictionary,
            BamlTreeUpdateMap treeMap
            )
        {
            BamlLocalizationDictionaryEnumerator enumerator = dictionary.GetEnumerator();

            while (enumerator.MoveNext())
            {
                BamlLocalizableResourceKey key      = enumerator.Key;
                BamlLocalizableResource    resource = enumerator.Value;

                // get the baml tree node from the tree
                BamlTreeNode node = treeMap.MapKeyToBamlTreeNode(key);

                if (node == null)
                {
                    if (key.PropertyName == BamlConst.ContentSuffix)
                    {
                        // see if there is already a Baml node with the Uid. If so
                        // ignore this entry
                        node = treeMap.MapUidToBamlTreeElementNode(key.Uid);
                        if (node == null)
                        {
                            // create new Baml element node
                            BamlStartElementNode newNode = new BamlStartElementNode(
                                treeMap.Resolver.ResolveAssemblyFromClass(key.ClassName),
                                key.ClassName,
                                false, /*isInjected*/
                                false  /*CreateUsingTypeConverter*/
                                );

                            // create new x:Uid node for this element node
                            newNode.AddChild(
                                new BamlDefAttributeNode(
                                    XamlReaderHelper.DefinitionUid,
                                    key.Uid
                                    )
                                );

                            TryAddContentPropertyToNewElement(treeMap, newNode);

                            // terminate the node with EndElementNode
                            newNode.AddChild(new BamlEndElementNode());

                            // store this new node into the map so that it can be found
                            // when other translations reference it as a childplace holder, or property owner
                            treeMap.AddBamlTreeNode(key.Uid, key, newNode);
                        }
                    }
                    else
                    {
                        BamlTreeNode newNode;
                        if (key.PropertyName == BamlConst.LiteralContentSuffix)
                        {
                            // create a LiterContent node
                            newNode = new BamlLiteralContentNode(resource.Content);
                        }
                        else
                        {
                            newNode = new BamlPropertyNode(
                                treeMap.Resolver.ResolveAssemblyFromClass(key.ClassName),
                                key.ClassName,
                                key.PropertyName,
                                resource.Content,
                                BamlAttributeUsage.Default
                                );
                        }

                        // add to the map
                        treeMap.AddBamlTreeNode(null, key, newNode);
                    }
                }
            }
        }