Skip to content

Instantly share code, notes, and snippets.

Created October 11, 2021 15:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Extended properties example
<Project Sdk="Microsoft.NET.Sdk">
List<Status> statuses = new()
new(Category.Normal, new(20, false, 20)),
new(Category.Warning, new(20, false, 60)),
new(Category.Danger, new(20, true, 60)),
new(Category.Danger, new(100, false, 20))
foreach (Status status in statuses)
string message = status switch
{Category: Category.Normal} => "Let the good times roll",
{Category: Category.Warning, Reading.PM25: >50 and <100} => "Check the air filters",
{Reading.PM25: >200 } => "There must be a fire somewhere. Don't go outside.",
{Reading.SmokeDetected: true } => "We have a fire!",
{Category: Category.Danger} => "Something is badly wrong",
_ => "Unknown status"
record struct Reading(int Temperature, bool SmokeDetected, int PM25);
record struct Status(Category Category, Reading Reading);
enum Category
Copy link

richlander commented Oct 11, 2021

Produces the following output:

Let the good time roll
Check the air filters
We have a fire!
Something is badly wrong


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment