Esempio n. 1
0
 public CollectionConverter(
     CollectionCreator createCollection,
     ITomlSerializerContext context)
 {
     _createCollection = createCollection;
     _itemConverter    = context.GetConverter <TItem>();
 }
Esempio n. 2
0
        public TomlObject ConvertTo(object value, ITomlSerializerContext context)
        {
            // TODO: null handling
            var converter = context.GetConverter(value.GetType());

            return(converter.ConvertTo(value, context));
        }
Esempio n. 3
0
        private static NewTypeMetadata GetMetadata(Type typeToConvert, ITomlSerializerContext context)
        {
            var constructor = FindConstructor(typeToConvert);
            var innerType   = constructor.GetParameters()[0].ParameterType;
            var converter   = context.GetConverter(innerType);

            return(new NewTypeMetadata(innerType, converter, constructor, null !));
        }
Esempio n. 4
0
        public object ConvertFrom(TomlObject value, ITomlSerializerContext context)
        {
            var converter = value switch
            {
                TomlArray => (ITomlConverter)context.GetConverter <IEnumerable <object> >(),
                TomlString => context.GetConverter <string>(),
                TomlInteger => context.GetConverter <long>(),
                TomlBoolean => context.GetConverter <bool>(),
                TomlFloat => context.GetConverter <double>(),
                TomlDateTime => context.GetConverter <DateTime>(),
                TomlTable => throw new NotImplementedException(),
                      _ => throw new NotSupportedException(),
            };

            return(converter.ConvertFrom(value, context));
        }
Esempio n. 5
0
        private static CachedParameterInfo GetCachedParameterInfo(ParameterInfo info, ITomlSerializerContext context)
        {
            var converter = context.GetConverter(info.ParameterType);

            return(new CachedParameterInfo(info, converter));
        }
Esempio n. 6
0
 public DictionaryConverter(Type instanceType, ITomlSerializerContext context)
 {
     _valueConverter = context.GetConverter <TValue>();
     _instanceType   = instanceType;
 }
Esempio n. 7
0
 public Guid ConvertFrom(TomlObject value, ITomlSerializerContext context)
 => Guid.Parse(context.GetConverter <string>().ConvertFrom(value, context));
 public static ITomlConverter <T> GetConverter <T>(this ITomlSerializerContext context)
 => context.GetConverter(typeof(T)).AsTomlConverter <T>();