예제 #1
0
        public void BufferStatementFragment(string fragment, Span sourceSpan)
        {
            if (sourceSpan != null && _currentBuffer.LinePragmaSpan == null)
            {
                _currentBuffer.LinePragmaSpan = sourceSpan;

                // Pad the output as necessary
                int start = _currentBuffer.Builder.Length;
                if (_currentBuffer.GeneratedCodeStart != null)
                {
                    start = _currentBuffer.GeneratedCodeStart.Value;
                }

                int paddingLength; // unused, in this case there is enough context in the original code to calculate the right padding length
                // (padded.Length - _currentBuffer.Builder.Length)

                string padded = CodeGeneratorPaddingHelper.Pad(
                    Host,
                    _currentBuffer.Builder.ToString(),
                    sourceSpan,
                    start,
                    out paddingLength
                    );
                _currentBuffer.GeneratedCodeStart =
                    start + (padded.Length - _currentBuffer.Builder.Length);
                _currentBuffer.Builder.Clear();
                _currentBuffer.Builder.Append(padded);
            }
            _currentBuffer.Builder.Append(fragment);
        }
예제 #2
0
        public override void GenerateCode(Span target, CodeGeneratorContext context)
        {
            string generatedCode = context.BuildCodeString(
                cw =>
            {
                cw.WriteSnippet(target.Content);
            }
                );

            int    paddingCharCount;
            string paddedCode = CodeGeneratorPaddingHelper.Pad(
                context.Host,
                generatedCode,
                target,
                out paddingCharCount
                );

            Contract.Assert(paddingCharCount > 0);

            context.GeneratedClass.Members.Add(
                new CodeSnippetTypeMember(paddedCode)
            {
                LinePragma = context.GenerateLinePragma(target, paddingCharCount)
            }
                );
        }
예제 #3
0
        public override void GenerateCode(Span target, CodeGeneratorContext context)
        {
            context.GeneratedClass.BaseTypes.Clear();
            context.GeneratedClass.BaseTypes.Add(
                new CodeTypeReference(ResolveType(context, BaseType.Trim()))
                );

            if (context.Host.DesignTimeMode)
            {
                int    generatedCodeStart = 0;
                string code = context.BuildCodeString(
                    cw =>
                {
                    generatedCodeStart = cw.WriteVariableDeclaration(
                        target.Content,
                        "__inheritsHelper",
                        null
                        );
                    cw.WriteEndStatement();
                }
                    );

                int paddingCharCount;

                CodeSnippetStatement stmt = new CodeSnippetStatement(
                    CodeGeneratorPaddingHelper.Pad(
                        context.Host,
                        code,
                        target,
                        generatedCodeStart,
                        out paddingCharCount
                        )
                    )
                {
                    LinePragma = context.GenerateLinePragma(
                        target,
                        generatedCodeStart + paddingCharCount
                        )
                };
                context.AddDesignTimeHelperStatement(stmt);
            }
        }