I want the second calling style should be similar to first calling style. Please see the details in my code. Any help is really appreciated.
Here is the code I am using.
// Calling Style of First Method
var source = db.ThinkFeeds.Single(tf => tf.ID == 1);
var target = new MyProduct.UIEntities.ThinkFeed();
TypeConverter.ConvertBlToUi(source, target);
//Calling Style of Second method. Its really a weird calling style.
var source = MyProduct.UIEntities.Book.GetBookByID(1);
var target = new MyProduct.DTOEntities.Book();
TypeConverter.ConvertUiToDto<MyProduct.UIEntities.Book, MyProduct.DTOEntities.Book, Book>(source, target);
//First Method
public static void ConvertBlToUi<TBl, TUi>(TBl entitySource, TUi entityTarget)
{
}
//Second Method
public static void ConvertUiToDto<TUi, TDto, TEntity>(TUi uiEntity, TDto dtoEntity)
where TDto : DTOEntities.MyProductDTO<TEntity, TDto>
where TEntity : EntityObject
{
}
You can’t. Generic Methods, type inference:
The first style you’ve shown is using type inference, but it’s just a convenient shorthand. There are times (as here) where type inference cannot work, and so you have to supply the type parameters explicitly.