Example #1
0
        private IEnumerable <KeyValuePair <string, string> > BonusGetFieldsWithValuesIEnumerable(TTable entity)
        {
            foreach (PropertyInfo prop in tableFieldPropertyInfos)
            {
                KeyAttribute keyNameAttribute = (prop.GetCustomAttribute(typeof(KeyAttribute)) as KeyAttribute);

                string name = keyNameAttribute?.Name ?? prop.Name;

                string value = entity != null?prop.GetValue(entity)?.ToString() : null;

                yield return(new KeyValuePair <string, string>(name, value));
            }
        }
Example #2
0
 /// <summary>
 /// Lấy về giá trị của khóa chính
 /// </summary>
 /// <returns>Giá trị của khóa</returns>
 /// Create by:dvthang:20.04.2017
 public void SetIdentity(object value)
 {
     PropertyInfo[] properties = this.GetType().GetProperties();
     foreach (PropertyInfo property in properties)
     {
         KeyAttribute keyAttr = property.GetCustomAttribute <KeyAttribute>(true);
         if (keyAttr != null)
         {
             property.SetValue(this, value);
             break;
         }
     }
 }
Example #3
0
        public static PropertyInfo GetKeyProperty(Type type)
        {
            foreach (PropertyInfo prop in type.GetProperties())
            {
                KeyAttribute keyAttribute = type.GetProperty(prop.Name).GetCustomAttributes(typeof(KeyAttribute), false).Cast <KeyAttribute>().Single();
                if (keyAttribute != null)
                {
                    return(prop);
                }
            }

            return(null);
        }
Example #4
0
        private void SetupTableNonPrimaryFields(PropertyInfo[] allTableFieldsProperties)
        {
            tableFieldPropertyInfos = allTableFieldsProperties.Where(f => f.GetCustomAttribute(typeof(PrimaryKeyAttribute)) == null).ToList();

            tableFieldNames = tableFieldPropertyInfos
                              .Select(pf =>
            {
                KeyAttribute keyNameAttribute = (pf.GetCustomAttribute(typeof(KeyAttribute)) as KeyAttribute);

                return(keyNameAttribute?.Name ?? pf.Name);
            })
                              .ToList();
        }
Example #5
0
 /// <summary>
 /// Lấy về giá trị của khóa chính
 /// </summary>
 /// <returns>Giá trị của khóa</returns>
 /// Create by:dvthang:20.04.2017
 public object GetIdentity()
 {
     PropertyInfo[] properties = this.GetType().GetProperties();
     foreach (PropertyInfo property in properties)
     {
         KeyAttribute keyAttr = property.GetCustomAttribute <KeyAttribute>(true);
         if (keyAttr != null)
         {
             return(property.GetValue(this));
         }
     }
     return(null);
 }
Example #6
0
        public override int GetHashCode()
        {
            int hash = 17;

            foreach (PropertyInfo oProperty in this.GetType().GetProperties())
            {
                KeyAttribute keyAttribute = oProperty.GetCustomAttribute <KeyAttribute>();
                if (keyAttribute != null)
                {
                    hash ^= oProperty.GetValue(this, null).GetHashCode();
                }
            }
            return(hash);
        }
        /// <summary>
        /// Gets the name of the property that is the primary key for the model.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns>The primary key property name.</returns>
        private static string GetPrimaryKeyName(this Type type)
        {
            PropertyInfo[] infos = type.GetProperties();
            foreach (PropertyInfo pi in infos)
            {
                KeyAttribute k = (KeyAttribute)pi.GetCustomAttribute(typeof(KeyAttribute));
                if (k != null)
                {
                    return(pi.Name);
                }
            }

            return(string.Empty);
        }
Example #8
0
        /// <summary>
        /// Tên của khóa chính
        /// </summary>
        /// <returns>Tên khóa</returns>
        /// Create by: dvthang:20.04.2017
        public string GetKeyName()
        {
            PropertyInfo[] properties = this.GetType().GetProperties();

            foreach (PropertyInfo property in properties)
            {
                KeyAttribute keyAttr = property.GetCustomAttribute <KeyAttribute>(true);
                if (keyAttr != null)
                {
                    return(property.Name);
                }
            }
            return(string.Empty);
        }
