mapperly icon indicating copy to clipboard operation
mapperly copied to clipboard

Generic factory not work if the generic member is generic it self

Open mu-dawood opened this issue 2 years ago • 0 comments

Not working

    public abstract class BaseDto<TEntity>  // this is generic
    {
        internal abstract TEntity CreateEntity();
    }

    [Mapper()]
    public partial class DtoMapper
    {

        [ObjectFactory]
        private TTarget Create<TSource, TTarget>(TSource source) where TSource : BaseDto<TTarget> //this is generic
        {
            return source.CreateEntity();
        }

    } 

Working

 public abstract class BaseDto  //this is not generic
 {
     internal abstract object CreateEntity();
 }

 [Mapper()]
 public partial class DtoMapper
 {

     [ObjectFactory]
     private TTarget Create<TSource, TTarget>(TSource source) where TSource : BaseDto //this is not generic
     {
         ....
     }

 }

mu-dawood avatar Aug 05 '23 17:08 mu-dawood