You can cast your object first to IEnumerable
, then convert to list.
public List<object> convertObjectBackToList(object Input)
{
if(Input is IEnumerable)
return ((IEnumerable)Input).Cast<Object>().ToList();
return new List<Object>() { Input };
}
EDIT
A generic extension method would even be better
public static partial class SOExtensions
{
public static List<T> ToList2<T>(this object Input)
{
if (Input is IEnumerable)
return ((IEnumerable)Input).Cast<T>().ToList();
return new List<T>() { (T)Input };
}
}
Then you could use it as
var list1 = someObject.ToList2<SomeType>();