Example #9
0
        private void SetupTablePrimaryField(PropertyInfo[] allTableFieldsProperties)
        {
            List <PropertyInfo> primaryKeyFields = allTableFieldsProperties.Where(f => f.GetCustomAttribute(typeof(PrimaryKeyAttribute)) != null).ToList();

            if (primaryKeyFields.Count != 1)
            {
                throw new InvalidRepositoryTableException($"Table {TableName} has {primaryKeyFields.Count} primary fields and should have one.");
            }
            primaryKeyFieldPropertyInfo = primaryKeyFields.First();

            KeyAttribute primaryKeyKeyNameAttribute = (primaryKeyFieldPropertyInfo.GetCustomAttribute(typeof(KeyAttribute)) as KeyAttribute);

            primaryKeyFieldName = primaryKeyKeyNameAttribute?.Name ?? primaryKeyFieldPropertyInfo.Name;
        }
    static KeyAttribute GetKeyAttribute_OrNull(MemberInfo pMember)
    {
        var arrAttribute = pMember.GetCustomAttributes();

        foreach (var pAttribute in arrAttribute)
        {
            KeyAttribute pAttributeKey = pAttribute as KeyAttribute;
            if (pAttributeKey != null)
            {
                return(pAttributeKey);
            }
        }

        return(null);
    }
Example #11
0
        private IInsqlEntityMap CreateAnnotationEntityMap(Type entityType)
        {
            TableAttribute tableAttribute = (TableAttribute)entityType.GetCustomAttribute(typeof(TableAttribute), true);

            IInsqlEntityMap resultMap = new InsqlEntityMap(entityType, tableAttribute.Name, tableAttribute.Schema);

            var columnMaps = entityType.GetProperties(BindingFlags.Instance | BindingFlags.Public).Select(propInfo =>
            {
                ColumnAttribute columnAttribute       = (ColumnAttribute)propInfo.GetCustomAttribute(typeof(ColumnAttribute), true);
                KeyAttribute keyAttribute             = (KeyAttribute)propInfo.GetCustomAttribute(typeof(KeyAttribute), true);
                NotMappedAttribute notMappedAttribute = (NotMappedAttribute)propInfo.GetCustomAttribute(typeof(NotMappedAttribute), true);
                EditableAttribute editableAttribute   = (EditableAttribute)propInfo.GetCustomAttribute(typeof(EditableAttribute), true);
                DatabaseGeneratedAttribute databaseGeneratedAttribute = (DatabaseGeneratedAttribute)propInfo.GetCustomAttribute(typeof(DatabaseGeneratedAttribute), true);

                InsqlPropertyMap propertyMap = new InsqlPropertyMap(propInfo, columnAttribute?.Name);

                if (keyAttribute != null)
                {
                    propertyMap.IsKey = true;
                }
                if (notMappedAttribute != null)
                {
                    propertyMap.IsIgnored = true;
                }
                if (databaseGeneratedAttribute != null)
                {
                    if (databaseGeneratedAttribute.DatabaseGeneratedOption == DatabaseGeneratedOption.Identity)
                    {
                        propertyMap.IsIdentity = true;
                    }
                }
                if (editableAttribute != null && !editableAttribute.AllowEdit)
                {
                    propertyMap.IsReadonly = true;
                }

                return(propertyMap);
            });

            foreach (var columnMap in columnMaps)
            {
                resultMap.Properties.Add(columnMap);
            }

            InsqlEntityValidator.Instance.Validate(resultMap);

            return(resultMap);
        }
Example #12
0
        private IEnumerable <PropertyInfo> GetPropertyInfos <T>(T entity)
        {
            Type type = entity.GetType();
            var  ps   = type.GetProperties().Where(m =>
            {
                var obj = m.GetCustomAttributes(typeof(KeyAttribute), false).FirstOrDefault();
                if (obj != null)
                {
                    KeyAttribute key = obj as KeyAttribute;
                    return(!key.Increment);
                }
                return(true);
            });

            return(ps);
        }
