Exemplo n.º 1
0
        /// <summary>
        /// Maps a specified <see cref="CodeSnippetElement"/> to the newly created <see cref="Snippet"/>.
        /// </summary>
        /// <param name="element">A <see cref="CodeSnippetElement"/> that contains deserialized snippet data.</param>
        /// <returns>Newly created <see cref="Snippet"/>.</returns>
        public static Snippet MapFromElement(CodeSnippetElement element)
        {
            if (element == null)
                throw new ArgumentNullException(nameof(element));

            var snippet = new Snippet();

            if (element.Format != null)
            {
                Version version = null;

                if (Version.TryParse(element.Format, out version)
                    && ValidationHelper.IsValidVersion(version))
                {
                    snippet.FormatVersion = version;
                }
            }

            if (element.Header != null)
                LoadHeaderElement(element.Header, snippet);

            if (element.Snippet != null)
                LoadSnippetElement(element.Snippet, snippet);

            return snippet;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SerializationContext"/> class with a specified code snippet and and settings.
 /// </summary>
 /// <param name="snippet">A <see cref="Snippet"/> instance to serialize.</param>
 /// <param name="settings">A <see cref="SaveSettings"/> that enables to modify code snippet serialization process.</param>
 public SerializationContext(Snippet snippet, SaveSettings settings)
 {
     Snippet = snippet;
     Settings = settings;
     Element = new CodeSnippetElement();
 }