public static void ConstructorTest() { FluentCodeCompileUnit compileUnit = new FluentCodeCompileUnit(); compileUnit.Namespace("TestNamespace") .Class("AClass").Inherits("BaseClass") .Constructor(MemberAttributes.Public) .BaseArgs() .EndConstructor .Constructor(MemberAttributes.Public).Parameter(typeof(int), "IntArg") .ThisArgs(Expr.Arg("IntArg"), Expr.Primitive("Hello")) .EndConstructor .Constructor(MemberAttributes.Public).Parameter(typeof(int), "IntArg").Parameter(typeof(string), "StringArg") .BaseArgs(Expr.Arg("StringArg")) .EndConstructor .EndClass .Class("BaseClass") .Constructor(MemberAttributes.Public) .EndConstructor .Constructor(MemberAttributes.Public).Parameter(typeof(string), "TextToPrint") .CallStatic(typeof(Console), "WriteLine", Expr.Arg("TextToPrint")) .EndConstructor .EndClass .EndFluent(); Assembly assembly = TestGenerated(compileUnit.EndFluent()); object instance = GetClassInstance("TestNamespace.AClass", assembly); instance.GetType().GetConstructor(new Type[] { typeof(int) }).Invoke(instance, new object[] { 32 }); }
public static void ConstructorTest() { FluentCodeCompileUnit compileUnit = new FluentCodeCompileUnit(); compileUnit.Namespace("TestNamespace") .Class("AClass").Inherits("BaseClass") .Constructor(MemberAttributes.Public) .BaseArgs() .EndConstructor .Constructor(MemberAttributes.Public).Parameter(typeof(int), "IntArg") .ThisArgs(Expr.Arg("IntArg"), Expr.Primitive("Hello")) .EndConstructor .Constructor(MemberAttributes.Public).Parameter(typeof(int), "IntArg").Parameter(typeof(string), "StringArg") .BaseArgs(Expr.Arg("StringArg")) .EndConstructor .EndClass .Class("BaseClass") .Constructor(MemberAttributes.Public) .EndConstructor .Constructor(MemberAttributes.Public).Parameter(typeof(string), "TextToPrint") .CallStatic(typeof(Console), "WriteLine", Expr.Arg("TextToPrint")) .EndConstructor .EndClass .EndFluent(); Assembly assembly = TestGenerated(compileUnit.EndFluent()); object instance = GetClassInstance("TestNamespace.AClass", assembly); instance.GetType().GetConstructor(new Type[] { typeof(int)}).Invoke(instance, new object[] { 32 }); }
public static void EnumTest() { FluentCodeCompileUnit compileUnit = new FluentCodeCompileUnit(); compileUnit.Namespace("TestNamespace") .Enum("TestEnum").CustomAttribute(typeof(FlagsAttribute)) .Value("Value1", Expr.Primitive(1)).EndValue .Value("Value2", Expr.Primitive(2)).EndValue .Value("Value3", Expr.Primitive(4)).EndValue .EndEnum .EndFluent(); TestGenerated(compileUnit.EndFluent()); }