I have some DTOs with one parent. This parent has generic method to create any its child(uses reflection). Every of those DTOs has configuration(dictionary). I can pass the dictionary through parameters in the creating method but every child type has the same configuration so I would like to make it static and store in children. I found here: Accessing a static property of a child in a parent method that it can be a faulty design. Is it in my case? Do I have to pass the configuration through parameter or maybe store it somewhere else?
Example:
public class Parrent
{
public static T Create<T>(string[] fields, Dictionary<string, bool> config)
where T : Parrent
{
var result = Activator.CreateInstance<T>();
// filling fields using config
return result
}
}
EDIT:
Here's how does the config work:
public class Child1 : Parrent
{
public string Child1String;
public DateTime Child1DateTime;
}
public class Child2 : Parrent
{
public int Child2Int;
public string Child2String;
public TimeSpan Child2TimeSpan;
}
and the dictionary(it says which fields I can ignore (because they will be empty for example) and it's set in processing class from a config file):
- Child1:
"Child1String": true,
"Child1DateTime": true,
- Child2
"Child2Int": true,
"Child2String": false,
"Child2TimeSpan": true,