c# - Determine datatype parameter for generic used in interface -
i struggling find elegant solution in determining data type in interface used generic parameter in abstract class.
abstract class:
public abstract class entity<t> { /// <summary> /// object identifier /// </summary> public t id { get; set; } }
concrete class:
public class department: entity<int> { // additional properties } public class employee: entity<long> { // additional properties }
interface implementation:
public interface iservice<t1, t2> t1 : entity<?> t2 : entity<?> { task transferemployeetodepartment(? departmentid, ? employeeid); }
a solution problem send data type additional parameter personal , ocd reasons prefer not so. there way solve this?
agree dennis comment. according method name transfer concrete class employee
concrete class department
. there nothing generic here.
if want transfer these 2 entities code should this
public class department: entity<int> { // additional properties } public class employee: entity<long> { // additional properties public department transfertodepartment() {} //implementation here }
if goal transfer entity entity remake yout interface following way
public interface iservice<t1, t2> { task transferemployeetodepartment(entity<t1> entityfrom, entity<t2> entityto); }
but if set of unrelated entities (like department , employee) doubt possible write generic code this
Comments
Post a Comment