Esempio n. 1
0
        public void ClassInheritance()
        {
            var c = new Class(AccessModifier.Public, "Person");
            c.BaseClass = new TypeName("PersonBase");

            Assert.AreEqual("public class Person : PersonBase" + SourceCodeGenerator.NewLine
                + "{" + SourceCodeGenerator.NewLine
                + "}" + SourceCodeGenerator.NewLine
                , SourceCodeGenerator.Write(SourceCodeLanguage.CSharp, c));
        }
        public Class CreateClass()
        {
            var t = this.Table;
            var c = new Class(AccessModifier.Public, t.Name);

            c.Modifier.Partial = true;

            c.Classes.Add(this.CreateRecordClass());

            return c;
        }
        public Class CreateClass()
        {
            Class c = new Class(AccessModifier.Public, "Record");

            c.Modifier.Partial = true;
            c.BaseClass = new TypeName("UserDefinedTableTypeRecord");

            ClassSourceCodeFileFactory.AddPropertyAndField(c, this.UserDefinedTableType.Columns);

            c.Constructors.Add(new Constructor(AccessModifier.Public, "Record"));
            c.Methods.Add(this.CreateGetValuesMethod());

            return c;
        }
        public Class CreateClass()
        {
            Class c = new Class(AccessModifier.Public, this.UserDefinedTableType.Name);

            c.Modifier.Partial = true;
            c.BaseClass = new TypeName(String.Format("UserDefinedTableType<{0}.Record>", this.UserDefinedTableType.Name));

            var factory = new UserDefinedTableTypeRecordClassFactory(this.UserDefinedTableType);
            c.Classes.Add(factory.CreateClass());

            c.Methods.Add(CreateCreateDataTableMethod());

            return c;
        }
Esempio n. 5
0
        public void ClassIndent()
        {
            var c = new Class(AccessModifier.Public, "StringUtility");
            c.Modifier.Static = true;
            c.Modifier.Abstract = true;

            CSharpSourceCodeGenerator sc = new CSharpSourceCodeGenerator();
            sc.CurrentIndentLevel = 2;
            sc.Write(c);

            Assert.AreEqual("        public static class StringUtility" + SourceCodeGenerator.NewLine
                + "        {" + SourceCodeGenerator.NewLine
                + "        }" + SourceCodeGenerator.NewLine
                , sc.ToString());
        }
        private void AddResultSetsXPropertyAndField(Class @class, StoredProcedureResultSetColumn resultSet)
        {
            var c = @class;
            var rs = resultSet;
            var f = new Field(String.Format("List<{0}>", rs.Name), String.Format("_{0}List", rs.Name));
            f.Initializer = String.Format("new {0}()", f.TypeName.Name);
            c.Fields.Add(f);

            var p = new Property(f.TypeName, rs.Name + "List");
            p.Get.Body.Add(SourceCodeLanguage.CSharp, String.Format("return {0};", f.Name));

            p.Set = null;

            c.Properties.Add(p);
        }
        public Class CreateClass()
        {
            Class c = new Class(AccessModifier.Public, "ResultSetsList");

            c.Modifier.Partial = true;

            c.Constructors.Add(new Constructor(AccessModifier.Public, "ResultSetsList"));

            foreach (var item in this.StoredProcedure.ResultSets)
            {
                AddResultSetsXPropertyAndField(c, item);
            }

            return c;
        }
