Пример #1
0
        public void foox()
        {
            var i = new SD();
            var r = typeof(IDictionary).IsAssignableFrom(i.GetType());


            // Arrange
            var entity = new TomlEntity();
            var classA = new ClassA();
            var classB = new ClassB();

            entity.Dictionary.Add(nameof(ClassA), classA);
            entity.Dictionary.Add(nameof(ClassB), classB);
            var result = Toml.WriteString(entity);

            // act
            var settings = TomlSettings.Create(cfg => cfg
                                               .ConfigureType <IDictionary <string, ISomeInterface> >(ct => ct
                                                                                                      .CreateInstance(() => new Dictionary <string, ISomeInterface>()))
                                               .ConfigureType <ISomeInterface>(tc => tc
                                                                               .CreateInstance(ctx => ctx.Key switch
            {
                nameof(ClassA) => new ClassA(),
                nameof(ClassB) => new ClassB(),
                _ => throw new System.Exception($"Key '{ctx.Key}' not recognized as a 'ISomeInterface'."),
            })));