Exemple #1
0
 private void NamespaceCreateButton_Click(object sender, EventArgs e)
 {
     _currentCompileUnitBuilder    = new CompileUnitBuilder(NamespaceBox.Text);
     NamespaceBox.Enabled          = false;
     NamespaceCreateButton.Enabled = false;
     ToggelClassesPanel();
     UpdateClasses();
 }
Exemple #2
0
        public void IfNewIntanceOfCompileUnitBuilderShouldHaveNamespaceWithGivenNamespaceName()
        {
            var builder = new CompileUnitBuilder(NamespaceName);

            var target = builder.GetCompileUnit();

            Assert.AreEqual(target.Namespaces.Count, 1);
            Assert.AreEqual(target.Namespaces[0].Name, NamespaceName);
        }
Exemple #3
0
        public void IfUsingIsAddedNamespaceShouldHaveGivenUsing()
        {
            const string usingName = "system";
            var          builder   = new CompileUnitBuilder(NamespaceName);

            var target = builder.AddUsing(usingName).GetCompileUnit();

            Assert.AreEqual(target.Namespaces[0].Imports.Count, 1);
        }
Exemple #4
0
        public void IsNewTypeIsAddedNamespaceHaveTypeWithGivenType()
        {
            const string typeName         = "testType";
            var          builder          = new CompileUnitBuilder(NamespaceName);
            var          classDeclaration = new CodeTypeDeclaration(typeName);
            var          target           = builder.AddClass(classDeclaration).GetCompileUnit();

            Assert.AreEqual(1, target.Namespaces[0].Types.Count);

            Assert.AreEqual(typeName, target.Namespaces[0].Types[0].Name);
        }
Exemple #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            var    language = GenerateCodeBox.Text;
            string sExt     = "";

            saveFileDialog1.FileName = "MyNewClass";
            switch (language)
            {
            case "CSharp":
                sExt = "CSharp(*.cs|*.cs";
                break;

            case "CPP":
                sExt = "CPP(*.cpp)|*.cpp";
                break;

            case "VB":
                sExt = "Visual Basic(*.vb)|*.vb";
                break;

            case "JScript":
                sExt = "JScript(*.js)|*.js";
                break;

            default:
                language = "CSharp";
                sExt     = "CSharp(*.cs|*.cs";
                break;
            }
            saveFileDialog1.Filter = sExt;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                var path = saveFileDialog1.FileName;
                _currentCompileUnitBuilder.PublishCode(path);
            }

            _currentCompileUnitBuilder = null;
            NamespaceBox.Text          = "";
            ClassesBox.Items.Clear();
            ToggelClassPanel();
        }
Exemple #6
0
        static void Main()
        {
            var cb = new ClassBuilder("EntryPoint", TypeAttributes.Public, false);
            var pi = new ParameterItem();

            pi.Name = "s";
            pi.Type = typeof(string);

            IStatementLine[] Statements = new IStatementLine[]
            {
                new ExpressionStatementLine(),
                new ReturnStatementLine()
            };

            var methodInvoke = new MethodInvokeExpressionLine();

            methodInvoke.MethodName = "WriteLine";
            var test = new TypeReferenceExpressionLine();

            test.Type = "System.Console";
            methodInvoke.TargetObject = test;
            var methodInvokeParam = new VariableReferenceExpressionLine();

            methodInvokeParam.VariableName = "s";
            methodInvoke.Parameters        = new IExpressionLine[] { methodInvokeParam };
            Statements[1].Expressions.Add(0, new VariableReferenceExpressionLine()
            {
                VariableName = "s"
            });
            Statements[0].Expressions.Add(0, methodInvoke);
            cb.AddMethod <string>("Print", new ParameterItem[] { pi }, MemberAttributes.Public | MemberAttributes.Static, Statements);

            var cub      = new CompileUnitBuilder("Bla");
            var typeDecl = cb.GetDeclaration();

            cub.AddClass(typeDecl);
            cub.PublishCode("c:\\Users\\Sytse\\Documents\\GitHubVisualStudio\\Minor_CodeGen\\CodeGen\\test.cs");

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new CodeGenStudio());
        }
Exemple #7
0
        public void IfUsingIsAddedWithAWhitespacedStringAsUsingShouldThowException()
        {
            var builder = new CompileUnitBuilder(NamespaceName);

            builder.AddUsing(" ");
        }
Exemple #8
0
        public void IfUsingIsAddedWithNullAsUsingShouldThowException()
        {
            var builder = new CompileUnitBuilder(NamespaceName);

            builder.AddUsing(null);
        }
Exemple #9
0
        public void IfClassDeclarationIsNullShouldThrowException()
        {
            var builder = new CompileUnitBuilder(NamespaceName);

            builder.AddClass(null);
        }
Exemple #10
0
 public void IfNewIntanceOfCompileUnitBuilderWithAWhitspaceStringAsNamespaceNameShouldThrowException()
 {
     var builder = new CompileUnitBuilder(" ");
 }
Exemple #11
0
 public void IfNewIntanceOfCompileUnitBuilderWithAnEmptyStringAsNamespaceNameShouldThrowException()
 {
     var builder = new CompileUnitBuilder(string.Empty);
 }
Exemple #12
0
 public void IfNewIntanceOfCompileUnitBuilderWithNullAsNamespaceNameShouldThrowException()
 {
     var builder = new CompileUnitBuilder(null);
 }