// Token: 0x06006EB6 RID: 28342 RVA: 0x001FCF00 File Offset: 0x001FB100 internal bool TryGetContent(BamlLocalizableResourceKey key, BamlTreeNode currentNode, out string content) { content = string.Empty; BamlNodeType nodeType = currentNode.NodeType; if (nodeType == BamlNodeType.StartElement) { BamlStartElementNode bamlStartElementNode = (BamlStartElementNode)currentNode; if (bamlStartElementNode.Content == null) { StringBuilder stringBuilder = new StringBuilder(); foreach (BamlTreeNode bamlTreeNode in bamlStartElementNode.Children) { nodeType = bamlTreeNode.NodeType; if (nodeType != BamlNodeType.StartElement) { if (nodeType == BamlNodeType.Text) { stringBuilder.Append(BamlResourceContentUtil.EscapeString(((BamlTextNode)bamlTreeNode).Content)); } } else { string value; if (!this.TryFormatElementContent(key, (BamlStartElementNode)bamlTreeNode, out value)) { return(false); } stringBuilder.Append(value); } } bamlStartElementNode.Content = stringBuilder.ToString(); } content = bamlStartElementNode.Content; return(true); } if (nodeType == BamlNodeType.Property) { bool result = true; BamlPropertyNode bamlPropertyNode = (BamlPropertyNode)currentNode; content = BamlResourceContentUtil.EscapeString(bamlPropertyNode.Value); string text = content; string text2; string text3; if (MarkupExtensionParser.GetMarkupExtensionTypeAndArgs(ref text, out text2, out text3)) { LocalizabilityGroup localizabilityComment = this._resolver.GetLocalizabilityComment(bamlPropertyNode.Parent as BamlStartElementNode, bamlPropertyNode.PropertyName); result = (localizabilityComment != null && localizabilityComment.Readability == Readability.Readable); } return(result); } if (nodeType != BamlNodeType.LiteralContent) { return(true); } content = BamlResourceContentUtil.EscapeString(((BamlLiteralContentNode)currentNode).Content); return(true); }
/// <summary> /// This builds the localizable string from the baml tree node /// </summary> /// <return> /// return true when the node has valid localizable content, false otherwise. /// </return> internal bool TryGetContent(BamlLocalizableResourceKey key, BamlTreeNode currentNode, out string content) { content = string.Empty; switch (currentNode.NodeType) { case BamlNodeType.Property: { bool isValidContent = true; BamlPropertyNode propertyNode = (BamlPropertyNode)currentNode; content = BamlResourceContentUtil.EscapeString(propertyNode.Value); // // Markup extensions are not localizable values, e.g. {x:Type SolidColorBrush}. // So if the string can be parsed as Markup extensions, we will exclude it unless // the user sets localization comments explicitly to localize this value. // string typeName, args; string tempContent = content; if (MarkupExtensionParser.GetMarkupExtensionTypeAndArgs(ref tempContent, out typeName, out args)) { // See if this value has been marked as localizable explicitly in comments LocalizabilityGroup localizability = _resolver.GetLocalizabilityComment( propertyNode.Parent as BamlStartElementNode, propertyNode.PropertyName ); isValidContent = (localizability != null && localizability.Readability == Readability.Readable); } return(isValidContent); } case BamlNodeType.LiteralContent: { content = BamlResourceContentUtil.EscapeString( ((BamlLiteralContentNode)currentNode).Content ); return(true); // succeed } case BamlNodeType.StartElement: { BamlStartElementNode elementNode = (BamlStartElementNode)currentNode; if (elementNode.Content == null) { StringBuilder contentBuilder = new StringBuilder(); foreach (BamlTreeNode child in elementNode.Children) { // we only format element and text inline // other nodes like property node we don't put them into the content of the element switch (child.NodeType) { case BamlNodeType.StartElement: { string childContent; if (TryFormatElementContent(key, (BamlStartElementNode)child, out childContent)) { contentBuilder.Append(childContent); } else { return(false); // failed to get content for children element } break; } case BamlNodeType.Text: { contentBuilder.Append(BamlResourceContentUtil.EscapeString( ((BamlTextNode)child).Content) ); break; } } } elementNode.Content = contentBuilder.ToString(); } content = elementNode.Content; return(true); } default: return(true); } }