Rick G. Garibay

I am building a generic data mapper factory and would like any feedback on the following snippet which would represent the mapper factory.

In the code below, MyEntity is a custom entity that is hyrdated by the MyEntityMapper which implements IDataMapper<T> (constructing T as MyEntity in the implementation). The client would call the method as follows:

IDataMapper<MyEntity> mapper;

mapper = DataMapper.GetMapper<MyEntity>();

MyEntity entity = mapper.FindSingle<int>(5);

Specifically, I am interested in any concerns around the way I determine the type of T, and, if the resulting API could be any cleaner or more efficient:

public static IDataMapper<T> GetMapper<T>() where T: new()


     T m_type = new T();

     if (m_type is MyEntity)


            IDataMapper<MyEntity> map = new MyEntityMapper();

            return (IDataMapper<T>) map;


     return (IDataMapper<T>) null;


Many thanks.


Re: Visual C# General Feedback on Generics Prototype

Figo Fei - MSFT

Hi, Rick

If you could explain the purpose of your code and what the MyEntity is, we can give comments on your code.

Thank you

Re: Visual C# General Feedback on Generics Prototype

Ernst Kuschke

You obviously want your API to be as intuitive as possible, and the 1st two lines seem pretty good to me.

What though does FindSingle do exactly The fact that I'm asking might mean that it isn't as intuitive as you want