Exemplo n.º 1
0
        /// <summary>
        /// 컬럼명=속성명 매핑함수를 이용하여 지정된 DataReader의 컬럼명을 속성명으로 매핑한다.
        /// </summary>
        /// <param name="reader">instance of IDataReader</param>
        /// <param name="mappingFunc">mapping function</param>
        /// <param name="propertyNamesToExclude">매핑에서 제외할 속성명</param>
        /// <returns>instance of <see cref="INameMap"/></returns>
        public static INameMap Mapping(this IDataReader reader, Func <string, string> mappingFunc, params string[] propertyNamesToExclude)
        {
            reader.ShouldNotBeNull("reader");
            mappingFunc.ShouldNotBeNull("mappingFunc");

            if (IsDebugEnabled)
            {
                log.Debug("지정된 DataReader의 컬럼명을 속성명으로 매핑합니다...");
            }

            var nameMap      = new NameMap();
            var excludeNames = (propertyNamesToExclude != null) ? propertyNamesToExclude.ToList() : new List <string>();

            for (int i = 0; i < reader.FieldCount; i++)
            {
                var columnName = reader.GetName(i);

                if (columnName.IsNotWhiteSpace())
                {
                    var propertyName = mappingFunc(columnName);

                    if (propertyName.IsNotWhiteSpace() && excludeNames.Contains(propertyName, StringComparer.Ordinal) == false)
                    {
                        nameMap.Add(columnName, propertyName);
                    }
                }
            }

            if (IsDebugEnabled)
            {
                log.Debug("컬럼명-속성명 매핑 결과 = " + nameMap.CollectionToString());
            }

            return(nameMap);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Command의 Parameter 정보와 속성 정보를 매핑한다. (ParameterName = 속성명) 형식
        /// </summary>
        /// <param name="command">instance of DbCommand to execute</param>
        /// <param name="mappingFunc">Mapping function. input = parameter name of command , result = property name of persistent object </param>
        /// <param name="propertyNamesToExclude">매핑에서 제외할 속성명</param>
        /// <returns>instance of <see cref="INameMap"/>, Key = parameter name of a specified command, Value = property name of persistent object</returns>
        public static INameMap Mapping(this DbCommand command, Func <string, string> mappingFunc, params string[] propertyNamesToExclude)
        {
            command.ShouldNotBeNull("command");
            mappingFunc.ShouldNotBeNull("mappingFunc");

            if (IsDebugEnabled)
            {
                log.Debug("Command 파라미터명을 속성명으로 매핑합니다...");
            }

            var nameMap      = new NameMap();
            var excludeNames = (propertyNamesToExclude != null) ? propertyNamesToExclude.ToList() : new List <string>();

            foreach (IDataParameter parameter in command.Parameters)
            {
                var paramName = parameter.ParameterName.RemoveParameterPrefix();

                if (paramName.IsNotWhiteSpace())
                {
                    var propertyName = mappingFunc(paramName);

                    if (propertyName.IsNotWhiteSpace() && excludeNames.Contains(propertyName, StringComparer.Ordinal) == false)
                    {
                        nameMap.Add(paramName, propertyName);
                    }
                }
            }

            if (IsDebugEnabled)
            {
                log.Debug("Command 파라미터명-속성명 매핑 결과 = " + nameMap.CollectionToString());
            }

            return(nameMap);
        }