Esempio n. 8
0
        public void ClassBasicFeature()
        {
            var c = new Class(AccessModifier.Public, "Person");
            var f = new Field("Int32", "_Age");
            c.Fields.Add(f);

            var p = new Property("Int32", "Age");
            p.Get.Body.Add(new CodeBlock(SourceCodeLanguage.CSharp, "return _Age;"));
            p.Set.Body.Add(new CodeBlock(SourceCodeLanguage.CSharp, "_Age = value;"));
            c.Properties.Add(p);

            var md = new Method(MethodAccessModifier.Public, "GetNumber");
            md.Body.Add(SourceCodeLanguage.CSharp, "return 123;");
            c.Methods.Add(md);

            var sw = new StringWriter();
            var cs = new CSharpSourceCodeGenerator(sw);
            cs.Write(c);

            Assert.AreEqual("public class Person" + SourceCodeGenerator.NewLine
                + "{" + SourceCodeGenerator.NewLine
                + "    private Int32 _Age;" + SourceCodeGenerator.NewLine
                + SourceCodeGenerator.NewLine
                + "    public Int32 Age" + SourceCodeGenerator.NewLine
                + "    {" + SourceCodeGenerator.NewLine
                + "        get" + SourceCodeGenerator.NewLine
                + "        {" + SourceCodeGenerator.NewLine
                + "            return _Age;" + SourceCodeGenerator.NewLine
                + "        }" + SourceCodeGenerator.NewLine
                + "        set" + SourceCodeGenerator.NewLine
                + "        {" + SourceCodeGenerator.NewLine
                + "            _Age = value;" + SourceCodeGenerator.NewLine
                + "        }" + SourceCodeGenerator.NewLine
                + "    }" + SourceCodeGenerator.NewLine
                + SourceCodeGenerator.NewLine
                + "    public void GetNumber()" + SourceCodeGenerator.NewLine
                + "    {" + SourceCodeGenerator.NewLine
                + "        return 123;"+ SourceCodeGenerator.NewLine
                + "    }" + SourceCodeGenerator.NewLine
                + "}" + SourceCodeGenerator.NewLine
                , sw.ToString());
        }
Esempio n. 9
0
        public Class CreateClass()
        {
            Class c = new Class(AccessModifier.Public, this.ResultSet.Name);

            c.Modifier.Partial = true;
            c.BaseClass = new TypeName(String.Format("StoredProcedureResultSet", this.StoredProcedureName));
            if (String.IsNullOrEmpty(this.ResultSet.TableName) == false)
            {
                c.ImplementInterfaces.Add(new TypeName(this.ResultSet.TableName + ".IRecord"));
            }

            ClassSourceCodeFileFactory.AddPropertyAndField(c, this.ResultSet.Columns);

            c.Constructors.Add(new Constructor(AccessModifier.Public, this.ResultSet.Name));
            c.Constructors.Add(CreateResultSetConstructor());
            c.Constructors.Add(CreateResultSetConstructorWithStoredProcedure());

            c.Methods.Add(CreateResultSetToStringMethod());

            return c;
        }
        public static void AddPropertyAndField(Class @class, IEnumerable<DataType> parameters)
        {
            var c = @class;
            Property p = null;
            Field f = null;
            String pName = "";

            foreach (var parameter in parameters)
            {
                pName = parameter.GetNameWithoutAtmark();
                f = new Field(parameter.GetClassName(), "_" + pName);
                if (f.TypeName.Name == "String")
                {
                    f.Initializer = "null";
                }
                else if (parameter.DbType.IsUserDefinedTableType() == true)
                {
                    f.Initializer = String.Format("new {0}()", parameter.GetClassName());
                }
                c.Fields.Add(f);

                p = new Property(parameter.GetClassName(), pName);
                p.Get.Body.Add(SourceCodeLanguage.CSharp, "return _{0};", pName);

                if (f.TypeName.Name == "String" &&
                    parameter.AllowNull == false)
                {
                    p.Set.Body.Add(SourceCodeLanguage.CSharp, "this.SetPropertyValue(ref _{0}, value ?? \"\", this.GetPropertyChangedEventHandler());", pName);
                }
                else
                {
                    p.Set.Body.Add(SourceCodeLanguage.CSharp, "this.SetPropertyValue(ref _{0}, value, this.GetPropertyChangedEventHandler());", pName);
                }

                c.Properties.Add(p);
            }
        }
        public Class CreateClass()
        {
            var t = this.Table;
            var c = new Class(AccessModifier.Public, t.Name);

            c.BaseClass = new TypeName(String.Format("Table<{0}.Record>", t.Name));
            c.Modifier.Partial = true;

            c.Fields.Add(CreateNameConstField());
            c.Properties.Add(CreateStoredProcedureNameProperty());

            c.Methods.Add(CreateGetDatabaseKeyMethod(this.DatabaseKey));
            c.Methods.Add(CreateCreateRecordMethod());
            c.Methods.Add(CreateSetRecordPropertyMethod());
            c.Methods.Add(CreateSetOutputParameterValueMethod());

            c.Methods.Add(CreateSelectByPrimaryKeyMethod());
            c.Methods.Add(CreateSelectByPrimaryKeyOrNullMethod());
            c.Methods.Add(CreateSelectByPrimaryKeyMethod1());
            c.Methods.Add(CreateSelectByPrimaryKeyOrNullMethod1());
            c.Methods.Add(CreateDeleteByValueMethod());
            c.Methods.Add(CreateDeleteByValueMethod1());

            c.Methods.Add(CreateCreateStoredProcedureWithResultSetMethod());
            c.Methods.Add(CreateCreateStoredProcedureMethod());
            c.Methods.Add(CreateSelectAllStoredProcedureMethod());
            c.Methods.Add(CreateSelectByPrimaryKeyStoredProcedureMethod());
            c.Methods.Add(CreateInsertStoredProcedureMethod());
            c.Methods.Add(CreateUpdateStoredProcedureMethod());
            c.Methods.Add(CreateDeleteStoredProcedureMethod());

            c.Methods.Add(CreateCreateDataTableMethod());
            c.Methods.Add(CreateSetDataRowMethod());

            return c;
        }
        public Class CreateRecordClass()
        {
            var t = this.Table;
            var c = new Class(AccessModifier.Public, "Record");

            c.Modifier.Partial = true;
            c.BaseClass = new TypeName("TableRecord<Record>");
            c.ImplementInterfaces.Add(new TypeName("IRecord"));

            c.Constructors.Add(CreateDefaultConstructor());
            c.Constructors.Add(CreateConstructor());

            c.Methods.Add(CreateGetTableNameMethod());
            c.Methods.Add(new Method(MethodAccessModifier.Partial, "ConstructorExecuted"));
            c.Methods.Add(CreateSetPropertyMethod());
            c.Methods.Add(CreateSetPropertyMethod1());
            c.Methods.Add(CreateCompareAllColumnMethod());
            c.Methods.Add(CreateComparePrimaryKeyColumnMethod());
            c.Methods.Add(CreateGetValueMethod());
            c.Methods.Add(CreateSetValueMethod());
            c.Methods.Add(CreateGetColumnCountMethod());

            if (t.Columns.Exists(el => el.Name == "SaveMode") == false)
            {
                c.Properties.Add(CreateSaveModeProperty());
            }
            ClassSourceCodeFileFactory.AddPropertyAndField(c, t.Columns);

            return c;
        }
