Platform: C# 2.0 WinForms
I have a factory class that provides an instantiation of a particular data mapper depending on the type that I send it, the code is as such:
public static IDataMapper<T> GetMapper<T>() where T: IDto
{
Type mapperType = MapperLocator.GetMapper(typeof(T));
return (IDataMapper<T>)mapperType.Assembly.CreateInstance(mapperType.FullName);
}
I am using DynamicProxy2 to intercept method calls to my DTO objects. In my intercept method I am trying to call the above factory using the type from Invocation.TargetType. However this comes back with the exception:
The type or namespace name 'invocation' could not be found.
Obviously this is because any calls to a generic method need to know the type explicitly from what I understand at compile time. Obviously I can't do that in this case and I definitely am not going to do a switch statement across all of my DTO objects.
So, can you guys suggest a strategy or point out what I am doing wrong? I am trying to make this as generic as possible so that it could fit across all of my objects and any new ones as well as code portability to other projects.
Thanks in advance!