Пример #1
0
        private static void LoadCodeElement(CodeElement element, Snippet snippet)
        {
            if (element.Delimiter?.Length == 1)
                snippet.Delimiter = element.Delimiter[0];

            if (element.Kind != null)
            {
                ContextKind kind;
                if (ContextKinds.TryGetValue(element.Kind, out kind))
                    snippet.ContextKind = kind;
            }

            if (element.Language != null)
                snippet.Language = LanguageMapper.Instance.MapTextToEnum(element.Language);

            if (!string.IsNullOrEmpty(element.Code))
                snippet.CodeText = element.Code;
        }
Пример #2
0
        private static CodeElement CreateCodeElement(SerializationContext context)
        {
            var element = new CodeElement();
            Snippet snippet = context.Snippet;

            if (!string.IsNullOrEmpty(snippet.CodeText))
            {
                if (TextUtility.ContainsCDataEnd(snippet.CodeText))
                    throw new InvalidOperationException("Snippet code cannot contain CDATA ending sequence ']]>'.");

                element.Code = snippet.CodeText;
            }

            if (!snippet.HasDefaultDelimiter || !context.Settings.OmitDefaultDelimiter)
                element.Delimiter = new string(snippet.Delimiter, 1);

            if (snippet.ContextKind != ContextKind.None)
                element.Kind = snippet.ContextKind.ToString();

            element.Language = LanguageMapper.Instance.MapEnumToText(snippet.Language);

            return element;
        }