Example #13
0
        /// <summary>
        /// If a field has a primary key type defined, gets the information for it
        /// </summary>
        /// <param name="dfi">The field to check</param>
        /// <param name="pi">The property information for the field</param>
        protected void ParsePrimaryFieldType(DataFieldInfo dfi, PropertyInfo pi)
        {
            dfi.PrimaryKey = false;

            if (pi.Name.Equals("id", StringComparison.InvariantCultureIgnoreCase))
            {
                dfi.PrimaryKey = true;
            }

            KeyAttribute ka = pi.GetCustomAttributes(typeof(KeyAttribute), true).FirstOrDefault() as KeyAttribute;

            if (ka != null)
            {
                dfi.PrimaryKey = true;
            }
        }
Example #14
0
        protected List <string> GetKeyColumns <T>(T obj)
        {
            PropertyInfo[] props        = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
            List <string>  indexColumns = new List <string>();

            foreach (var prop in props)
            {
                KeyAttribute attributes = (KeyAttribute)prop.GetCustomAttribute(typeof(KeyAttribute));
                if (attributes != null)
                {
                    indexColumns.Add(prop.Name);
                }
            }

            return(indexColumns);
        }
Example #15
0
        private Dictionary <string, string> GetFieldsWithValues(TTable entity)
        {
            Dictionary <string, string> fieldsWithValues = new Dictionary <string, string>();

            foreach (PropertyInfo prop in tableFieldPropertyInfos)
            {
                KeyAttribute keyNameAttribute = (prop.GetCustomAttribute(typeof(KeyAttribute)) as KeyAttribute);

                string name = keyNameAttribute?.Name ?? prop.Name;

                string value = entity != null?prop.GetValue(entity)?.ToString() : null;

                fieldsWithValues.Add(name, value);
            }

            return(fieldsWithValues);
        }
Example #16
0
 public DbMapInfo(string dbName, string netName, Type type)
 {
     DbName  = dbName;
     NetName = netName;
     PropertyInfo[] properties = type.GetProperties(s_flag);
     ColumnMapInfos = new List <ColumnMapInfo>();
     foreach (PropertyInfo prop in properties)
     {
         KeyAttribute       attrKey    = prop.GetCustomAttribute <KeyAttribute>();
         ColumnAttribute    attrColumn = prop.GetCustomAttribute <ColumnAttribute>();
         NotMappedAttribute attrIgnore = prop.GetCustomAttribute <NotMappedAttribute>();
         bool   iskey     = attrKey != null;
         string dbColName = attrIgnore != null ? string.Empty : ((attrColumn != null && !string.IsNullOrEmpty(attrColumn.Name)) ? attrColumn.Name : prop.Name);
         ColumnMapInfos.Add(new ColumnMapInfo(dbColName, prop.Name, prop.PropertyType, iskey));
     }
     CacheColumnMapInfos = ColumnMapInfos.ToDictionary(e => e.PropName, e => e);
 }
Example #17
0
        private static IEnumerable <string> GetKeyPropertyNames(Type t)
        {
            object[] attributes = t.GetCustomAttributes(typeof(KeyAttribute), false);
            if (attributes.Length > 0)
            {
                KeyAttribute attrib = (KeyAttribute)attributes[0];
                return(attrib.KeyNames);
            }

            if (t.GetProperty("ID") != null)
            {
                return new string[] { "ID" }
            }
            ;

            return(new string[] { });
        }
Example #18
0
 private IEnumerable <PropertyInfo> TransferObjectIntoProperty(Type type)
 {
     PropertyInfo[] props = type.GetProperties();
     foreach (var prop in props)
     {
         object[] attrs = prop.GetCustomAttributes(true);
         foreach (object attr in attrs)
         {
             KeyAttribute keyAttr = attr as KeyAttribute;
             if (keyAttr != null)
             {
                 props.Where(t => t.Name != prop.Name);
             }
         }
     }
     return(props);
 }
Example #19
0
        /// <summary>
        ///  获取实体对象Key
        /// </summary>
        /// <returns></returns>
        public static string GetEntityKey <T>()
        {
            Type type = typeof(T);

            PropertyInfo[] props = type.GetProperties();
            foreach (PropertyInfo prop in props)
            {
                foreach (System.Attribute attr in prop.GetCustomAttributes(true))
                {
                    KeyAttribute keyattribute = attr as KeyAttribute;
                    if (keyattribute != null)
                    {
                        return(prop.Name);
                    }
                }
            }
            return(null);
        }
