public static CodeTypeDeclaration AddEnum(this CodeNamespace codeNamespace, string enumName) { var e = Define.Enum(enumName); codeNamespace.Types_Add(e); return(e); }
public static CodeTypeDeclaration AddEnum(this CodeTypeDeclaration @class, string enumName) { var e = Define.Enum(enumName); @class.AddEnum(e); return(e); }
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); }