Beispiel #1
0
 public CodeSnippetItem(CodeSnippetItem source)
     : base(source)
 {
     _exampleId   = source._exampleId;
     _snippetId   = source._snippetId;
     _snippetLang = source._snippetLang;
     _snippetText = source._snippetText;
 }
Beispiel #2
0
        public CodeSnippetItem(string exampleId, string snippetId,
                               CodeSnippetLanguage snippetLang, string snippetText)
            : this(exampleId, snippetId)
        {
            BuildExceptions.NotNull(snippetLang, "snippetLang");
            BuildExceptions.NotNull(snippetText, "snippetText");

            _snippetLang = snippetLang;
            _snippetText = snippetText;
        }
Beispiel #3
0
        public CodeSnippetItem(string exampleId, string snippetId)
        {
            BuildExceptions.NotNullNotEmpty(exampleId, "exampleId");
            BuildExceptions.NotNullNotEmpty(snippetId, "snippetId");

            _snippetLang = CodeSnippetLanguage.None;
            _snippetText = String.Empty;

            _exampleId = exampleId;
            _snippetId = snippetId;
        }
Beispiel #4
0
        /// <summary>
        /// This reads and sets its state or attributes stored in a <c>XML</c> format
        /// with the given reader.
        /// </summary>
        /// <param name="reader">
        /// The reader with which the <c>XML</c> attributes of this object are accessed.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the <paramref name="reader"/> is <see langword="null"/>.
        /// </exception>
        public override void ReadXml(XmlReader reader)
        {
            BuildExceptions.NotNull(reader, "reader");

            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            if (reader.NodeType != XmlNodeType.Element)
            {
                return;
            }

            if (!String.Equals(reader.Name, TagName,
                               StringComparison.OrdinalIgnoreCase))
            {
                Debug.Assert(false, "The tag name does not match.");
                return;
            }

            string nodeText = reader.GetAttribute("id");

            if (String.IsNullOrEmpty(nodeText))
            {
                Debug.Assert(false, "The tag has no id attribute.");
                return;
            }
            int hashIndex = nodeText.IndexOf('#');

            if (hashIndex < 0)
            {
                Debug.Assert(false, "The tag has valid id attribute.");
                return;
            }
            _exampleId = nodeText.Substring(0, hashIndex);
            _snippetId = nodeText.Substring(hashIndex + 1);

            if (reader.IsEmptyElement)
            {
                return;
            }

            Type langType = typeof(CodeSnippetLanguage);

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (String.Equals(reader.Name, "sampleCode",
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        nodeText = reader.GetAttribute("language");
                        if (!String.IsNullOrEmpty(nodeText))
                        {
                            _snippetLang = (CodeSnippetLanguage)Enum.Parse(
                                langType, nodeText, true);
                            _snippetText = reader.ReadString();
                        }
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (String.Equals(reader.Name, TagName,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }
            }
        }