CalDavSynchronizer.Conversions.Msft.HtmlFromXamlConverter.WriteElementContent C# (CSharp) Method

WriteElementContent() private static method

Reads a content of current xaml element, converts it
private static WriteElementContent ( XmlTextReader xamlReader, XmlTextWriter htmlWriter, StringBuilder inlineStyle ) : void
xamlReader System.Xml.XmlTextReader /// XmlTextReader which is expected to be at XmlNodeType.Element /// (opening element tag) position. ///
htmlWriter System.Xml.XmlTextWriter /// May be null, in which case we are skipping the xaml element; /// witout producing any output to html. ///
inlineStyle StringBuilder /// StringBuilder used for collecting css properties for inline STYLE attribute. ///
return void
    private static void WriteElementContent(XmlTextReader xamlReader, XmlTextWriter htmlWriter, StringBuilder inlineStyle)
    {
      Debug.Assert(xamlReader.NodeType == XmlNodeType.Element);

      bool elementContentStarted = false;

      if (xamlReader.IsEmptyElement)
      {
        if (htmlWriter != null && !elementContentStarted && inlineStyle.Length > 0)
        {
          // Output STYLE attribute and clear inlineStyle buffer.
          htmlWriter.WriteAttributeString("STYLE", inlineStyle.ToString());
          inlineStyle.Remove(0, inlineStyle.Length);
        }
        elementContentStarted = true;
      }
      else
      {
        while (ReadNextToken(xamlReader) && xamlReader.NodeType != XmlNodeType.EndElement)
        {
          switch (xamlReader.NodeType)
          {
            case XmlNodeType.Element:
              if (xamlReader.Name.Contains(".") && !xamlReader.Name.Equals("Table.Columns"))
              {
                AddComplexProperty(xamlReader, inlineStyle);
              }
              else
              {
                if (htmlWriter != null && !elementContentStarted && inlineStyle.Length > 0)
                {
                  // Output STYLE attribute and clear inlineStyle buffer.
                  htmlWriter.WriteAttributeString("STYLE", inlineStyle.ToString());
                  inlineStyle.Remove(0, inlineStyle.Length);
                }
                elementContentStarted = true;
                WriteElement(xamlReader, htmlWriter, inlineStyle);
              }
              Debug.Assert(xamlReader.NodeType == XmlNodeType.EndElement || xamlReader.NodeType == XmlNodeType.Element && xamlReader.IsEmptyElement);
              break;
            case XmlNodeType.Comment:
              if (htmlWriter != null)
              {
                if (!elementContentStarted && inlineStyle.Length > 0)
                {
                  htmlWriter.WriteAttributeString("STYLE", inlineStyle.ToString());
                }
                htmlWriter.WriteComment(xamlReader.Value);
              }
              elementContentStarted = true;
              break;
            case XmlNodeType.CDATA:
            case XmlNodeType.Text:
            case XmlNodeType.SignificantWhitespace:
              if (htmlWriter != null)
              {
                if (!elementContentStarted && inlineStyle.Length > 0)
                {
                  htmlWriter.WriteAttributeString("STYLE", inlineStyle.ToString());
                }
                htmlWriter.WriteString(xamlReader.Value);
              }
              elementContentStarted = true;
              break;
          }
        }

        Debug.Assert(xamlReader.NodeType == XmlNodeType.EndElement);
      }
    }