/// <inheritdoc />
        public void Add(T setting)
        {
            ThrowIfReadOnly();

            if (setting.IsHelp)
            {
                if (HasHelpCommand)
                {
                    throw new InvalidOperationException("Do not add more than one help command into a setting parser.");
                }
                HasHelpCommand = true;
            }

            var guid = Guid.NewGuid();

            foreach (var name in setting.Names)
            {
                NameMap.Add(name, guid);
            }
            SettingMap.Add(guid, setting);
            setting.AssociateParser(this);
        }
예제 #2
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;
        }
예제 #3
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;
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cs"></param>
        public NameSection(CustomSection cs)
        {
            var stream           = new MemoryStream((byte[])cs.Content);
            var reader           = new Reader(stream);
            var previousSection  = NameSubsection.Module;
            var preSectionOffset = reader.Offset;

            while (reader.TryReadVarUInt7(out var id)) //At points where TryRead is used, the stream can safely end.
            {
                if (id != 0 && (NameSubsection)id < previousSection)
                {
                    throw new ModuleLoadException($"Sections out of order; section {(NameSubsection)id} encounterd after {previousSection}.", preSectionOffset);
                }
                var payloadLength = reader.ReadVarUInt32();

                switch ((NameSubsection)id)
                {
                case NameSubsection.Module:
                {
                    var nameLength = reader.ReadVarUInt32();
                    Name = reader.ReadString(nameLength);
                }
                break;

                case NameSubsection.Function:
                {
                    var count = reader.ReadVarUInt32();
                    Functions = new FunctionMap((int)count);
                    for (int i = 0; i < count; i++)
                    {
                        var index      = reader.ReadVarUInt32();
                        var nameLength = reader.ReadVarUInt32();
                        var name       = reader.ReadString(nameLength);
                        Functions.Add(index, name);
                    }
                }
                break;

                case NameSubsection.Local:
                {
                    var fun_count = reader.ReadVarUInt32();
                    Locals = new LocalMap((int)fun_count);
                    for (int f = 0; f < fun_count; f++)
                    {
                        var fun_index = reader.ReadVarUInt32();

                        var count   = reader.ReadVarUInt32();
                        var nameMap = new NameMap((int)count);
                        Locals.Add(fun_index, nameMap);
                        for (int i = 0; i < count; i++)
                        {
                            var index      = reader.ReadVarUInt32();
                            var nameLength = reader.ReadVarUInt32();
                            var name       = reader.ReadString(nameLength);
                            nameMap.Add(index, name);
                        }
                    }
                }
                break;
                }

                previousSection = (NameSubsection)id;
            }
        }