Depends on what you want. Using Objects to store just about anything looks like a bad idea anyway.
If you'd work with Generics you'd have something like List<Object> which yields the same result.
What you have there seems like a '
God Method[
^]' that can do all sorts of different things dependent on its input.
One way perhaps is to have an Interface that has a Property Object and a Method DoSomething. That way you could write a Class and a specific DoSomething for each type.
I imagine an implementation would look something like this:
public interface IDoSomethingWithObj
{
object TheObject { get; set; }
void DoSomething();
}
public class DoSomethingWithString : IDoSomethingWithObj
{
object IDoSomething.TheObject { get; set; }
String MyString { get; set; }
void DoSomething() {
}
Also, possibly set the String in the Constructor (MyString isn't available in the Interface).
Now you could have a list or array of IDoSomethingWithObj.
foreach (IDoSomethingWithObj obj in myList)
{ obj.DoSomething }
I guess this is one way of handling such a situation (may not be the best, but better than having to make huge switch statements I guess).
The downside is that you cannot replace the Objects with other Objects (if you wanted to) because this is more or less 'type safe' so you'd have to make sure the new Objects type matched the old.
Another Method, if you know what you want (like always a String, int, long, bool in that order) you could use a
Tuple[
^].
The downside here is that you have no idea what Properties like 'Item1' up to 'Item8' could possible mean.
Nice question. Interested in other solutions too :)