コード例 #1
0
        public IniValue FormatToWrite(object objectToFormat, IniContext iniContext)
        {
            if (iniContext.TypeDetailsInformation.UnderlyingKeyTypeInformation.TypeCode == TypeCode.ComplexObject ||
                iniContext.TypeDetailsInformation.UnderlyingTypeInformation.TypeCode == TypeCode.ComplexObject)
            {
                throw new CollectionOfComplexTypeException($"Collection of complex type not supported for {iniContext}");
            }

            if (!(objectToFormat is IDictionary dictionary))
            {
                throw new InvalidOperationException();
            }

            var dictionaryEnumerator = dictionary.GetEnumerator();

            while (dictionaryEnumerator.MoveNext())
            {
                if (dictionaryEnumerator.Key == null || dictionaryEnumerator.Value == null)
                {
                    continue;
                }

                var value = _underlyingTypeIniConverter.FormatToWrite(dictionaryEnumerator.Value, iniContext)?.Value;

                iniContext.IniParser.Write(iniContext.IniValue.Key,
                                           _underlyingKeyTypeIniConverter.FormatToWrite(dictionaryEnumerator.Key, iniContext)?.Value,
                                           value);
            }

            return(null);
        }
コード例 #2
0
        public IniValue FormatToWrite(object objectToFormat, IniContext iniContext)
        {
            var enumerable = objectToFormat as IEnumerable;

            var stringBuilder = new StringBuilder();

            foreach (var item in enumerable)
            {
                if (item == null)
                {
                    continue;
                }

                stringBuilder.Append(_underlyingTypeIniConverter.FormatToWrite(item, iniContext)?.Value);
                stringBuilder.Append(_iniSettings.EnumerableEntitySeparator);
            }

            RemoveLastSeparator(stringBuilder);

            iniContext.IniValue.Value = stringBuilder.ToString();

            return(iniContext.IniValue);
        }
コード例 #3
0
        public IniValue FormatToWrite(object objectToFormat, IniContext iniContext)
        {
            var ignoreAttribute = _memberInfoWrapper.GetAttribute <IniIgnoreAttribute>();

            return(ignoreAttribute == null?_iniConverter.FormatToWrite(objectToFormat, iniContext) : null);
        }
コード例 #4
0
 public IniValue FormatToWrite(object objectToFormat, IniContext iniContext)
 {
     objectToFormat = Activator.CreateInstance(iniContext.TypeDetailsInformation.UnderlyingTypeInformation.Type);
     return(_complexTypeIniConverter.FormatToWrite(objectToFormat, iniContext));
 }