示例#1
0
        /// <summary>
        /// フィールドの属性値をすべて取得
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tableMapper"></param>
        /// <param name="typeObject"></param>
        private void GetFieldAttribute <T>(Dictionary <string, List <string> > tableMapper, T typeObject)
        {
            FieldInfo[] arFi = typeObject.GetType().GetFields(BindingFlags.GetField);

            foreach (FieldInfo fi in arFi)
            {
                DatabaseMapAttribute at = (DatabaseMapAttribute)Attribute.GetCustomAttribute(fi, typeof(DatabaseMapAttribute));
                if (tableMapper.ContainsKey(at.Table) == true)
                {
                    tableMapper[at.Table].Add(at.Columns);
                }
                else
                {
                    var entities = new List <string>();
                    entities.Add(at.Columns);
                    tableMapper.Add(at.Table, entities);
                }
            }
        }
示例#2
0
        /// <summary>
        /// フィールドに値を設定
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="columns"></param>
        /// <param name="value"></param>
        /// <param name="typeObject"></param>
        private bool SetFieldValue <T>(string columns, object value, T typeObject)
        {
            FieldInfo[] arFi = typeObject.GetType().GetFields();

            foreach (FieldInfo fi in arFi)
            {
                DatabaseMapAttribute at = (DatabaseMapAttribute)Attribute.GetCustomAttribute(fi, typeof(DatabaseMapAttribute));

                if (at != null)
                {
                    if (at.Columns == columns)
                    {
                        SetField <T>(fi, value, typeObject, fi.MemberType.GetType());
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#3
0
        /// <summary>
        /// フィールドから値を取得
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tableName">テーブル名称</param>
        /// <param name="param">パラメータ名</param>
        /// <param name="typeObject">取得対象</param>
        /// <param name="value">出力値</param>
        /// <returns></returns>
        private bool GetFieldValue <T>(string tableName, string param, T typeObject, out object value)
        {
            FieldInfo[] arFi = typeObject.GetType().GetFields();
            foreach (FieldInfo fi in arFi)
            {
                DatabaseMapAttribute at = (DatabaseMapAttribute)Attribute.GetCustomAttribute(fi, typeof(DatabaseMapAttribute));

                if (at != null)
                {
                    // 属性設定されている場合のみ処理
                    if (tableName == at.Table && param == at.Param)
                    {
                        value = fi.GetValue(typeObject);
                        return(true);
                    }
                }
            }
            value = null;
            return(false);
        }
示例#4
0
        /// <summary>
        /// プロパティに値を設定
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="columns"></param>
        /// <param name="value"></param>
        /// <param name="typeObject"></param>
        private bool SetPropertyValue <T>(string columns, object value, T typeObject)
        {
            PropertyInfo[] arPi = typeObject.GetType().GetProperties();

            foreach (PropertyInfo pi in arPi)
            {
                DatabaseMapAttribute at = (DatabaseMapAttribute)Attribute.GetCustomAttribute(pi, typeof(DatabaseMapAttribute));

                if (at != null)
                {
                    if (at.Columns == columns)
                    {
                        SetProperty <T>(pi, value, typeObject, pi.PropertyType);
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#5
0
        /// <summary>
        /// プロパティから値を取得
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tableName"></param>
        /// <param name="param"></param>
        /// <param name="typeObject"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private bool GetPropertyValue <T>(string tableName, string param, T typeObject, out object value)
        {
            PropertyInfo[] arPi = typeObject.GetType().GetProperties();
            foreach (PropertyInfo pi in arPi)
            {
                DatabaseMapAttribute at = (DatabaseMapAttribute)Attribute.GetCustomAttribute(pi, typeof(DatabaseMapAttribute));

                if (at != null)
                {
                    // 属性設定されている場合のみ処理
                    if (tableName == at.Table && param == at.Param)
                    {
                        value = pi.GetValue(typeObject, null);
                        return(true);
                    }
                }
            }
            value = null;
            return(false);
        }
示例#6
0
        /// <summary>
        /// プロパティの属性値をすべて取得(パラメータ)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tableMapper"></param>
        /// <param name="typeObject"></param>
        private void GetPropertyAttributeParam <T>(Dictionary <string, List <string> > tableMapper, T typeObject)
        {
            PropertyInfo[] arPi = typeObject.GetType().GetProperties();
            foreach (PropertyInfo pi in arPi)
            {
                DatabaseMapAttribute at = (DatabaseMapAttribute)Attribute.GetCustomAttribute(pi, typeof(DatabaseMapAttribute));

                if (at != null)
                {
                    // 属性設定されている場合のみ処理
                    if (tableMapper.ContainsKey(at.Table) == true && string.IsNullOrEmpty(at.Param) == false)
                    {
                        tableMapper[at.Table].Add(at.Param);
                    }
                    else if (string.IsNullOrEmpty(at.Param) == false)
                    {
                        var entities = new List <string>();
                        entities.Add(at.Param);
                        tableMapper.Add(at.Table, entities);
                    }
                }
            }
        }
示例#7
0
        /// <summary>
        /// プロパティの属性値をすべて取得
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tableMapper"></param>
        /// <param name="typeObject"></param>
        private void GetPropertyAttribute <T>(Dictionary <string, List <string> > tableMapper, T typeObject)
        {
            PropertyInfo[] arPi = typeObject.GetType().GetProperties();
            foreach (PropertyInfo pi in arPi)
            {
                DatabaseMapAttribute at = (DatabaseMapAttribute)Attribute.GetCustomAttribute(pi, typeof(DatabaseMapAttribute));

                if (at == null)
                {
                    // 属性設定なしの場合は無視
                }
                else if (tableMapper.ContainsKey(at.Table) == true)
                {
                    tableMapper[at.Table].Add(at.Columns);
                }
                else
                {
                    var entities = new List <string>();
                    entities.Add(at.Columns);
                    tableMapper.Add(at.Table, entities);
                }
            }
        }