Thanks Frans. I got it.
In case if any one is interested here is the code I have come up with
public class DataProjectorToImmutableClass<T> : DataProjectorToCustomClass<T> where T : class, new()
{
private ConstructorInfo _typeConstructor;
public DataProjectorToImmutableClass(List<T> destination) : base(destination)
{
}
public ConstructorInfo TypeConstructor
{
get { return _typeConstructor; }
private set
{
if(value == null)
{
throw new ArgumentException("Failed to find a constructor on destination type with the matching projection parameters");
}
_typeConstructor = value;
}
}
protected override void AddProjectionResultToContainer(System.Collections.IList projectors, object[] rawProjectionResult)
{
T newInstance = new T();
if(TypeConstructor == null)
{
Type[] paramterTypes = new Type[projectors.Count];
int i = 0;
foreach(IProjector projector in projectors)
{
paramterTypes[i] = projector.ValueType;
i++;
}
TypeConstructor = typeof(T).GetConstructor(paramterTypes);
}
TypeConstructor.Invoke(newInstance, rawProjectionResult);
Destination.Add(newInstance);
}
}