# PatternMatchingExtension **Repository Path**: fuis/PatternMatchingExtension ## Basic Information - **Project Name**: PatternMatchingExtension - **Description**: A pattern matching extension for C#6 - **Primary Language**: C# - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 2 - **Created**: 2016-05-28 - **Last Updated**: 2021-09-15 ## Categories & Tags **Categories**: utils **Tags**: None ## README # PatternMatchingExtension Pattern matching extension methods for C#6 # Example ```CSharp "foo" .Match(x => Console.WriteLine($"int {x}")) .Match(x => Console.WriteLine($"string {x}")) .Match<_>(x => Console.WriteLine($"object {x}")) ; new { a = 1, b = 2 } .Match((x1, x2) => Console.WriteLine($" {x1} {x2}")) .Match((x1, x2) => Console.WriteLine($" {x1} {x2}")) ; var len = new Function, int>() .Match(list => list.IsEmpty(), self => list => 0) .Match(list => true, self => list => list.Match((x, xs) => self.Invoke(xs) + 1)) .ToFunc() ; len(new List { 1, 2, 3, 4, 5 }).Println(); var fib = new Function() .Match(x => x == 0, self => x => 0) .Match(x => x == 1, self => x => 1) .Match(x => x > 1, self => x => self.Invoke(x - 1) + self.Invoke(x - 2)) .Match(_ => true, self => _ => { throw new ArgumentOutOfRangeException(nameof(_)); }) .ToFunc() ; $"fib(10) = {fib(10)}".Println(); ```