Skip to content

Instantly share code, notes, and snippets.

@rstropek
Last active June 6, 2021 14:21
Show Gist options
  • Save rstropek/d65641de6e913b8de6592a756709b244 to your computer and use it in GitHub Desktop.
Save rstropek/d65641de6e913b8de6592a756709b244 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
var heroes = new List<IHero>
{
new Hero("Homelander", new(true, true)),
new Hero("Stormfront", new(true, false)),
};
// Old: if (heroes[0] is Hero { Flying: { CanFlyInSpace: true } })
if (heroes[0] is Hero { Flying.CanFlyInSpace: true })
{
Console.WriteLine("Hero can fly on earth");
}
class Flying
{
public bool CanFlyOnEarth { get; set; }
public bool CanFlyInSpace { get; set; }
public Flying(bool canFlyOnEarth, bool canFlyInSpace)
=> (CanFlyOnEarth, CanFlyInSpace) = (canFlyOnEarth, canFlyInSpace);
}
interface IHero { }
class Hero : IHero
{
public string Name;
public Flying Flying;
public Hero(string name, Flying flying)
=> (Name, Flying) = (name, flying);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment