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()}"); } }
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); }
public string GetSection(Type destinationType, IMemberInfoWrapper memberInfoWrapper) { return(_attributeManager.GetSection(destinationType, memberInfoWrapper) ?? destinationType.Name); }