If you need the properties in a list, I suggest you use List<object>
. Since all classes in .NET derive from the object
class, casting will be a lot more logic than casting a string to an object. Since you're using a list of objects, you don't need a class anymore to hold the properties. Also, you can use the object initializer to create the list instead of calling the Add()
method every time. The assignment of the list will look like:
List<object> properties = new List<object>
{
backgroundColor,
textColor,
timeOffset,
dateOffset,
title,
showTitle,
showText
};
And now you can pass this list to your method, like this:
YourListExpectingMethod(properties);
In the method you'll have to provide some logic to determine to which type to cast the object!
More reading: