Example #1
0
        protected virtual void OnSetBusinessObject(BusinessObject value)
        {
            this.Ãû³Æ = value.Ãû³Æ;
            var temp = BusinessObjectCodeGenerateExtendesion.CommonUsing();

            temp     += Template;
            this.Code = new CsharpCode(temp, this);
        }
Example #2
0
        public static BusinessObjectPartialLogic AddPartialLogic(this BusinessObject self, string code, string usingBlock = null)
        {
            var logic = new BusinessObjectPartialLogic(self.Session);

            logic.BusinessObject = self;
            if (usingBlock == null)
            {
                code = BusinessObjectCodeGenerateExtendesion.CommonUsing() + code;
            }
            logic.Code = new CsharpCode(code, logic);
            return(logic);
        }
        public string GetCode()
        {
            var rst = new StringBuilder();

            #region using
            rst.Append(BusinessObjectCodeGenerateExtendesion.CommonUsing());

            #endregion


            #region namespace
            rst.AppendLine($@"namespace {Category.FullName}
{{");
            #endregion

            #region 说明
            rst.AppendLine("\t//BO:" + Oid);

            #endregion

            #region attributes
            if (!IsPersistent)
            {
                rst.AppendLine("\t[NonPersistent]");
            }

            if (IsCloneable.HasValue && IsCloneable.Value)
            {
                rst.AppendLine("\t[ModelDefault(\"Cloneable\",\"True\")]");
            }

            if (IsCreatableItem.HasValue && IsCreatableItem.Value)
            {
                rst.AppendLine("\t[ModelDefault(\"Createable\",\"True\")]");
            }

            if (IsVisibileInReports.HasValue && IsVisibileInReports.Value)
            {
                rst.AppendLine("\t[VisibleInReport]");
            }
            #endregion

            rst.Append($"\tpublic ");
            if (this.Modifier != Modifier.None)
            {
                rst.Append($"{ Modifier.ToString().ToLower()} ");
            }
            rst.Append($" partial class { 名称 } ");

            //" { (Modifier == Modifier.Sealed ? "" : "sealed") + (IsAbstract ? "abstract" : "") }");

            #region 本类泛型定义
            if (GenericParameterDefines.Count > 0)
            {
                //如果设置了泛型参数的值,则付入,否则认为本类也是泛型类
                rst.AppendFormat("<{0}>",
                                 string.Join(",",
                                             GenericParameterDefines
                                             .OrderBy(x => x.ParameterIndex)
                                             .Select(x => x.Name)
                                             .ToArray()));
            }
            #endregion

            rst.Append(":");

            #region 基类 泛型处理
            if (Base.IsGenericTypeDefine)
            {
                var n = Base.FullName;
                if (Base.IsRuntimeDefine)
                {
                    rst.Append("global::" + n);
                }
                else
                {
                    rst.Append("global::" + n.Substring(0, n.Length - 2));
                }
#warning where 等待制作

                //如果设置了泛型参数的值,则付入,否则认为本类也是泛型类
                //rst.AppendFormat("<{0}>",
                //    string.Join(",",
                //        GenericParameterInstances.Select(
                //            x => x.ParameterValue == null ? x.Name : "global::" + x.ParameterValue.FullName).ToArray()));
                //where xxxx : xxxx
                //var constraints = string.Join("\n", GenericParameterInstances.Where(x => !string.IsNullOrEmpty(x.Constraint)).Select(x => " where " + x.Name + " : " + x.Constraint));
                //rst.AppendLine(constraints);
            }
            else
            {
                rst.Append("global::" + Base.FullName);
            }
            #endregion

            rst.AppendLine();

            //begin class
            rst.AppendLine("\t{");

            #region 构造函数
            rst.AppendLine($"\t\tpublic {名称}(Session s):base(s){{  }}");

            #endregion

            #region 属性模板
            var propertyTemplate =
                "\t\tpublic {0} {1}\n" +
                "\t\t{\n" +
                "\t\t\tget { return _{1}; }\n" +
                "\t\t\tset { SetPropertyValue(\"{1}\",ref _{1},value); }\n" +
                "\t\t}\n";
            #endregion

            #region 属性生成
            foreach (var item in Properties)
            {
                var pt = "global::" + item.PropertyType.FullName;
                rst.AppendLine($"\t\t{ pt } _{ item.名称 };");

                if (item.Size != 100 && item.Size != 0)
                {
                    rst.AppendLine($"\t\t[Size({item.Size})]");
                }
                ProcessPropertyBase(rst, item);
                if (item.RelationProperty != null)
                {
                    var assName = string.Format("{0}_{1}", item.RelationProperty.称, item.称);
                    rst.AppendFormat("\t\t[{0}(\"{1}\")]", typeof(AssociationAttribute).FullName, assName);
                }


                rst.Append(propertyTemplate.Replace("{0}", pt).Replace("{1}", item.称));
            }
            #endregion

            #region 关联集合
            var att = "\t\t[" + typeof(DevExpress.Xpo.AggregatedAttribute).FullName + "]";
            foreach (var item in CollectionProperties)
            {
                if (item.Aggregated)
                {
                    rst.AppendLine(att);
                }
                ProcessPropertyBase(rst, item);

                var assName = string.Format("{0}_{1}", item.称, item.RelationProperty.称);
                rst.AppendFormat("\t\t[{0}(\"{1}\")]\n", typeof(AssociationAttribute).FullName, assName);
                var pt = "global::" + item.PropertyType.FullName;
                rst.AppendLine($"\t\tpublic XPCollection<{pt}> {item.名称}{{ get{{ return GetCollection<{pt}>(\"{item.名称}\"); }} }}");
            }
            #endregion

            #region 业务逻辑处理
            foreach (var method in Methods)
            {
                rst.AppendLine(method.MethodDefineCode);
            }
            #endregion

            #region 结束
            //end class
            rst.AppendLine("\t}");
            rst.AppendLine("}");
            #endregion
            return(rst.ToString());
        }