I have multiple string[] that are defined like this:
var allEntities = new[] { "a", "b", "c", "d", "e", "f", "g", "h", "i" }
var entitiesWithPriority = new[] { "c", "d", "g" }
var entitiesWithIssue = new [] { "d", "h", "i" }
var entitiesWith... = new [] { ... }
Now I'd like to compile a single list from those arrays by using the following class structure:
class Entity {
public string Name { get; set; }
public bool HasPriority { get; set; }
public bool HasIssue { get; set; }
}
The result of the operation should therefore be something like this:
[
{ "name": "a", "hasPriority": false, "hasIssue": false }
{ "name": "b", "hasPriority": false, "hasIssue": false }
{ "name": "c", "hasPriority": true, "hasIssue": false }
{ "name": "d", "hasPriority": true, "hasIssue": true }
{ "name": "e", "hasPriority": false, "hasIssue": false }
{ "name": "f", "hasPriority": false, "hasIssue": false }
{ "name": "g", "hasPriority": true, "hasIssue": false }
{ "name": "h", "hasPriority": false, "hasIssue": true }
{ "name": "i", "hasPriority": false, "hasIssue": true }
]
I could do something in the lines of the following code, but I think this solution is not perfect at all:
var result = allEntities.Select(entityName => new Entity()
{
Name = entityName,
HasPriority = entitiesWithPriority.Contains(entityName),
HasIssue = entitiesWithIssue.Contains(entityName)
});
How can I compile such a list while being performance efficient.