Exemple #1
0
        public static CodeTypeDeclaration AddEnum(this CodeNamespace codeNamespace, string enumName)
        {
            var e = Define.Enum(enumName);

            codeNamespace.Types_Add(e);

            return(e);
        }
Exemple #2
0
        public static CodeTypeDeclaration AddEnum(this CodeTypeDeclaration @class, string enumName)
        {
            var e = Define.Enum(enumName);

            @class.AddEnum(e);

            return(e);
        }
Exemple #3
0
        public void Builder_Enum()
        {
            var c = new CodeDomGenerator();

            c.AddNamespace("Samples").AddEnum(Define.Enum("ee")
                                              .AddFields(
                                                  Define.StructField("Xx"),
                                                  Define.StructField("Yy"),
                                                  Define.StructField("Zz", () => 100)
                                                  )
                                              ).AddEnum("rr").AddAttribute(typeof(FlagsAttribute))
            .AddFields(
                Define.StructField("Xx"),
                Define.StructField("Yy"),
                Define.StructField("Zz")
                ).AddClass("cls").AddMethod(MemberAttributes.Static | MemberAttributes.Public, () => "foo",
                                            Emit.declare("rr", "e"),
                                            Emit.assignVar("e", () => CodeDom.Field(new CodeTypeReference("rr"), "Xx"))
                                            );

            Console.WriteLine(c.GenerateCode(CodeDomGenerator.Language.CSharp));

            Console.WriteLine(c.GenerateCode(CodeDomGenerator.Language.VB));

            var ass = c.Compile();

            Assert.IsNotNull(ass);

            Type eeClass = ass.GetType("Samples.ee");

            Assert.IsNotNull(eeClass);

            Type rrClass = ass.GetType("Samples.rr");

            Assert.IsNotNull(rrClass);
        }