Skip to content

Instantly share code, notes, and snippets.

@ReedCopsey
Created August 31, 2017 18:37
Show Gist options
  • Save ReedCopsey/1bf665bb1f8c90d9ac746d5b64dcdf83 to your computer and use it in GitHub Desktop.
Save ReedCopsey/1bf665bb1f8c90d9ac746d5b64dcdf83 to your computer and use it in GitHub Desktop.
Linqpad C# Program
void Main()
{
IMsg test = new S2("foo", "bar");
switch (test)
{
// How do I simplify this??? I'd like to "match and deconstruct" as a oneliner if possible
case S1 s1:
{
int foo = s1.Data;
Console.WriteLine($"Values are: {foo}");
}
break;
case S2 s2:
{
(string foo, string bar) = s2.Data;
Console.WriteLine($"Values are {foo} and {bar}");
}
break;
}
}
// Define other methods and classes here
interface IMsg { }
abstract class DataHolder<T>
{
public T Data { get; }
protected DataHolder(T item)
{
this.Data = item;
}
}
class S1 : DataHolder<int>, IMsg
{
public S1(int Foo) : base(Foo) { }
}
class S2 : DataHolder<(string Foo, string Bar)>, IMsg
{
public S2(string Foo, string Bar) : base((Foo, Bar)) { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment