You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 19, 2020. It is now read-only.
Hello, I have a interface and some derived classes, like:
public interface ISomeInterface
{
int SomeInteger { get; set; }
string SomeString { get; set; }
}
public class ClassA : ISomeInterface
{
public int SomeInteger { get; set; } = 1;
public string SomeString { get; set; } = "This is Class A.";
public string ClassAProperty { get; set; } = "Only for Class A!";
}
public class ClassB : ISomeInterface
{
public int SomeInteger { get; set; } = 2;
public string SomeString { get; set; } = "This is Class B.";
public string ClassBProperty { get; set; } = "Only for Class B!";
}
And I have a entity class with a IDictionary property with the interface above as value type:
public class TomlEntity
{
public IDictionary<string, ISomeInterface> Dictionary { get; set; } =
new Dictionary<string, ISomeInterface>();
}
Now I can write the entity to string but cannot read into it:
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);
Console.Write(result);
var reader = Toml.ReadString<TomlEntity>(result); // error
In fact I will have more derived classes and I have their own reflection types, how can I specify their type and instantiate them into the dictionary?
Hello, I have a interface and some derived classes, like:
And I have a entity class with a IDictionary property with the interface above as value type:
Now I can write the entity to string but cannot read into it:
In fact I will have more derived classes and I have their own reflection types, how can I specify their type and instantiate them into the dictionary?