当前位置: 首页>>代码示例>>C#>>正文


C# Property.AddAttribute方法代码示例

本文整理汇总了C#中System.Property.AddAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Property.AddAttribute方法的具体用法?C# Property.AddAttribute怎么用?C# Property.AddAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Property的用法示例。


在下文中一共展示了Property.AddAttribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateField

        public void GenerateField()
        {
            string fieldName = column.ToFieldName();
            string ty = ColumnSchema.GetFieldType(column.DataType, column.Nullable);

            Property prop = new Property(new CodeBuilder.TypeInfo { userType = ty }, fieldName);
            if (dpoClass.option.HasColumnAttribute || column.ColumnName != fieldName)
            {
                var attr = prop.AddAttribute<ColumnAttribute>();
                Attribute(attr, column);
                attr.comment = new Comment(string.Format("{0}({1}) {2}", column.DataType, column.AdjuestedLength(), column.Nullable ? "null" : "not null"));
            }

            if (dpoClass.Nonvalized.IndexOf(fieldName) != -1)
                prop.AddAttribute<NonValizedAttribute>();

            //When programmer make field Nullable, it must be Nullable
            //if(dgc.NullableFields.IndexOf(fieldName) != -1)
            //    nullable = true;

            dpoClass.clss.Add(prop);

            dpoClass.dict_column_field.Add(column.ColumnName, new PropertyDefinition(ty, fieldName));

            if (column.ForeignKey != null && dpoClass.Dict != null)
            {
                TableName pkTableName = new TableName(
                    column.ForeignKey.TableName.DatabaseName,
                    column.ForeignKey.PK_Schema,
                    column.ForeignKey.PK_Table);  //column.ForeignKey.TableName;

                if (dpoClass.Dict.ContainsKey(pkTableName))
                {
                    Type type = dpoClass.Dict[pkTableName];
                    ForeignKey.GetAttribute(column.ForeignKey, type);
                }
                else
                {
                    //###
                    //ForeignKey check for external Dpo classes, they don't be load into dict
                    //var log = new LogDpoClass(pkTableName);
                    //if (log.Exists)
                    //{
                    //    string classFullName = string.Format("{0}.{1}", log.name_space, log.class_name);
                    //    line = string.Format("{0}{1}\r\n", tab, ForeignKey.GetAttribute(column.ForeignKey, classFullName)) + line;
                    //}
                    //else
                        throw new MessageException("cannot generate Dpo class of FK {0} before generate Dpo class of PK {1}",
                            dpoClass.MetaTable.TableName,
                            pkTableName);
                }
            }

            return;
        }
开发者ID:fjiang2,项目名称:sqlcon,代码行数:55,代码来源:DpoField.cs

示例2: AddLife

 public Property AddLife(LifeType type, Direction direction, string value = null,
     string initial = null,
     string limit = null, string warning = null)
 {
     Property life = new Property("ItemLife");
     life.Value = value;
     life.AddAttribute(new Property.Attribute("type", type.ToString()));
     life.AddAttribute(new Property.Attribute("countDirection", direction.ToString()));
     if (initial != null)
         life.AddAttribute(new Property.Attribute("initial", initial));
     if (limit != null)
         life.AddAttribute(new Property.Attribute("limit", limit));
     if (warning != null)
         life.AddAttribute(new Property.Attribute("warning", warning));
     mProperties.Add(life);
     return life;
 }
开发者ID:rcaronster,项目名称:mc2-adapter-lab,代码行数:17,代码来源:MTCCuttingTool.cs

示例3: AddEntitySet

        /// <summary>
        /// add children tables
        /// </summary>
        /// <param name="clss"></param>
        /// <param name="constructor"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        private Property AddEntitySet(Class clss, Constructor constructor, IForeignKey key)
        {
            TableName fk_tname = new TableName(tname.DatabaseName, key.FK_Schema, key.FK_Table);
            string fk_cname = fk_tname.ToClassName(null);
            string pname;

            Property prop;
            TypeInfo ty;
            Field field;

            var fk_schema = GetSchema(fk_tname);
            var _keys = fk_schema.PrimaryKeys.Keys;

            if (_keys.Length == 1 && _keys.Contains(key.FK_Column))
            {
                // 1:1 mapping
                pname = clss.MakeUniqueName(Pluralization.Singularize(fk_cname));
                ty = new TypeInfo { userType = $"EntityRef<{fk_cname}>" };
                field = new Field(ty, $"_{pname}") { modifier = Modifier.Private };

                prop = new Property(new TypeInfo { userType = fk_cname }, pname) { modifier = Modifier.Public };
                prop.gets.Append($"return this._{pname}.Entity;");
                prop.sets.Append($"this._{pname}.Entity = value;");

                prop.AddAttribute(new AttributeInfo("Association",
                 new
                 {
                     Name = $"{this.cname}_{fk_cname}",
                     Storage = $"_{pname}",
                     ThisKey = key.PK_Column,
                     OtherKey = key.FK_Column,
                     IsUnique = true,
                     IsForeignKey = false
                 }));
            }
            else
            {
                //1:n mapping
                pname = clss.MakeUniqueName(Pluralization.Pluralize(fk_cname));
                constructor.statements.AppendLine($"this._{pname} = new EntitySet<{fk_cname}>();");

                ty = new TypeInfo { userType = $"EntitySet<{fk_cname}>" };
                field = new Field(ty, $"_{pname}") { modifier = Modifier.Private };

                prop = new Property(ty, pname) { modifier = Modifier.Public };
                prop.gets.Append($"return this._{pname};");
                prop.sets.Append($"this._{pname}.Assign(value);");

                prop.AddAttribute(new AttributeInfo("Association",
                 new
                 {
                     Name = $"{this.cname}_{fk_cname}",
                     Storage = $"_{pname}",
                     ThisKey = key.PK_Column,
                     OtherKey = key.FK_Column,
                     IsForeignKey = false
                 }));
            }

            clss.Add(field);

            return prop;
        }
