Guest User

Untitled

a guest
Jan 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. public interface IDataMapper<TEntity> where TEntity : IEntity
  2. {
  3. void Update(TEntity entity);
  4. }
  5.  
  6. public IDataMapper<TEntity> GetMapper<TEntity>() where TEntity : IEntity
  7. {
  8. // Return something of type IDataMapper<TEntity>
  9. }
  10.  
  11. foreach (IEntity entity in _dirtyObjects)
  12. {
  13. MethodInfo method = typeof(MapperFactory).GetMethod("GetMapper");
  14. MethodInfo generic = method.MakeGenericMethod(entity.GetType());
  15.  
  16. generic.Invoke(_mapperFactory, null);
  17. // I now want to call the Update() method
  18. // I have tried to cast to IDataMapper<IEntity> which results in a null ref ex
  19. }
  20.  
  21. object dataMapper = generic.Invoke(_mapperFactory, null);
  22. method = dataMapper.GetType().GetMethod("Update");
  23. method.Invoke(dataMapper, new object[] {entity});
Add Comment
Please, Sign In to add comment