Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var myClass = new ClassDeclaration("CMyClass");

            // Add a private field
            myClass.Fields.Add(new FieldDeclaration("m_someInt", Primitive.Int, AccessLevel.Private));

            // Define our custom type
            var myType = new TypeReference("CSomeOtherClass").MakePointer();

            // And store a private pointer with a basic comment
            myClass.Fields.Add(new FieldDeclaration("m_pSomePointer", myType, AccessLevel.Private,
                new Comment("Test comment")));

            // Add getters
            myClass.Functions.Add(new FunctionDeclaration("GetInteger", Primitive.Int));
            myClass.Functions.Add(new FunctionDeclaration("GetOtherClass", myType));

            // And setters
            var intArg = new VariableDeclaration("value", Primitive.Int);
            var classPtrArg = new VariableDeclaration("value", myType);

            myClass.Functions.Add(new FunctionDeclaration("SetInteger", Primitive.Void,
                AccessLevel.Public, false, intArg));
            myClass.Functions.Add(new FunctionDeclaration("SetOtherClass", Primitive.Void,
                AccessLevel.Public, false, classPtrArg));

            // Add a virtual function with a multiline comment
            var comment = new MultilineComment("This is a function",
                "that should be overridden",
                "just because it can be");

            var function = new FunctionDeclaration("OverrideMe", Primitive.Char.MakePointer().MakeConst(),
                AccessLevel.Public, true);

            function.Comment = comment;
            myClass.Functions.Add(function);

            var classSource = myClass.CreateSource();

            Console.Write(myClass.CreateSource());
            Console.ReadLine();
        }