1: public class Repository<T> where TSource : new()
2: {
3: public void Save(T entity)
4: {
5: }
6: }
1: new Repository<Pessoa>().Save(pessoa)
1: public class Service
3: public void Save(Object entity)
4: { new Repository<???
5: Type type = entity.GetType()
6: var repository = Activator.CreateInstance(typeof (Repository<>).MakeGenericType(type));
8:
9: repository
10: .GetMethod("Save", new Type[] { type})
11: .Invoke(repository, new object[] { entity});
12: }
13: }
Fernando Lugão Veltem edited Original. Comment: alterado título para padronização e adicionado TAG
Parabéns pelo artigo Alexis.
Muito bom.