Generics C# How to pass a property of a generic object by parameter -
i have created method has problem couldn't sort out.
how can pass parameter predicate? because "x.isactive" , "source.id" , "x.id" vary, objects pass parameter have isactive , id properties.
public static differences<t> checkchanges<t>(list<t> sourcetable, list<t> destinationtable) { var differences = new differences<t>(); foreach (var sourceitem in sourcetable.where(x => x.isactive)) { var destinationitem = destinationtable.firstordefault(x => x.id == sourceitem.id); } return differences; }
if can make objects inherit common interface, easier:
public interface iaccount { int id { get; set; } bool isactive { get; set; } }
your method signature more then:
public static differences<iaccount> checkchanges(list<iaccount> sourcetable, list<iaccount> destinationtable)