开发者ID:fjiang2,项目名称:sqlcon,代码行数:70,代码来源:Linq2SQLClassBuilder.cs

示例4: CreateClass

        protected override void CreateClass()
        {
            var clss = new Class(cname)
            {
                modifier = Modifier.Public | Modifier.Partial
            };
            clss.AddAttribute(new AttributeInfo("Table", new { Name = tname.ShortName }));

            builder.AddClass(clss);

            TableSchema schema = GetSchema(tname);

            Property prop;
            foreach (IColumn column in schema.Columns)
            {
                TypeInfo ty = new TypeInfo { userType = ColumnSchema.GetFieldType(column.DataType, column.Nullable) };

                prop = new Property(ty, column.ToFieldName()) { modifier = Modifier.Public };

                List<object> args = new List<object>();
                args.Add(new { Name = column.ColumnName });

                //args.Add(new { DbType = ColumnSchema.GetSQLType(column) + (column.Nullable ? " NULL" : " NOT NULL") });

                if (column.IsPrimary)
                    args.Add(new { IsPrimaryKey = true });

                if (column.IsIdentity)
                    args.Add(new { IsDbGenerated = true });

                if (!column.IsPrimary && !column.Nullable)
                    args.Add(new { CanBeNull = false });

                if (column.CType == CType.Text || column.CType == CType.NText)
                    args.Add(new AttributeInfoArg("UpdateCheck", "UpdateCheck.Never"));

                prop.AddAttribute(new AttributeInfo("Column", args.ToArray()));

                if (!column.IsComputed)
                    clss.Add(prop);

            }

            var fkBy = schema.ByForeignKeys.Keys.OrderBy(k => k.FK_Table);

            Constructor constructor = null;
            if (fkBy.Count() > 0)
            {
                clss.AppendLine();

                constructor = new Constructor(this.cname);
            }

            List<Property> list = new List<Property>();
            foreach (var key in fkBy)
            {
                prop = AddEntitySet(clss, constructor, key);
                list.Add(prop);
            }

            var fks = schema.ForeignKeys;
            //list = new List<Property>();

            if (fks.Length > 0)
                clss.AppendLine();

            foreach (var key in fks.Keys)
            {
                prop = AddEntityRef(clss, key);
                list.Add(prop);
            }

            if (constructor != null)
                clss.Add(constructor);

            foreach (var p in list)
                clss.Add(p);
        }
开发者ID:fjiang2,项目名称:sqlcon,代码行数:78,代码来源:Linq2SQLClassBuilder.cs

示例5: AddEntityRef

        /// <summary>
        /// add foreighn keys
        /// </summary>
        /// <param name="clss"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        private Property AddEntityRef(Class clss, IForeignKey key)
        {
            string pk_cname = new TableName(tname.DatabaseName, key.PK_Schema, key.PK_Table).ToClassName(null);
            string pname = clss.MakeUniqueName(pk_cname);

            var field = new Field(new TypeInfo { userType = $"EntityRef<{pk_cname}>" }, $"_{pname}") { modifier = Modifier.Private };
            clss.Add(field);

            var prop = new Property(new TypeInfo { userType = pk_cname }, pname) { modifier = Modifier.Public };
            prop.gets.Append($"return this._{pname}.Entity;");
            prop.sets.Append($"this._{pname}.Entity = value;");
            prop.AddAttribute(new AttributeInfo("Association",
                new
                {
                    Name = $"{pk_cname}_{this.cname}",
                    Storage = $"_{pname}",
                    ThisKey = key.FK_Column,
                    OtherKey = key.PK_Column,
                    IsForeignKey = true
                }));
            return prop;
        }
开发者ID:fjiang2,项目名称:sqlcon,代码行数:28,代码来源:Linq2SQLClassBuilder.cs


注:本文中的System.Property.AddAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。