As Matthias said, this is not possible because Field<int> and Field<string> are completely different types. What you can do is:
Create a Field base that is not shared:
public class Field { public string Name { get; set; } } public class Field<T> : Field { public T Value { get; set; } }
And then:
var customFields = new Field[] { new Field<string> { Name = "nickname", Value = "Bob" }, new Field<int> { Name = "age", Value = 42 }, new Field<DateTime> { Name = "customer_since", Value = new DateTime(2000, 12, 1) } };
As Matthias commented, getting a Value for different types will require a reduction. If there is a certain logic for each type of Value to execute, a good way to handle this would be to use the Factory design template. factory will return for each Field correct " FieldHandler<T> ", which will lower, perform the operation and return what is needed.
source share