Example #20
0
        /// <summary> 需要从Eclipse命名空间初始化的项 </summary>
        public void InitRegisterFromEclipse(Type item)
        {
            var objs = item.GetCustomAttributes(typeof(KeyAttribute), false);

            if (objs != null && objs.Length > 0)
            {
                KeyAttribute k = objs[0] as KeyAttribute;

                if (k.SimKeyType == SimKeyType.EclipseAndSimON || k.SimKeyType == SimKeyType.SimON)
                {
                    //  表格形式关键字
                    if (item.IsSubclassOf(typeof(TableKey)))
                    {
                        this.KeyTableSimONConfiger.Add(item.Name);
                    }
                }
            }
        }
Example #21
0
        /// <summary>
        /// Returns the KeyKind if <paramref name="propertyInfo"/> is declared as a key in <paramref name="dataServiceKeyAttribute"/> or it follows the key naming convension.
        /// </summary>
        /// <param name="propertyInfo">Property in question.</param>
        /// <param name="dataServiceKeyAttribute">DataServiceKeyAttribute instance.</param>
        /// <returns>Returns the KeyKind if <paramref name="propertyInfo"/> is declared as a key in <paramref name="dataServiceKeyAttribute"/> or it follows the key naming convension.</returns>
        private static KeyKind IsKeyProperty(PropertyInfo propertyInfo, KeyAttribute dataServiceKeyAttribute)
        {
            Debug.Assert(propertyInfo != null, "propertyInfo != null");

            string propertyName = GetServerDefinedName(propertyInfo);

            KeyKind keyKind = KeyKind.NotKey;

            if (dataServiceKeyAttribute != null && dataServiceKeyAttribute.KeyNames.Contains(propertyName))
            {
                keyKind = KeyKind.AttributedKey;
            }
            else if (propertyName.EndsWith("ID", StringComparison.Ordinal))
            {
                string declaringTypeName = propertyInfo.DeclaringType.Name;
                if ((propertyName.Length == (declaringTypeName.Length + 2)) && propertyName.StartsWith(declaringTypeName, StringComparison.Ordinal))
                {
                    // matched "DeclaringType.Name+ID" pattern
                    keyKind = KeyKind.TypeNameId;
                }
                else if (2 == propertyName.Length)
                {
                    // matched "ID" pattern
                    keyKind = KeyKind.Id;
                }
            }
            else if (propertyName.EndsWith("Id", StringComparison.Ordinal))
            {
                string declaringTypeName = propertyInfo.DeclaringType.Name;
                if ((propertyName.Length == (declaringTypeName.Length + 2)) && propertyName.StartsWith(declaringTypeName, StringComparison.Ordinal))
                {
                    // matched "DeclaringType.Name+Id" pattern
                    keyKind = KeyKind.LowerTypeNameId;
                }
                else if (2 == propertyName.Length)
                {
                    // matched "Id" pattern
                    keyKind = KeyKind.LowerId;
                }
            }

            return(keyKind);
        }
Example #22
0
        private string getIdPropertyName()
        {
            string propName = string.Empty;

            PropertyInfo[] props = typeof(ET).GetProperties();
            foreach (PropertyInfo prop in props)
            {
                object[] attrs = prop.GetCustomAttributes(true);
                foreach (object attr in attrs)
                {
                    KeyAttribute authAttr = attr as KeyAttribute;
                    if (authAttr != null)
                    {
                        propName = prop.Name;
                    }
                }
            }
            return(propName);
        }
