-
-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Labels
PR welcomeUser contribution/PR is welcomeUser contribution/PR is welcomeenhancementNew feature or requestNew feature or request
Description
Polymorphic Deserialization also knowns Type-Tagged Deserialization, means to deserialize objects with difference types by type field (such as type). for example:
[[db_connections]]
type = "mysql"
host = "localhost"
port = 3306
user_id = "root"
password = "123"
schema = "db_test"
[[db_connections]]
type = "sqlite"
file_path = "/var/sqlite/test.db"
password = "123"Now look at both items of db_connections, it's basically different but with a same field type. Because of the type field it can be deserialized to different types like declearations below:
class BaseDbConnectionConfig {
public string Type { get; set; }
}
class MysqlDbConnectionConfig : BaseDbConnectionConfig {
public string Host { get; set; }
public ushort Port { get; set; }
public string UserId { get; set; }
public string Password { get; set; }
public string Schema { get; set; }
}
class SqliteDbConnectionConfig : BaseDbConnectionConfig {
public string FilePath { get; set; }
public string Password { get; set; }
}Metadata
Metadata
Assignees
Labels
PR welcomeUser contribution/PR is welcomeUser contribution/PR is welcomeenhancementNew feature or requestNew feature or request