예제 #1
0
 public void FieldBasic1()
 {
     var f = new Field("String", "_name")
     {
         Initializer = "\"Default Name\""
     };
     Assert.AreEqual("private String _name = \"Default Name\";" + SourceCodeGenerator.NewLine
         , SourceCodeGenerator.Write(SourceCodeLanguage.CSharp, f));
 }
        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);
        }
예제 #3
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());
        }
        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 Field CreateNameConstField()
 {
     var f = new Field("String", "Name");
     f.Modifier.AccessModifier = AccessModifier.Public;
     f.Modifier.Const = true;
     f.Initializer = String.Format("\"{0}\"", this.Table.Name);
     return f;
 }
예제 #6
0
파일: Class.cs 프로젝트: fengweijp/higlabo
        public void AddPropertyAndField(String typeName, String name)
        {
            var f = new Field(typeName, "_" + name);
            this.Fields.Add(f);

            var p = new Property(typeName, name);
            p.Get.Body.Add(SourceCodeLanguage.CSharp, "return _" + name + ";");
            p.Get.IsAutomaticProperty = true;
            p.Set.Body.Add(SourceCodeLanguage.CSharp, "_" + name + " = value;");
            p.Set.IsAutomaticProperty = true;
            this.Properties.Add(p);
        }
 public override void Write(Field field)
 {
     throw new NotImplementedException();
 }
예제 #8
0
 public abstract void Write(Field field);
예제 #9
0
 public static String Write(SourceCodeLanguage language, Field field)
 {
     var sc = Create(language);
     sc.Write(field);
     return sc.TextWriter.ToString();
 }