Exemple #1
0
        public void Make(string baseDir)
        {
            using System.IO.StreamWriter sw = beanKey.Space.OpenWriter(baseDir, beanKey.Name + ".cs");

            sw.WriteLine("// auto-generated");
            sw.WriteLine("");
            sw.WriteLine("using Zeze.Serialize;");
            sw.WriteLine("using System;");
            //sw.WriteLine("using Zeze.Transaction.Collections;");
            sw.WriteLine("");
            sw.WriteLine("namespace " + beanKey.Space.Path());
            sw.WriteLine("{");
            sw.WriteLine("    public sealed class " + beanKey.Name + " : Serializable, System.IComparable");
            sw.WriteLine("    {");
            // declare enums
            foreach (Types.Enum e in beanKey.Enums)
            {
                sw.WriteLine("        public const int " + e.Name + " = " + e.Value + ";" + e.Comment);
            }
            if (beanKey.Enums.Count > 0)
            {
                sw.WriteLine("");
            }

            // declare variables
            foreach (Types.Variable v in beanKey.Variables)
            {
                sw.WriteLine("        private " + TypeName.GetName(v.VariableType) + " " + v.NamePrivate + ";" + v.Comment);
            }
            sw.WriteLine("");

            sw.WriteLine("        // for decode only");
            sw.WriteLine("        public " + beanKey.Name + "()");
            sw.WriteLine("        {");
            sw.WriteLine("        }");
            sw.WriteLine("");

            // params construct
            {
                sw.WriteLine("        public " + beanKey.Name + "(" + ParamName.GetParamList(beanKey.Variables) + ")");
                sw.WriteLine("        {");
                foreach (Types.Variable v in beanKey.Variables)
                {
                    sw.WriteLine("            this." + v.NamePrivate + " = " + v.NamePrivate + "_;");
                }
                sw.WriteLine("        }");
                sw.WriteLine("");
            }
            PropertyBeanKey.Make(beanKey, sw, "        ");
            sw.WriteLine("");
            Tostring.Make(beanKey, sw, "        ");
            Encode.Make(beanKey, sw, "        ");
            Decode.Make(beanKey, sw, "        ");
            Equal.Make(beanKey, sw, "        ");
            HashCode.Make(beanKey, sw, "        ");
            Compare.Make(beanKey, sw, "        ");
            NegativeCheck.Make(beanKey, sw, "        ");
            sw.WriteLine("    }");
            sw.WriteLine("}");
        }
Exemple #2
0
 /// <summary>
 /// 实际上 BeanKey 很多类型都不支持,下面先尽量实现,以后可能用来实现 Bean 的 Equals.
 /// </summary>
 /// <param name="bean"></param>
 /// <param name="sw"></param>
 /// <param name="prefix"></param>
 public static void Make(Types.BeanKey bean, System.IO.StreamWriter sw, String prefix)
 {
     sw.WriteLine(prefix + "public override bool Equals(object _obj1_)");
     sw.WriteLine(prefix + "{");
     sw.WriteLine(prefix + "    if (_obj1_ == this) return true;");
     sw.WriteLine(prefix + "    if (_obj1_ is " + bean.Name + " _obj_)");
     sw.WriteLine(prefix + "    {");
     foreach (Types.Variable var in bean.Variables)
     {
         var v = new Equal(var, "_obj_", false);
         var.VariableType.Accept(v);
         sw.WriteLine(prefix + "        if (" + v.text + ") return false;");
     }
     sw.WriteLine(prefix + "        return true;");
     sw.WriteLine(prefix + "    }");
     sw.WriteLine(prefix + "    return false;");
     sw.WriteLine(prefix + "}");
     sw.WriteLine("");
 }