Example #23
0
        static public string CreateTableSql <T>(string tableName)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(string.Format("CREATE TABLE [dbo].[{0}](", tableName));
            bool haskey = false;

            foreach (var dcol in typeof(T).GetProperties())
            {
                var    filedAttr = FiledInfoAttribute.GetAttribute(dcol);
                string typename  = filedAttr != null ? filedAttr.PropertyTypeName : "";
                int    len       = filedAttr != null ? filedAttr.Len : -1;
                string cannull   = filedAttr != null ? filedAttr.CanNull ? "NULL" : "NOT NULL" : "NOT NULL";
                if (string.IsNullOrWhiteSpace(typename))
                {
                    typename = SqlHelp.ConvertType2Sql(dcol.PropertyType.Name);
                }
                stringBuilder.Append(string.Format("[{0}] [{1}]", dcol.Name, typename));
                if (len != -1)
                {
                    stringBuilder.Append(string.Format("({0})", len));
                }
                if (IdentityAttribute.GetAttribute(dcol) != null)
                {
                    stringBuilder.Append("IDENTITY(1,1)");
                }
                stringBuilder.Append(string.Format(" {0}", cannull));
                stringBuilder.Append(",");
                if (KeyAttribute.IsDefined(dcol, typeof(KeyAttribute)))
                {
                    stringBuilder.Append(string.Format(@"CONSTRAINT [PK_{0}] PRIMARY KEY CLUSTERED ([{1}] ASC),", tableName, dcol.Name));
                    haskey = true;
                }
            }
            if (!haskey)
            {
                throw new InvalidOperationException("you need appoint PRIMARY use KeyAttribute " + typeof(T).Name + " above");
            }

            stringBuilder.Append(") ON [PRIMARY]");

            return(stringBuilder.ToString());
        }
Example #24
0
        /// <summary>
        /// 修改时的特殊赋值
        /// 不修改key主键
        /// 属性不存在,不修改
        /// 属性值为null,旧实例属性也置为null
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="U"></typeparam>
        /// <param name="oldObject"></param>
        /// <param name="newObject"></param>
        public static void ModifySetValue <T, U>(T oldObject, U newObject)
        {
            //用list的数据,替换ItemSource
            foreach (var item in oldObject.GetType().GetProperties())
            {
                var          l1 = item.GetCustomAttributes(typeof(KeyAttribute), true);
                KeyAttribute p1 = l1.Count() > 0 ? l1[0] as KeyAttribute : null;

                if (p1 == null)//只能为不是key的值赋值
                {
                    var va = newObject.GetType().GetProperty(item.Name);
                    if (va != null)
                    {
                        var temp = va.GetValue(newObject);
                        item.SetValue(oldObject, temp);
                    }
                }
            }
        }
Example #25
0
        internal static Dictionary <string, object> GetFieldsWithValues <T>(T entity, List <PropertyInfo> properties, bool ignoreAutoIncrementKey) where T : new()
        {
            var output = new Dictionary <string, object>();

            properties.ForEach(property =>
            {
                if (Attribute.IsDefined(property, typeof(ForeignKeyModelAttribute)) ||
                    Attribute.IsDefined(property, typeof(IgnoreAttribute)) ||
                    (ignoreAutoIncrementKey && KeyAttribute.IsAutoIncrementKey(property)))     // Ignore Auto increment key
                {
                    return;
                }

                var columnName = ColumnAttribute.GetColumnName(typeof(T), property.Name);
                output.Add(columnName, property.GetValue(entity));
            });

            return(output);
        }
Example #26
0
        public (bool, string) migraGeneral(sipiunitec_dbContext _MiContexto, object _tablaDestino, object _tablaTemporal, bool _saltaClave, [Optional] string _clave, [Optional] long _valor)
        {
            #region "*** Lee Valor TMP y Crea objeto a guardar ***"
            var propInfo = _tablaDestino.GetType().GetProperties();
            foreach (var item in propInfo)
            {
                KeyAttribute key = Attribute.GetCustomAttribute(item, typeof(KeyAttribute)) as KeyAttribute;
                if (key == null || _saltaClave == false)
                {
                    try
                    {
                        var campo   = item.Name;
                        var _valida = _tablaTemporal.GetType().GetProperty(campo);
                        if (_valida != null)
                        {
                            var values = _tablaTemporal.GetType().GetProperty(campo).GetValue(_tablaTemporal, null);
                            _tablaDestino.GetType().GetProperty(campo).SetValue(_tablaDestino, values, null);
                        }
                    }
                    catch (DbUpdateException) { }
                }
                else if (_clave != null)
                {
                    var values = _valor;
                    _tablaDestino.GetType().GetProperty(_clave).SetValue(_tablaDestino, values, null);
                }
            }
            #endregion

            #region "*** Guarda el objeto en la tabla ***"
            try
            {
                _MiContexto.Add(_tablaDestino);
                _context.SaveChanges();
                return(false, "");
            }
            catch (DbUpdateException ex)
            {
                _context.Entry(_tablaDestino).State = EntityState.Detached;
                return(true, ex.InnerException.Message.ToString());
            }
            #endregion
        }
