예제 #1
0
        public void 委托_T2_返回值()
        {
            DelegateBuilder builder = CodeSyntax.CreateDelegate("T2")
                                      .WithAccess(MemberAccess.Public)
                                      .WithReturnType("string");

            var result = builder.ToFormatCode();

#if Log
            _tempOutput.WriteLine(result);
#endif
            Assert.Equal("public delegate string T2();", result);
        }
예제 #2
0
        public void 委托_T1_类中()
        {
            DelegateBuilder builder = CodeSyntax.CreateDelegate("T1")
                                      .WithAccess(NamespaceAccess.Public)
                                      .WithReturnType("void");

            var result = builder.ToFormatCode();

#if Log
            _tempOutput.WriteLine(result);
#endif
            Assert.Equal("public delegate void T1();", result);
        }
예제 #3
0
        public void 委托_T4_特性()
        {
            DelegateBuilder builder = CodeSyntax.CreateDelegate("T4")
                                      .WithAttributes(new string[] { @"[Test(""1"", ""2"", A = ""3"", B = ""4"")]" })
                                      .WithAccess(MemberAccess.Public);

            var result = builder.ToFormatCode();

#if Log
            _tempOutput.WriteLine(result);
#endif
            Assert.Equal(@"[Test(""1"", ""2"", A = ""3"", B = ""4"")]
public delegate void T4();", result);
        }
        public void 委托_T3_参数和返回值()
        {
            DelegateBuilder builder = CodeSyntax.CreateDelegate("T3")
                                      .WithAccess(MemberAccess.Public)
                                      .WithReturnType("string")
                                      .WithParams("string a");

            var result = builder.ToFormatCode();

#if Log
            _tempOutput.WriteLine(result.WithUnixEOL());
#endif
            Assert.Equal("public delegate string T3(string a);", result.WithUnixEOL());
        }
예제 #5
0
        public void 委托_T5_泛型委托()
        {
            DelegateBuilder builder = CodeSyntax.CreateDelegate("Test")
                                      .WithAccess(MemberAccess.Public)
                                      .WithReturnType("T2")
                                      .WithGeneric(builder =>
            {
                builder
                .WithCreate("T1").WithEnd()
                .WithCreate("T2").WithStruct().WithEnd()
                .WithCreate("T3").WithClass().WithEnd()
                .WithCreate("T4").WithNotnull().WithEnd()
                .WithCreate("T5").WithInterface("IEnumerable<int>", "IQueryable<int>").WithEnd();
            });

            var result = builder.ToFormatCode();

#if Log
            _tempOutput.WriteLine(result);
#endif
            Assert.Equal(@"public delegate T2 Test<T1, T2, T3, T4, T5>()
    where T2 : struct where T3 : class where T4 : notnull where T5 : IEnumerable<int>, IQueryable<int>;", result);
        }
        public void 约束()
        {
            DelegateBuilder builder = CodeSyntax.CreateDelegate("Test")
                                      .WithGeneric(b =>
            {
                b.WithCreate("T1").WithStruct()
                .WithCreate("T2").WithClass()
                .WithCreate("T3").WithNotnull()
                .WithCreate("T4").WithUnmanaged()
                .WithCreate("T5").WithNotnull()
                .WithCreate("T6").WithBase("Enum")
                .WithCreate("T7").WithBase("IEnumerable<int>")
                .WithCreate("T8").WithTo("T2")
                .WithCreate("T9").WithClass().WithNew();
            });
            var result = builder.ToFormatCode();

#if Log
            _tempOutput.WriteLine(result.WithUnixEOL());
#endif

            Assert.Equal(@"delegate void Test<T1, T2, T3, T4, T5, T6, T7, T8, T9>()
    where T1 : struct where T2 : class where T3 : notnull where T4 : unmanaged where T5 : notnull where T6 : Enum where T7 : IEnumerable<int> where T8 : T2 where T9 : class, new();", result.WithUnixEOL());
        }