I have a class that looks like this:
public class BasePadWI
{
public WorkItem WorkItemReference { get; set; }
.... Other stuff ......
}
I then have a dictionary that is defined like this:
public Dictionary<BasePadWI, Canvas> Pad { get; set; }
I would then like to make a call like this:
List<WorkItem> workItems = Pad.Keys.ToList();
(Note: WorkItem is a sealed class, so I cannot inherit.)
Is there some trickery that I could do in the class to make it look like a WorkItem?
I have done this in the meantime:
List<WorkItem> workItems = Pad.Keys.ToList().ConvertAll(x=>x.WorkItemReference );
You can override the cast operator for
This might be a little misleading since you’re not really casting BasePadWI to WorkItem, but it should let you build the lists you want quite easily.
Whenever you do do something like the following:
bpw should be implicitly converted to a WorkItem, which, due to the operator we’ve declared, returns a reference to bpw’s internal WorkItem _workItemReference.
You can also use this to, say, cast database connections to integers, so be careful that you don’t make your code too difficult to interpret by the poor schmuck who’s going to wind up maintaining this later.