Example #27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entityType"></param>
        /// <returns></returns>
        public EntityMap CreateEntityMap(Type entityType)
        {
            var map = GetEntityMap(entityType);

            if (map != null)
            {
                return(map);
            }
            map = new EntityMap(entityType);
            var tableAttr = entityType.GetCustomAttribute <TableAttribute>();

            map.TableName = string.IsNullOrEmpty(tableAttr.Name) ? entityType.Name : tableAttr.Name;


            PropertyInfo[] properties = entityType.GetProperties(s_flag);

            foreach (PropertyInfo prop in properties)
            {
                KeyAttribute       attrKey    = prop.GetCustomAttribute <KeyAttribute>();
                ColumnAttribute    attrColumn = prop.GetCustomAttribute <ColumnAttribute>();
                NotMappedAttribute attrIgnore = prop.GetCustomAttribute <NotMappedAttribute>();
                if (attrIgnore != null)
                {
                    continue;
                }
                bool   iskey     = attrKey != null;
                string dbColName = attrIgnore != null ? string.Empty : ((attrColumn != null && !string.IsNullOrEmpty(attrColumn.Name)) ? attrColumn.Name : prop.Name);
                var    pm        = new PropertyMap
                {
                    PropertyName = prop.Name,
                    ColumnName   = dbColName,
                    PropertyType = prop.PropertyType
                };
                if (iskey)
                {
                    map.KeyMaps.Add(pm);
                }
                map.PropertyMaps.Add(pm);
            }
            _cache.TryAdd(entityType, map);
            return(map);
        }
Example #28
0
        /// <summary>
        /// Kiểm tra giá trị khóa có phải là kiểu tự tăng hay không
        /// </summary>
        /// Create by:dvthang:20.04.2017
        public bool HasIdentity()
        {
            bool isIdentity = false;

            PropertyInfo[] properties = this.GetType().GetProperties();
            foreach (PropertyInfo pi in properties)
            {
                KeyAttribute keyAttr = pi.GetCustomAttribute <KeyAttribute>(true);
                if (keyAttr != null)
                {
                    if (pi.PropertyType == typeof(int) || pi.PropertyType == typeof(Int32) ||
                        pi.PropertyType == typeof(Int64) || pi.PropertyType == typeof(Int16))
                    {
                        isIdentity = true;
                    }
                    break;
                }
            }
            return(isIdentity);
        }
Example #29
0
File: DBEx.cs Project: tfwcn/blog
 /// <summary>
 /// 获取主键字段名称
 /// </summary>
 public static string GetPKName(this Type objType)
 {
     foreach (var property in objType.GetPropertiesPGS(false))
     {
         KeyAttribute    keyAttribute    = Attribute.GetCustomAttribute(property, typeof(KeyAttribute)) as KeyAttribute;
         ColumnAttribute columnAttribute = Attribute.GetCustomAttribute(property, typeof(ColumnAttribute)) as ColumnAttribute;
         if (keyAttribute != null)
         {
             if (columnAttribute != null && !String.IsNullOrEmpty(columnAttribute.Name))
             {
                 return(columnAttribute.Name);
             }
             else
             {
                 return(property.Name);
             }
         }
     }
     return(null);
 }
    static void ProcAddField(IEnumerable <PropertyInfo> arrProperty)
    {
        if (arrProperty.Count() == 0)
        {
            return;
        }

        foreach (PropertyInfo pProperty in arrProperty)
        {
            SMemberWrapper sMemberWrapper = new SMemberWrapper(pProperty);
            KeyAttribute   pKeyAttribute  = GetKeyAttribute_OrNull(pProperty);
            if (pKeyAttribute != null)
            {
                AddDictionary_MemberInfo(pKeyAttribute.strKeyName, ref sMemberWrapper);
            }
            else
            {
                AddDictionary_MemberInfo(pProperty.Name, ref sMemberWrapper);
            }
        }
    }