Esempio n. 13
0
        public void ClassInheritanceAndImplement()
        {
            var c = new Class(AccessModifier.Public, "Person");
            c.BaseClass = new TypeName("PersonBase");
            c.ImplementInterfaces.Add(new TypeName("IDisposable"));
            c.ImplementInterfaces.Add(new TypeName("IEnumerable"));

            Assert.AreEqual("public class Person : PersonBase, IDisposable, IEnumerable" + SourceCodeGenerator.NewLine
                +"{" + SourceCodeGenerator.NewLine
                + "}" + SourceCodeGenerator.NewLine
                , SourceCodeGenerator.Write(SourceCodeLanguage.CSharp, c));
        }
Esempio n. 14
0
        public void ClassModifierStaticAbstractPriority()
        {
            var c = new Class(AccessModifier.Public, "StringUtility");
            c.Modifier.Static = true;
            c.Modifier.Abstract = true;

            Assert.AreEqual("public static class StringUtility" + SourceCodeGenerator.NewLine
                + "{" + SourceCodeGenerator.NewLine
                + "}" + SourceCodeGenerator.NewLine
                , SourceCodeGenerator.Write(SourceCodeLanguage.CSharp, c));
        }
Esempio n. 15
0
 public abstract void Write(Class @class);
 public override void Write(Class @class)
 {
     throw new NotImplementedException();
 }
Esempio n. 17
0
        public void ClassLineBreakFeature()
        {
            var c = new Class(AccessModifier.Public, "Person");

            var md = new Method(MethodAccessModifier.Public, "GetNumber");
            md.Body.Add(SourceCodeLanguage.CSharp, "return 123;");
            c.Methods.Add(md);

            Assert.AreEqual("public class Person" + SourceCodeGenerator.NewLine
                + "{" + SourceCodeGenerator.NewLine
                + "    public void GetNumber()" + SourceCodeGenerator.NewLine
                + "    {" + SourceCodeGenerator.NewLine
                + "        return 123;" + SourceCodeGenerator.NewLine
                + "    }" + SourceCodeGenerator.NewLine
                + "}" + SourceCodeGenerator.NewLine
                , SourceCodeGenerator.Write(SourceCodeLanguage.CSharp, c));
        }
Esempio n. 18
0
 public static String Write(SourceCodeLanguage language, Class @class)
 {
     var sc = Create(language);
     sc.Write(@class);
     return sc.TextWriter.ToString();
 }