コード例 #1
0
        public object ReadValue(IMemberInfoWrapper memberInfoWrapper, object configuration, Type configurationType)
        {
            var(converter, defaultConverter, typeDetailsInformation) = _iniConverterFactory.GetConverter(memberInfoWrapper.GetMemberType(), 0, memberInfoWrapper);

            if (typeDetailsInformation.TypeCode == TypeCode.ComplexObject)
            {
                return(converter.ParseReadValue(null, typeDetailsInformation.Type, null));
            }

            var iniValue = new IniValue()
            {
                Section = _iniValueManager.GetSection(configurationType, memberInfoWrapper),
                Key     = _iniValueManager.GetKey(memberInfoWrapper)
            };

            try
            {
                var iniContext = new IniContext(memberInfoWrapper, typeDetailsInformation, iniValue, _iniParser, defaultConverter);

                var readValue = _iniParser.Read(iniValue.Section, iniValue.Key);

                return(converter.ParseReadValue(readValue, typeDetailsInformation.Type, iniContext));
            }
            catch (FormatException)
            {
                throw new IniWrongFormatException($"Wrong format in {iniValue} expected type: {memberInfoWrapper.GetMemberType()}");
            }
        }
コード例 #2
0
ファイル: SavingManager.cs プロジェクト: Szpi/IniWrapper
        public void SaveValue(IMemberInfoWrapper memberInfoWrapper, object configuration)
        {
            var value = memberInfoWrapper.GetValue(configuration);

            var defaultIniValue = new IniValue()
            {
                Section = _iniValueManager.GetSection(configuration.GetType(), memberInfoWrapper),
                Key     = _iniValueManager.GetKey(memberInfoWrapper),
            };

            var(converter, defaultConverter, typeDetailsInformation) = _iniConverterFactory.GetConverter(memberInfoWrapper.GetMemberType(), value, memberInfoWrapper);

            var iniContext = new IniContext(memberInfoWrapper, typeDetailsInformation, defaultIniValue, _iniParser, defaultConverter);

            var valueToSave = converter.FormatToWrite(value, iniContext);

            if (valueToSave?.Value == null)
            {
                return;
            }

            _iniParser.Write(valueToSave.Section, valueToSave.Key, valueToSave.Value);
        }
コード例 #3
0
 public string GetSection(Type destinationType, IMemberInfoWrapper memberInfoWrapper)
 {
     return(_attributeManager.GetSection(destinationType, memberInfoWrapper) ?? destinationType.Name);
 }