Can I replace this code snippent with a C#8 switch expression
?
Note that if ObjectType is Computer, ObjectClass will contain "person" so ordering matters.
Also, the question is academic and I am only interested in the switch expression
and not how to solve this particular problem.
public List<string> ObjectClass { get; set; }
public ObjectType ObjectType {
get {
if (ObjectClass.Contains("group")) { return ObjectType.Group; }
if (ObjectClass.Contains("computer")) { return ObjectType.Computer; }
if (ObjectClass.Contains("person")) { return ObjectType.User; }
return ObjectType.Unknown;
}
}