Let's say that I have a class called car like this:
public class Car
{
public int Id { get; set; }
public State State { get; set; }
}
public abstract record State(DateTime UpdatedAt)
{
protected State() : this(DateTime.UtcNow)
{
}
}
public record New : State;
public record Damaged(int DamagedParts, string Description) : State;
and I fetched a list of cars with state damaged from database. It is a IReadOnlyCollection. How can I easily get properties of DamagedState (damaged parts and description) without iterating through the list? Can I use pattern matching for this?
Amount of fetched Cars can be up to 50k.