but input.getType().GetGenericArguments()[0] says it is object type...
Well, as List<T>
is invariant, the generic argument of the list passed in will always match the generic argument of the method parameter, exactly.
In this case, the list will always be a list of object
s.
Now, each item in the list may not be an object
(as it's most derived type), it could be a string, or a PSObject
. However you can't assume that all of them are any type other than object
.
So you could check if there is a more derived type for a particular item in the list, but not of the list as a whole.
So it's more likely that you'll have to refactor the code to do:
Boolean actions(List<Object> input)
{
foreach(object element in input)
{
if (element is String)
{...}
else if (element is PSObject)
{...}
}
}
If it's important for all of the items to be of the same type then you can use generics:
Boolean actions<T>(List<T> input)
{
if (typeof(T) == typeof(string))
{...}
if(typeof(T) == typeof(PSObject))
{...}
}