// Token: 0x06006E21 RID: 28193 RVA: 0x001FB3C4 File Offset: 0x001F95C4 internal static BamlLocalizableResourceKey GetKey(BamlTreeNode node) { BamlLocalizableResourceKey result = null; BamlNodeType nodeType = node.NodeType; if (nodeType != BamlNodeType.StartElement) { if (nodeType != BamlNodeType.Property) { if (nodeType == BamlNodeType.LiteralContent) { BamlLiteralContentNode bamlLiteralContentNode = (BamlLiteralContentNode)node; BamlStartElementNode bamlStartElementNode = (BamlStartElementNode)node.Parent; if (bamlStartElementNode.Uid != null) { result = new BamlLocalizableResourceKey(bamlStartElementNode.Uid, bamlStartElementNode.TypeFullName, "$LiteralContent", bamlStartElementNode.AssemblyName); } } } else { BamlPropertyNode bamlPropertyNode = (BamlPropertyNode)node; BamlStartElementNode bamlStartElementNode2 = (BamlStartElementNode)bamlPropertyNode.Parent; if (bamlStartElementNode2.Uid != null) { string uid; if (bamlPropertyNode.Index <= 0) { uid = bamlStartElementNode2.Uid; } else { uid = string.Format(TypeConverterHelper.InvariantEnglishUS, "{0}.{1}_{2}", new object[] { bamlStartElementNode2.Uid, bamlPropertyNode.PropertyName, bamlPropertyNode.Index }); } result = new BamlLocalizableResourceKey(uid, bamlPropertyNode.OwnerTypeFullName, bamlPropertyNode.PropertyName, bamlPropertyNode.AssemblyName); } } } else { BamlStartElementNode bamlStartElementNode3 = (BamlStartElementNode)node; if (bamlStartElementNode3.Uid != null) { result = new BamlLocalizableResourceKey(bamlStartElementNode3.Uid, bamlStartElementNode3.TypeFullName, "$Content", bamlStartElementNode3.AssemblyName); } } return(result); }
// 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); } } } }
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); } } } }
//------------------------------------------------- // Internal static //------------------------------------------------- /// <summary> /// Return the localizable resource key for this baml tree node. /// If this node shouldn't be localized, the key returned will be null. /// </summary> internal static BamlLocalizableResourceKey GetKey(BamlTreeNode node) { BamlLocalizableResourceKey key = null; switch (node.NodeType) { case BamlNodeType.StartElement: { BamlStartElementNode elementNode = (BamlStartElementNode)node; if (elementNode.Uid != null) { key = new BamlLocalizableResourceKey( elementNode.Uid, elementNode.TypeFullName, BamlConst.ContentSuffix, elementNode.AssemblyName ); } break; } case BamlNodeType.Property: { BamlPropertyNode propertyNode = (BamlPropertyNode)node; BamlStartElementNode parent = (BamlStartElementNode)propertyNode.Parent; if (parent.Uid != null) { string uid; if (propertyNode.Index <= 0) { uid = parent.Uid; } else { // This node is auto-numbered. This has to do with the fact that // the compiler may compile duplicated properties into Baml under the same element. uid = string.Format( TypeConverterHelper.InvariantEnglishUS, "{0}.{1}_{2}", parent.Uid, propertyNode.PropertyName, propertyNode.Index ); } key = new BamlLocalizableResourceKey( uid, propertyNode.OwnerTypeFullName, propertyNode.PropertyName, propertyNode.AssemblyName ); } break; } case BamlNodeType.LiteralContent: { BamlLiteralContentNode literalNode = (BamlLiteralContentNode)node; BamlStartElementNode parent = (BamlStartElementNode)node.Parent; if (parent.Uid != null) { key = new BamlLocalizableResourceKey( parent.Uid, parent.TypeFullName, BamlConst.LiteralContentSuffix, parent.AssemblyName ); } break; } } return(key); }
//----------------------------- // private methods //----------------------------- /// <summary> /// build the baml element tree as well as the localizability inheritance tree /// </summary> /// <param name="bamlSteam">input baml stream.</param> /// <returns>the tree constructed.</returns> private BamlTree LoadBamlImp(Stream bamlSteam) { _reader = new BamlReader(bamlSteam); _reader.Read(); if (_reader.NodeType != BamlNodeType.StartDocument) { throw new XamlParseException(SR.Get(SRID.InvalidStartOfBaml)); } // create root element. _root = new BamlStartDocumentNode(); PushNodeToStack(_root); // A hash table used to handle duplicate properties within an element Hashtable propertyOccurrences = new Hashtable(8); // create the tree by depth first traversal. while (_bamlTreeStack.Count > 0 && _reader.Read()) { switch (_reader.NodeType) { case BamlNodeType.StartElement: { BamlTreeNode bamlNode = new BamlStartElementNode( _reader.AssemblyName, _reader.Name, _reader.IsInjected, _reader.CreateUsingTypeConverter ); PushNodeToStack(bamlNode); break; } case BamlNodeType.EndElement: { BamlTreeNode bamlNode = new BamlEndElementNode(); AddChildToCurrentParent(bamlNode); PopStack(); break; } case BamlNodeType.StartComplexProperty: { BamlStartComplexPropertyNode bamlNode = new BamlStartComplexPropertyNode( _reader.AssemblyName, _reader.Name.Substring(0, _reader.Name.LastIndexOf('.')), _reader.LocalName ); bamlNode.LocalizabilityAncestor = PeekPropertyStack(bamlNode.PropertyName); PushPropertyToStack(bamlNode.PropertyName, (ILocalizabilityInheritable)bamlNode); PushNodeToStack(bamlNode); break; } case BamlNodeType.EndComplexProperty: { BamlTreeNode bamlNode = new BamlEndComplexPropertyNode(); AddChildToCurrentParent(bamlNode); PopStack(); break; } case BamlNodeType.Event: { BamlTreeNode bamlNode = new BamlEventNode(_reader.Name, _reader.Value); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.RoutedEvent: { BamlTreeNode bamlNode = new BamlRoutedEventNode( _reader.AssemblyName, _reader.Name.Substring(0, _reader.Name.LastIndexOf('.')), _reader.LocalName, _reader.Value ); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.PIMapping: { BamlTreeNode bamlNode = new BamlPIMappingNode( _reader.XmlNamespace, _reader.ClrNamespace, _reader.AssemblyName ); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.LiteralContent: { BamlTreeNode bamlNode = new BamlLiteralContentNode(_reader.Value); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.Text: { BamlTreeNode bamlNode = new BamlTextNode( _reader.Value, _reader.TypeConverterAssemblyName, _reader.TypeConverterName ); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.StartConstructor: { BamlTreeNode bamlNode = new BamlStartConstructorNode(); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.EndConstructor: { BamlTreeNode bamlNode = new BamlEndConstructorNode(); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.EndDocument: { BamlTreeNode bamlNode = new BamlEndDocumentNode(); AddChildToCurrentParent(bamlNode); PopStack(); break; } default: { throw new XamlParseException(SR.Get(SRID.UnRecognizedBamlNodeType, _reader.NodeType)); } } // read properties if it has any. if (_reader.HasProperties) { // The Hashtable is used to auto-number repeated properties. The usage is as the following: // When encountering the 1st occurrence of the property, it stores a reference to the property's node (BamlTreeNode). // When encountering the property the 2nd time, we start auto-numbering the property including the 1st occurrence // and store the index count (int) in the slot from that point onwards. propertyOccurrences.Clear(); _reader.MoveToFirstProperty(); do { switch (_reader.NodeType) { case BamlNodeType.ConnectionId: { BamlTreeNode bamlNode = new BamlConnectionIdNode(_reader.ConnectionId); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.Property: { BamlPropertyNode bamlNode = new BamlPropertyNode( _reader.AssemblyName, _reader.Name.Substring(0, _reader.Name.LastIndexOf('.')), _reader.LocalName, _reader.Value, _reader.AttributeUsage ); bamlNode.LocalizabilityAncestor = PeekPropertyStack(bamlNode.PropertyName); PushPropertyToStack(bamlNode.PropertyName, (ILocalizabilityInheritable)bamlNode); AddChildToCurrentParent(bamlNode); if (propertyOccurrences.Contains(_reader.Name)) { // we autonumber properties that have occurrences larger than 1 object occurrence = propertyOccurrences[_reader.Name]; int index = 2; if (occurrence is BamlPropertyNode) { // start numbering this property as the 2nd occurrence is encountered // the value stores the 1st occurrence of the property at this point ((BamlPropertyNode)occurrence).Index = 1; } else { // For the 3rd or more occurrences, the value stores the next index // to assign to the property index = (int)occurrence; } // auto-number the current property node ((BamlPropertyNode)bamlNode).Index = index; propertyOccurrences[_reader.Name] = ++index; } else { // store the first occurrence of the property propertyOccurrences[_reader.Name] = bamlNode; } break; } case BamlNodeType.DefAttribute: { if (_reader.Name == XamlReaderHelper.DefinitionUid) { // set the Uid proeprty when we see it. ((BamlStartElementNode)_currentParent).Uid = _reader.Value; } BamlTreeNode bamlNode = new BamlDefAttributeNode( _reader.Name, _reader.Value ); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.XmlnsProperty: { BamlTreeNode bamlNode = new BamlXmlnsPropertyNode( _reader.LocalName, _reader.Value ); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.ContentProperty: { BamlTreeNode bamlNode = new BamlContentPropertyNode( _reader.AssemblyName, _reader.Name.Substring(0, _reader.Name.LastIndexOf('.')), _reader.LocalName ); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.PresentationOptionsAttribute: { BamlTreeNode bamlNode = new BamlPresentationOptionsAttributeNode( _reader.Name, _reader.Value ); AddChildToCurrentParent(bamlNode); break; } default: { throw new XamlParseException(SR.Get(SRID.UnRecognizedBamlNodeType, _reader.NodeType)); } } } while (_reader.MoveToNextProperty()); } } // At this point, the baml tree stack should be completely unwinded and also nothing more to read. if (_reader.Read() || _bamlTreeStack.Count > 0) { throw new XamlParseException(SR.Get(SRID.InvalidEndOfBaml)); } return(new BamlTree(_root, _nodeCount)); //notice that we don't close the input stream because we don't own it. }
//----------------------------- // private methods //----------------------------- /// <summary> /// build the baml element tree as well as the localizability inheritance tree /// </summary> /// <param name="bamlSteam">input baml stream.</param> /// <returns>the tree constructed.</returns> private BamlTree LoadBamlImp(Stream bamlSteam) { _reader = new BamlReader(bamlSteam); _reader.Read(); if (_reader.NodeType != BamlNodeType.StartDocument) { throw new XamlParseException(SR.Get(SRID.InvalidStartOfBaml)); } // create root element. _root = new BamlStartDocumentNode(); PushNodeToStack(_root); // A hash table used to handle duplicate properties within an element Hashtable propertyOccurrences = new Hashtable(8); // create the tree by depth first traversal. while (_bamlTreeStack.Count > 0 && _reader.Read()) { switch (_reader.NodeType) { case BamlNodeType.StartElement : { BamlTreeNode bamlNode = new BamlStartElementNode( _reader.AssemblyName, _reader.Name, _reader.IsInjected, _reader.CreateUsingTypeConverter ); PushNodeToStack(bamlNode); break; } case BamlNodeType.EndElement : { BamlTreeNode bamlNode = new BamlEndElementNode(); AddChildToCurrentParent(bamlNode); PopStack(); break; } case BamlNodeType.StartComplexProperty : { BamlStartComplexPropertyNode bamlNode = new BamlStartComplexPropertyNode( _reader.AssemblyName, _reader.Name.Substring(0, _reader.Name.LastIndexOf('.')), _reader.LocalName ); bamlNode.LocalizabilityAncestor = PeekPropertyStack(bamlNode.PropertyName); PushPropertyToStack(bamlNode.PropertyName, (ILocalizabilityInheritable) bamlNode); PushNodeToStack(bamlNode); break; } case BamlNodeType.EndComplexProperty : { BamlTreeNode bamlNode = new BamlEndComplexPropertyNode(); AddChildToCurrentParent(bamlNode); PopStack(); break; } case BamlNodeType.Event : { BamlTreeNode bamlNode = new BamlEventNode(_reader.Name, _reader.Value); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.RoutedEvent : { BamlTreeNode bamlNode = new BamlRoutedEventNode( _reader.AssemblyName, _reader.Name.Substring(0, _reader.Name.LastIndexOf('.')), _reader.LocalName, _reader.Value ); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.PIMapping : { BamlTreeNode bamlNode = new BamlPIMappingNode( _reader.XmlNamespace, _reader.ClrNamespace, _reader.AssemblyName ); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.LiteralContent : { BamlTreeNode bamlNode = new BamlLiteralContentNode(_reader.Value); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.Text : { BamlTreeNode bamlNode = new BamlTextNode( _reader.Value, _reader.TypeConverterAssemblyName, _reader.TypeConverterName ); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.StartConstructor : { BamlTreeNode bamlNode = new BamlStartConstructorNode(); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.EndConstructor : { BamlTreeNode bamlNode = new BamlEndConstructorNode(); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.EndDocument : { BamlTreeNode bamlNode = new BamlEndDocumentNode(); AddChildToCurrentParent(bamlNode); PopStack(); break; } default : { throw new XamlParseException(SR.Get(SRID.UnRecognizedBamlNodeType, _reader.NodeType)); } } // read properties if it has any. if (_reader.HasProperties) { // The Hashtable is used to auto-number repeated properties. The usage is as the following: // When encountering the 1st occurrence of the property, it stores a reference to the property's node (BamlTreeNode). // When encountering the property the 2nd time, we start auto-numbering the property including the 1st occurrence // and store the index count (int) in the slot from that point onwards. propertyOccurrences.Clear(); _reader.MoveToFirstProperty(); do { switch (_reader.NodeType) { case BamlNodeType.ConnectionId: { BamlTreeNode bamlNode = new BamlConnectionIdNode(_reader.ConnectionId); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.Property : { BamlPropertyNode bamlNode = new BamlPropertyNode( _reader.AssemblyName, _reader.Name.Substring(0, _reader.Name.LastIndexOf('.')), _reader.LocalName, _reader.Value, _reader.AttributeUsage ); bamlNode.LocalizabilityAncestor = PeekPropertyStack(bamlNode.PropertyName); PushPropertyToStack(bamlNode.PropertyName, (ILocalizabilityInheritable) bamlNode); AddChildToCurrentParent(bamlNode); if (propertyOccurrences.Contains(_reader.Name)) { // we autonumber properties that have occurrences larger than 1 object occurrence = propertyOccurrences[_reader.Name]; int index = 2; if (occurrence is BamlPropertyNode) { // start numbering this property as the 2nd occurrence is encountered // the value stores the 1st occurrence of the property at this point ((BamlPropertyNode) occurrence).Index = 1; }else { // For the 3rd or more occurrences, the value stores the next index // to assign to the property index = (int) occurrence; } // auto-number the current property node ((BamlPropertyNode)bamlNode).Index = index; propertyOccurrences[_reader.Name] = ++index; } else { // store the first occurrence of the property propertyOccurrences[_reader.Name] = bamlNode; } break; } case BamlNodeType.DefAttribute : { if (_reader.Name == XamlReaderHelper.DefinitionUid) { // set the Uid proeprty when we see it. ((BamlStartElementNode)_currentParent).Uid = _reader.Value; } BamlTreeNode bamlNode = new BamlDefAttributeNode( _reader.Name, _reader.Value ); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.XmlnsProperty : { BamlTreeNode bamlNode = new BamlXmlnsPropertyNode( _reader.LocalName, _reader.Value ); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.ContentProperty : { BamlTreeNode bamlNode = new BamlContentPropertyNode( _reader.AssemblyName, _reader.Name.Substring(0, _reader.Name.LastIndexOf('.')), _reader.LocalName ); AddChildToCurrentParent(bamlNode); break; } case BamlNodeType.PresentationOptionsAttribute: { BamlTreeNode bamlNode = new BamlPresentationOptionsAttributeNode( _reader.Name, _reader.Value ); AddChildToCurrentParent(bamlNode); break; } default : { throw new XamlParseException(SR.Get(SRID.UnRecognizedBamlNodeType, _reader.NodeType)); } } } while (_reader.MoveToNextProperty()); } } // At this point, the baml tree stack should be completely unwinded and also nothing more to read. if (_reader.Read() || _bamlTreeStack.Count > 0) { throw new XamlParseException(SR.Get(SRID.InvalidEndOfBaml)); } return new BamlTree(_root, _nodeCount); //notice that we don't close the input stream because we don't own it. }
// Token: 0x06006E10 RID: 28176 RVA: 0x001FA87C File Offset: 0x001F8A7C private BamlTree LoadBamlImp(Stream bamlSteam) { this._reader = new BamlReader(bamlSteam); this._reader.Read(); if (this._reader.NodeType != BamlNodeType.StartDocument) { throw new XamlParseException(SR.Get("InvalidStartOfBaml")); } this._root = new BamlStartDocumentNode(); this.PushNodeToStack(this._root); Hashtable hashtable = new Hashtable(8); IL_5C8: while (this._bamlTreeStack.Count > 0 && this._reader.Read()) { switch (this._reader.NodeType) { case BamlNodeType.EndDocument: { BamlTreeNode node = new BamlEndDocumentNode(); this.AddChildToCurrentParent(node); this.PopStack(); break; } case BamlNodeType.ConnectionId: case BamlNodeType.Property: case BamlNodeType.ContentProperty: case BamlNodeType.XmlnsProperty: case BamlNodeType.IncludeReference: case BamlNodeType.DefAttribute: case BamlNodeType.PresentationOptionsAttribute: goto IL_2DF; case BamlNodeType.StartElement: { BamlTreeNode node2 = new BamlStartElementNode(this._reader.AssemblyName, this._reader.Name, this._reader.IsInjected, this._reader.CreateUsingTypeConverter); this.PushNodeToStack(node2); break; } case BamlNodeType.EndElement: { BamlTreeNode node3 = new BamlEndElementNode(); this.AddChildToCurrentParent(node3); this.PopStack(); break; } case BamlNodeType.StartComplexProperty: { BamlStartComplexPropertyNode bamlStartComplexPropertyNode = new BamlStartComplexPropertyNode(this._reader.AssemblyName, this._reader.Name.Substring(0, this._reader.Name.LastIndexOf('.')), this._reader.LocalName); bamlStartComplexPropertyNode.LocalizabilityAncestor = this.PeekPropertyStack(bamlStartComplexPropertyNode.PropertyName); this.PushPropertyToStack(bamlStartComplexPropertyNode.PropertyName, bamlStartComplexPropertyNode); this.PushNodeToStack(bamlStartComplexPropertyNode); break; } case BamlNodeType.EndComplexProperty: { BamlTreeNode node4 = new BamlEndComplexPropertyNode(); this.AddChildToCurrentParent(node4); this.PopStack(); break; } case BamlNodeType.LiteralContent: { BamlTreeNode node5 = new BamlLiteralContentNode(this._reader.Value); this.AddChildToCurrentParent(node5); break; } case BamlNodeType.Text: { BamlTreeNode node6 = new BamlTextNode(this._reader.Value, this._reader.TypeConverterAssemblyName, this._reader.TypeConverterName); this.AddChildToCurrentParent(node6); break; } case BamlNodeType.RoutedEvent: { BamlTreeNode node7 = new BamlRoutedEventNode(this._reader.AssemblyName, this._reader.Name.Substring(0, this._reader.Name.LastIndexOf('.')), this._reader.LocalName, this._reader.Value); this.AddChildToCurrentParent(node7); break; } case BamlNodeType.Event: { BamlTreeNode node8 = new BamlEventNode(this._reader.Name, this._reader.Value); this.AddChildToCurrentParent(node8); break; } case BamlNodeType.PIMapping: { BamlTreeNode node9 = new BamlPIMappingNode(this._reader.XmlNamespace, this._reader.ClrNamespace, this._reader.AssemblyName); this.AddChildToCurrentParent(node9); break; } case BamlNodeType.StartConstructor: { BamlTreeNode node10 = new BamlStartConstructorNode(); this.AddChildToCurrentParent(node10); break; } case BamlNodeType.EndConstructor: { BamlTreeNode node11 = new BamlEndConstructorNode(); this.AddChildToCurrentParent(node11); break; } default: goto IL_2DF; } if (this._reader.HasProperties) { hashtable.Clear(); this._reader.MoveToFirstProperty(); for (;;) { BamlNodeType nodeType = this._reader.NodeType; switch (nodeType) { case BamlNodeType.ConnectionId: { BamlTreeNode node12 = new BamlConnectionIdNode(this._reader.ConnectionId); this.AddChildToCurrentParent(node12); break; } case BamlNodeType.StartElement: case BamlNodeType.EndElement: goto IL_58F; case BamlNodeType.Property: { BamlPropertyNode bamlPropertyNode = new BamlPropertyNode(this._reader.AssemblyName, this._reader.Name.Substring(0, this._reader.Name.LastIndexOf('.')), this._reader.LocalName, this._reader.Value, this._reader.AttributeUsage); bamlPropertyNode.LocalizabilityAncestor = this.PeekPropertyStack(bamlPropertyNode.PropertyName); this.PushPropertyToStack(bamlPropertyNode.PropertyName, bamlPropertyNode); this.AddChildToCurrentParent(bamlPropertyNode); if (hashtable.Contains(this._reader.Name)) { object obj = hashtable[this._reader.Name]; int num = 2; if (obj is BamlPropertyNode) { ((BamlPropertyNode)obj).Index = 1; } else { num = (int)obj; } bamlPropertyNode.Index = num; hashtable[this._reader.Name] = num + 1; } else { hashtable[this._reader.Name] = bamlPropertyNode; } break; } case BamlNodeType.ContentProperty: { BamlTreeNode node13 = new BamlContentPropertyNode(this._reader.AssemblyName, this._reader.Name.Substring(0, this._reader.Name.LastIndexOf('.')), this._reader.LocalName); this.AddChildToCurrentParent(node13); break; } case BamlNodeType.XmlnsProperty: { BamlTreeNode node14 = new BamlXmlnsPropertyNode(this._reader.LocalName, this._reader.Value); this.AddChildToCurrentParent(node14); break; } default: if (nodeType != BamlNodeType.DefAttribute) { if (nodeType != BamlNodeType.PresentationOptionsAttribute) { goto Block_6; } BamlTreeNode node15 = new BamlPresentationOptionsAttributeNode(this._reader.Name, this._reader.Value); this.AddChildToCurrentParent(node15); } else { if (this._reader.Name == "Uid") { ((BamlStartElementNode)this._currentParent).Uid = this._reader.Value; } BamlTreeNode node16 = new BamlDefAttributeNode(this._reader.Name, this._reader.Value); this.AddChildToCurrentParent(node16); } break; } if (!this._reader.MoveToNextProperty()) { goto IL_5C8; } } Block_6: IL_58F: throw new XamlParseException(SR.Get("UnRecognizedBamlNodeType", new object[] { this._reader.NodeType })); } continue; IL_2DF: throw new XamlParseException(SR.Get("UnRecognizedBamlNodeType", new object[] { this._reader.NodeType })); } if (this._reader.Read() || this._bamlTreeStack.Count > 0) { throw new XamlParseException(SR.Get("InvalidEndOfBaml")); } return(new BamlTree(this._root, this._nodeCount)); }
// Token: 0x06006EAC RID: 28332 RVA: 0x001FC674 File Offset: 0x001FA874 private static bool ApplyChangeToBamlTree(BamlLocalizableResourceKey key, BamlLocalizableResource resource, BamlTreeUpdater.BamlTreeUpdateMap treeMap) { if (resource == null || resource.Content == null || !resource.Modifiable) { return(true); } if (!treeMap.LocalizationDictionary.Contains(key) && !treeMap.IsNewBamlTreeNode(key)) { return(true); } BamlTreeNode bamlTreeNode = treeMap.MapKeyToBamlTreeNode(key); Invariant.Assert(bamlTreeNode != null); BamlNodeType nodeType = bamlTreeNode.NodeType; if (nodeType != BamlNodeType.StartElement) { if (nodeType != BamlNodeType.Property) { if (nodeType == BamlNodeType.LiteralContent) { BamlLiteralContentNode bamlLiteralContentNode = (BamlLiteralContentNode)bamlTreeNode; bamlLiteralContentNode.Content = BamlResourceContentUtil.UnescapeString(resource.Content); if (bamlLiteralContentNode.Parent == null) { BamlTreeNode bamlTreeNode2 = treeMap.MapUidToBamlTreeElementNode(key.Uid); if (bamlTreeNode2 == null) { return(false); } bamlTreeNode2.AddChild(bamlLiteralContentNode); } } } else { BamlPropertyNode bamlPropertyNode = (BamlPropertyNode)bamlTreeNode; bamlPropertyNode.Value = BamlResourceContentUtil.UnescapeString(resource.Content); if (bamlPropertyNode.Parent == null) { BamlStartElementNode bamlStartElementNode = treeMap.MapUidToBamlTreeElementNode(key.Uid); if (bamlStartElementNode == null) { return(false); } bamlStartElementNode.InsertProperty(bamlTreeNode); } } } else { string b = null; if (treeMap.LocalizationDictionary.Contains(key)) { b = treeMap.LocalizationDictionary[key].Content; } if (resource.Content != b) { BamlTreeUpdater.ReArrangeChildren(key, bamlTreeNode, resource.Content, treeMap); } } return(true); }
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); } } } }
private static bool ApplyChangeToBamlTree( BamlLocalizableResourceKey key, BamlLocalizableResource resource, BamlTreeUpdateMap treeMap ) { if (resource == null || resource.Content == null || !resource.Modifiable) { // Invalid translation or the resource is marked as non-modifiable. return(true); } if (!treeMap.LocalizationDictionary.Contains(key) && !treeMap.IsNewBamlTreeNode(key)) { // A localizable node is either in the localization dicationary extracted // from the source or it is a new node created by the localizer. // Otherwise, we cannot modify it. return(true); } // get the node, at this point, all the missing nodes are created BamlTreeNode node = treeMap.MapKeyToBamlTreeNode(key); Invariant.Assert(node != null); // apply translations switch (node.NodeType) { case BamlNodeType.LiteralContent: { BamlLiteralContentNode literalNode = (BamlLiteralContentNode)node; // set the content to the node. literalNode.Content = BamlResourceContentUtil.UnescapeString(resource.Content); // now try to link this node into the parent. if (literalNode.Parent == null) { BamlTreeNode parent = treeMap.MapUidToBamlTreeElementNode(key.Uid); if (parent != null) { // link it up with the parent parent.AddChild(literalNode); } else { return(false); // can't resolve the parent yet } } break; } case BamlNodeType.Property: { BamlPropertyNode propertyNode = (BamlPropertyNode)node; // set the translation into the property propertyNode.Value = BamlResourceContentUtil.UnescapeString(resource.Content); // now try to link this node into the parent if (propertyNode.Parent == null) { BamlStartElementNode parent = (BamlStartElementNode)treeMap.MapUidToBamlTreeElementNode(key.Uid); if (parent != null) { // insert property node to the parent parent.InsertProperty(node); } else { return(false); } } break; } case BamlNodeType.StartElement: { string source = null; if (treeMap.LocalizationDictionary.Contains(key)) { source = ((BamlLocalizableResource)treeMap.LocalizationDictionary[key]).Content; } if (resource.Content != source) { // only rearrange the value if source and update are different ReArrangeChildren(key, node, resource.Content, treeMap); } break; } default: break; } return(true); }