I have an extension method :
public static List<object> ToModelViewObjectList<ModelViewType>(this IEnumerable<object> source)
{
List<ModelViewType> destinationList = new List<ModelViewType>();
PropertyInfo[] ModelViewProperties = typeof(ModelViewType).GetProperties();
foreach (var sourceElement in source)
{
object destElement = Activator.CreateInstance<ModelViewType>();
foreach (PropertyInfo sourceProperty in sourceElement.GetType().GetProperties())
{
if (ModelViewProperties.Select(m => m.Name).Contains(sourceProperty.Name))
{
destElement.GetType().GetProperty(sourceProperty.Name).SetValue(destElement, sourceProperty.GetValue(sourceElement));
}
}
destinationList.Add((ModelViewType)destElement);
}
return destinationList.Cast<object>().ToList();
}
And I have a method with a list of object that I want call extension methods in this method :
public void GridModel(IEnumerable<object> GridDataSource)
{
List<object> list = GridDataSource.ToModelViewObjectList<GridDataSource[0].GetType()>();
}
What should I write instead of GridDataSource[0].GetType() ?
Edited:
I have a method with a object parameter. I want to create a generic list of object type.
public void CreateListByNonGenericType(object myObject)
{
Type objType = myObject.GetType();
var lst = System.Collections.Generic.List < objType.MakeGenericType() > ();
}
What should I write instead of objType.MakeGenericType()
?