Exemplo n.º 1
0
 public Visitor(CodeTarget target, DefaultCodeRenderingContext context)
 {
     _target  = target;
     _context = context;
 }
Exemplo n.º 2
0
 public DefaultDocumentWriter(CodeTarget codeTarget, RazorCodeGenerationOptions options)
 {
     _codeTarget = codeTarget;
     _options    = options;
 }
Exemplo n.º 3
0
 public override void WriteNode(CodeTarget target, CodeRenderingContext context)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 4
0
        public void WriteDocument_WritesMethod()
        {
            // Arrange
            var document = new DocumentIntermediateNode();
            var builder  = IntermediateNodeBuilder.Create(document);

            builder.Add(new MethodDeclarationIntermediateNode()
            {
                Modifiers =
                {
                    "internal",
                    "virtual",
                    "async",
                },
                MethodName = "TestMethod",
                Parameters =
                {
                    new MethodParameter()
                    {
                        Modifiers =
                        {
                            "readonly",
                            "ref",
                        },
                        ParameterName = "a",
                        TypeName      = "int",
                    },
                    new MethodParameter()
                    {
                        ParameterName = "b",
                        TypeName      = "string",
                    }
                },
                ReturnType = "string",
            });

            var codeDocument = TestRazorCodeDocument.CreateEmpty();
            var options      = RazorCodeGenerationOptions.CreateDefault();

            var target = CodeTarget.CreateDefault(codeDocument, options);
            var writer = new DefaultDocumentWriter(target, options);

            // Act
            var result = writer.WriteDocument(codeDocument, document);

            // Assert
            var csharp = result.GeneratedCode;

            Assert.Equal(
                @"#pragma checksum ""test.cshtml"" ""{ff1816ec-aa5e-4d10-87f7-6f4963833460}"" ""da39a3ee5e6b4b0d3255bfef95601890afd80709""
// <auto-generated/>
#pragma warning disable 1591
#pragma warning disable 1998
internal virtual async string TestMethod(readonly ref int a, string b)
{
}
#pragma warning restore 1998
#pragma warning restore 1591
",
                csharp,
                ignoreLineEndingDifferences: true);
        }
 public override void WriteNode(CodeTarget target, CodeRenderingContext context)
 {
     context.CodeWriter.WriteLine("MyExtensionNode");
 }