Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true

前提是你 提交于 2020-01-04 02:09:25

问题


I've got an extension for all entities:

 public static class EntityBaseExtensions
    {
        public static T Clone<T>(this T item)
            where T : EntityBase
        {
            return item.EntityClone<T>();
        }
    }

and

 public virtual T EntityClone<T>() where T : EntityBase
        {
            return this.MemberwiseClone() as T;
        }

but when i call it like:

 var details = user.Details.Clone();

i get

Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.

any ideas?


回答1:


the solution is kinda weird:

public static T Clone<T>(this T item)
    where T : SimpleEntityBase
{
    return (T)item.EntityClone();
}

and

public virtual object EntityClone()
{
    return this.MemberwiseClone();
}


来源:https://stackoverflow.com/questions/19117874/late-bound-operations-cannot-be-performed-on-types-or-methods-for-which-contains

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!