I have a class ApprovalTicket that has a property called ApprovalRules that is of type IApproval:
IApproval ApprovalRules;
This field will contain several different types of classes that implement that interface. Now stepping one level up, I will have a List of ApprovalTickets. What I’m trying to do is use linq to return a list of ApprovalTickets that have ApprovalRules of the type MocReviewerApproval.
I was trying something like:
var reviews = request.MocApprovalTasks
.Where(mocApproval => mocApproval.ApprovalRules is MocReviewerApproval)
.ToList();
But when I check the list that gets returned, it’s still including tickets that have an ApprovalRules type of MocManagerApproval and others as well. What am I missing?
UPDATE:
Let me be more specific. Here is the inheritance scheme
MocApproval : TaskTicket
>>IApproval ApprovalRules;
MocReviewerApproval : IApproval
MocManagerApproval : IApproval
MocControllerApproval : IApproval
internal interface IApproval
{
bool Approve(Guid approverGuid, MocApproval approval);
bool Deny(Guid approverGuid, MocApproval approval, TaskComment denialComment);
bool Close(Guid approverGuid, MocApproval approval, TaskComment closeComment);
bool Notify();
void Set(MocApproval approval);
User GetAssignee();
TaskComment GetNotificationComment();
}
Your code looks fine to me. I suspect you’ve got diagnostic problems, or you’re not after the
iskind of relationship at all. Here’s a complete example showing it working:EDIT: If you want matches which are exactly the given type, use:
That’s more refactoring-friendly than finding the name as per Servy’s original answer.