I have two classes: Role and CustomRole
public class CustomRole
{
public string RoleName { get; set; }
public int RoleId { get; set; }
}
public class Role
{
public string RoleName { get; set; }
public int RoleId { get; set; }
public int MyRole { get; set; }
}
at compile time I have a delegate like this:
Func<CustomRole, bool> Del = o => o.RoleId > 0;
The problem is at runtime I need to create one more delegate with same condition but table name is changed
Func<Role, bool> Del1 = o => o.RoleId > 0;
How can I achieve this?
You could have both Role and CustomRole implement a IRole interface that includes the RuleId property, then make your delegate use IRole.
If that is not an option, you could look into duck typing.