Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IDataMapper<TEntity> where TEntity : IEntity
- {
- void Update(TEntity entity);
- }
- public IDataMapper<TEntity> GetMapper<TEntity>() where TEntity : IEntity
- {
- // Return something of type IDataMapper<TEntity>
- }
- foreach (IEntity entity in _dirtyObjects)
- {
- MethodInfo method = typeof(MapperFactory).GetMethod("GetMapper");
- MethodInfo generic = method.MakeGenericMethod(entity.GetType());
- generic.Invoke(_mapperFactory, null);
- // I now want to call the Update() method
- // I have tried to cast to IDataMapper<IEntity> which results in a null ref ex
- }
- object dataMapper = generic.Invoke(_mapperFactory, null);
- method = dataMapper.GetType().GetMethod("Update");
- method.Invoke(dataMapper, new object[] {entity});
Add Comment
Please, Sign In to add comment