Пример #1
0
        private static string TransformContent(ICsharpMacro macro, MacroDescriptor macroDescriptor, ICsharpMacroContext macroContext)
        {
            var sb = new StringBuilder();

            foreach (var attributes in macro.ExecuteMacro(macroDescriptor.Param, macroContext))
            {
                var transformedItem = TransformedTemplate(macroDescriptor.Template, attributes);
                sb.Append(transformedItem);
            }
            return(sb.ToString().Replace("//", ""));
        }
Пример #2
0
        private bool TryGetMacroDescriptor(SyntaxTriviaList triviaList, out MacroDescriptor descriptor, out SyntaxTriviaList leadingTrivia)
        {
            var(beforeMacro, macroTrivia) = SplitByMacro(triviaList);
            leadingTrivia = beforeMacro;
            if (macroTrivia.Count == 0)
            {
                descriptor = null;
                return(false);
            }

            var header        = macroTrivia.First().ToString();
            var templateLines = macroTrivia.Skip(1).SkipWhile(x => x.ToString().Equals("\r\n")).Select(x => x.ToString());
            var matches       = macroHeaderSyntax.Match(header);

            descriptor = new MacroDescriptor()
            {
                MacroName = matches.Groups["macro"].Value.Trim(),
                Param     = matches.Groups["param"].Value.Trim(),
                Template  = string.Join("", templateLines).TrimEnd(' ')
            };
            return(true);
        }