Example #31
0
        /// <summary> Write a Key XML Element from attributes in a member. </summary>
        public virtual void WriteKey(System.Xml.XmlWriter writer, System.Reflection.MemberInfo member, KeyAttribute attribute, BaseAttribute parentAttribute, System.Type mappedClass)
        {
            writer.WriteStartElement( "key" );
            // Attribute: <column>
            if(attribute.Column != null)
            writer.WriteAttributeString("column", GetAttributeValue(attribute.Column, mappedClass));
            // Attribute: <property-ref>
            if(attribute.PropertyRef != null)
            writer.WriteAttributeString("property-ref", GetAttributeValue(attribute.PropertyRef, mappedClass));
            // Attribute: <foreign-key>
            if(attribute.ForeignKey != null)
            writer.WriteAttributeString("foreign-key", GetAttributeValue(attribute.ForeignKey, mappedClass));
            // Attribute: <on-delete>
            if(attribute.OnDelete != OnDelete.Unspecified)
            writer.WriteAttributeString("on-delete", GetXmlEnumValue(typeof(OnDelete), attribute.OnDelete));
            // Attribute: <not-null>
            if( attribute.NotNullSpecified )
            writer.WriteAttributeString("not-null", attribute.NotNull ? "true" : "false");
            // Attribute: <update>
            if( attribute.UpdateSpecified )
            writer.WriteAttributeString("update", attribute.Update ? "true" : "false");
            // Attribute: <unique>
            if( attribute.UniqueSpecified )
            writer.WriteAttributeString("unique", attribute.Unique ? "true" : "false");

            WriteUserDefinedContent(writer, member, null, attribute);

            System.Collections.ArrayList memberAttribs = GetSortedAttributes(member);
            int attribPos; // Find the position of the KeyAttribute (its <sub-element>s must be after it)
            for(attribPos=0; attribPos<memberAttribs.Count; attribPos++)
                if( memberAttribs[attribPos] is KeyAttribute
                    && ((BaseAttribute)memberAttribs[attribPos]).Position == attribute.Position )
                    break; // found
            int i = attribPos + 1;

            // Element: <column>
            for(; i<memberAttribs.Count; i++)
            {
                BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute;
                if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType())
                    || IsNextElement(memberAttrib, attribute, typeof(ColumnAttribute)) )
                    break; // next attributes are 'elements' of the same level OR for 'sub-elements'
                else
                {
                    if( memberAttrib is KeyAttribute )
                        break; // Following attributes are for this Key
                    if( memberAttrib is ColumnAttribute )
                        WriteColumn(writer, member, memberAttrib as ColumnAttribute, attribute, mappedClass);
                }
            }
            WriteUserDefinedContent(writer, member, typeof(ColumnAttribute), attribute);

            writer.WriteEndElement();
        }
Example #32
0
			public KeyMember(PropertyInfo pi, KeyAttribute attr)
			{
				_pi = pi;
				_getMemberValue = o => _pi.GetValue(o, null);
				_setMemberValue = (o1, o2) => _pi.SetValue(o1, o2, null);
				Type = _pi.PropertyType;
				Attribute = attr;
				if (attr != null && !string.IsNullOrEmpty(attr.Name))
					Name = attr.Name;
				else
					Name = pi.Name;
			}
Example #33
0
			public KeyMember(FieldInfo fi, KeyAttribute attr)
			{
				_fi = fi;
				_getMemberValue = o => _fi.GetValue(o);
				_setMemberValue = (o1, o2) => _fi.SetValue(o1, o2);
				Type = _fi.FieldType;
				Attribute = attr;
				if (attr != null && !string.IsNullOrEmpty(attr.Name))
					Name = attr.Name;
				else
					Name = fi.Name;
			}
Example #34
0
			public KeyMember(FieldInfo fi, KeyAttribute attr)
			{
				_fi = fi;
				//_type = _fi.FieldType;
				_getMemberValue = o => _fi.GetValue(o);
				Attribute = attr;
				Name = fi.Name;
			}
Example #35
0
			//private Type _type;


			public KeyMember(PropertyInfo pi, KeyAttribute attr)
			{
				_pi = pi;
				//_type = _pi.PropertyType;
				_getMemberValue = o => _pi.GetValue(o, null);
				Attribute = attr;
				Name = pi.Name;
			}