Example #1
0
        public void MatchWithEscape()
        {
            string pattern = @"http://bla.de?hiho.x={(\d+)}";
            string value   = PatternMatching.MatchEmbeddedRegex(pattern, "http://bla.de?hiho.x=438");

            Assert.AreEqual("438", value);
        }
Example #2
0
        public void NoEmbeddedRegEx()
        {
            string pattern = @"http://bla.de?hiho.x=";
            string value   = PatternMatching.MatchEmbeddedRegex(pattern, "http://bla.de?hiho.x=");

            Assert.AreEqual(null, value);
        }
Example #3
0
        async static Task Main(string[] args)
        {
            Console.WriteLine("\n=== IndicesAndRanges ===");
            IndicesAndRanges.Demo();

            Console.WriteLine("\n=== SwitchExpressions ===");
            SwitchExpressions.Demo();

            Console.WriteLine("\n=== PatternMatching ===");
            PatternMatching.Demo();

            Console.WriteLine("\n=== StaticLocalFunctions ===");
            StaticLocalFunctions.Demo();

            Console.WriteLine("\n=== UsingDeclarations ===");
            UsingDeclarations.Demo();

            Console.WriteLine("\n=== AsyncStreams ===");
            await AsyncStreams.Demo();

            Console.WriteLine("\n=== TargetTypedNew ===");
            TargetTypedNew.Demo();

            Console.WriteLine("\n=== NullCoallescingAssignment ===");
            NullCoallescingAssignment.Demo();

            Console.WriteLine("\n=== DefaultInterfaceMethods ===");
            DefaultInterfaceMethods.Demo();

            Console.WriteLine("\n=== DisposableRefStruct ===");
            DisposableRefStruct.Demo();

            Console.WriteLine("\n=== UnmanagedConstructedTypes ===");
            UnmanagedConstructedTypes.Demo();
        }
Example #4
0
        public static void PartThreeStart()
        {
            int    amount   = 50;
            string splitter = "=";

            Program.center(amount, "Start of The Third Part", "*");
            //////////////////////////////////////////////
            Program.center(amount, "Extinsions", splitter);
            Extinsions extinsions = new Extinsions();

            extinsions.StartExample();
            //////////////////////////////////////////////
            Program.center(amount, "Partial methods and classes", splitter);
            StartPartial.StartExample();
            //////////////////////////////////////////////
            Program.center(amount, "Anon types", splitter);
            AnonoimoysTypes.StartExample();
            //////////////////////////////////////////////
            Program.center(amount, "Local functions", splitter);
            LocalFunctions.StartExample();
            //////////////////////////////////////////////
            Program.center(amount, "Deconstruction for beginers", splitter);
            Deconstruction.StartExample();
            //////////////////////////////////////////////
            Program.center(amount, "Pattern matching", splitter);
            PatternMatching.StartExample();////
            //////////////////////////////////////////////
            Program.center(amount, "Nullable Types", splitter);
            NullableTypes.StartExample();
            //////////////////////////////////////////////
            Program.center(amount, "Reference vars", splitter);
            ReferenceVars.StartExample();
            //////////////////////////////////////////////
        }
Example #5
0
        public void MatchSimpleString()
        {
            string pattern = @"hiho{(\d+)}bla";
            string value   = PatternMatching.MatchEmbeddedRegex(pattern, "hiho1234bla");

            Assert.AreEqual("1234", value);
        }
Example #6
0
        public void NotMatched()
        {
            string pattern = @"http://bla.de?hiho.x={(\d+)}";
            string value   = PatternMatching.MatchEmbeddedRegex(pattern, "http://bla.de?hiho.x=bfd");

            Assert.AreEqual(null, value);
        }
Example #7
0
        public void HandlesExceptionForDefaultCase()
        {
            // Arrange
            var patternMatching = new PatternMatching();

            // Act | Assert
            Assert.Throws <ArgumentNullException>("machine", () => patternMatching.MatchingMachineProduct(null));
        }
Example #8
0
        public void ClassA_With_Name_IsMatched()
        {
            var x = new ClassA();

            x.Name = "upendra";
            var result = PatternMatching.Match(x);

            Assert.True(result == "ClassA.upendra");
        }
        public void Run()
        {
            List <Shape> shapes = new() { new Circle(), new Rectangle() };

            foreach (var shape in shapes)
            {
                PatternMatching.DisplayShape(shape);
            }
        }
Example #10
0
        public void AddTest()
        {
            int?x = 1;
            int?y = 1;
            int?z = null;

            Assert.That(PatternMatching.Add(x, y), Is.EqualTo(2));
            Assert.That(PatternMatching.Add(x, z), Is.EqualTo(1));
            Assert.That(PatternMatching.Add(z, y), Is.EqualTo(1));
            Assert.That(PatternMatching.Add(z, z), Is.EqualTo(0));
        }
Example #11
0
        static void Main(string[] args)
        {
            Console.WriteLine("RelationalPatterns");
            RelationalPatterns.Run();

            Console.WriteLine("PatternMatching");
            PatternMatching.Run();

            Console.WriteLine("PatternCombinators");
            PatternCombinators.Run();
            Console.ReadLine();
        }
Example #12
0
        public void MatchesPizzaPatternInSwitch()
        {
            // Arrange
            var      patternMatching = new PatternMatching();
            IMachine pizza           = new PizzaMachine();

            // Act
            var result = patternMatching.MatchingMachineProduct(pizza);

            // Assert
            Assert.Equal("Pizza", result);
        }
Example #13
0
        public void MatchesFishAndChipsPatternInSwitch()
        {
            // Arrange
            var      patternMatching = new PatternMatching();
            IMachine fishAndChips    = new FishAndChipsMachine();

            // Act
            var result = patternMatching.MatchingMachineProduct(fishAndChips);

            // Assert
            Assert.Equal("Fish and chips", result);
        }
Example #14
0
        public void MatchesNotInCasePatternInSwitch()
        {
            // Arrange
            var      patternMatching = new PatternMatching();
            IMachine notInCase       = new NotInCaseMachine();

            // Act
            var result = patternMatching.MatchingMachineProduct(notInCase);

            // Assert
            Assert.Equal(null, result);
        }
Example #15
0
        public override IEnumerable <MatchResult> Match(Value v, MatchContext context)
        {
            if (!(v is ExpressionValue expr))
            {
                return(new MatchResult[0]);
            }

            return(_head.Match(expr.Head, context)
                   .SelectMany(res => PatternMatching.SequenceMatch(_parts, expr.Parts, res.Context)
                               .Select(partRes => partRes.Context.WithMatch(_engine.Expr(
                                                                                _engine.PatternMatching.ToSingle(res.SequenceMatch),
                                                                                partRes.SequenceMatch
                                                                                )))));
        }
Example #16
0
        public OsmiumEngine()
        {
            _symTab         = new SymbolTable(this);
            _evaluator      = new Evaluator(this);
            PatternMatching = new PatternMatching(this);
            System          = new SystemSymbols(this);

            Context     = "Global`";
            Zero        = new IntegerValue(this, BigInteger.Zero);
            One         = new IntegerValue(this, BigInteger.One);
            MinusOne    = new IntegerValue(this, BigInteger.MinusOne);
            Null        = System.Null;
            True        = System.True;
            False       = System.False;
            ContextPath = new List <string> {
                "System`"
            };
        }
Example #17
0
        static void Main()
        {
            //0. Attributes on Properties
            AttributesOnProperties.Run();

            //1. Readonly members
            ReadonlyMembers.Run();

            //2. Default interface methods
            DefaultInterfaceMethods.Run();

            //3. Patterns matching
            PatternMatching.Run();

            //4. Using Declarations
            UsingDeclarations.Run();

            //5. Static Local Functions
            StaticLocalFunctions.Run();

            //6. Disposable ref structs
            DisposableRefStructs.Run();

            //7. Nullable Reference Types
            NullableReferenceTypes.Run();

            //8. Asynchronous streams
            AsynchronousStreams.Run();

            //9. Asynchronous disposable
            AsynchronousDisposable.Run();

            //10. Indeces And Ranges
            IndecesAndRanges.Run();

            //11. Null-coalescing assignment
            NullCoalescingAssignment.Run();

            //12. Nested Stackalloc
            NestedStackalloc.Run();

            //13. Enhancement of interpolated verbatim strings
            InterpolatedVerbatimStringsEnhancement.Run();
        }
        static void Main(string[] args)
        {
            BinaryLiteralsAndDigitSeparators binaryLiteralsAndDigitSeparators = new BinaryLiteralsAndDigitSeparators();

            binaryLiteralsAndDigitSeparators.Run();

            RefLocalsAndReturns refLocalsAndReturns = new RefLocalsAndReturns();

            refLocalsAndReturns.Run();

            Deconstruction deconstruction = new Deconstruction();

            deconstruction.Run();

            PatternMatching patternMatching = new PatternMatching();

            patternMatching.Run();

            Tuples tuples = new Tuples();

            tuples.Run();
        }
Example #19
0
        static async Task Main(string[] args)
        {
            var result = await Tupler.ProcessLanguage();


            //Review 1 Null Conditional
            var nullConditional = new NullConditional();

            nullConditional.PurchaseProduct();

            //nifty way of checking argument length
            switch (args?.Length)
            {
            case 1:
                //one arg passed in
                break;

            case 2:
                //you get the idea
                break;
            }


            //2 Interpolation
            Interpolation.InterpolateDemo();


            //3 Null conditional
            var nc = new NullConditional();

            nc.PurchaseProduct();

            //As you see fit...



            //*****************************************************
            //1. Binary Literal and digit separator
            DigitAndBinary.Process();

            //*****************************************************
            //2. Ref returns - pointer to a structure

            //Cannot use with async. Compiler can't know if ref'd variable is set before it returns
            var refReturns = new RefReturnsAndLocal();

            refReturns.TestRefs();

            //*****************************************************
            //3. Expression bodied accessors, constructors, destructor/finalizer
            // C# 6
            var zombie = new CSharp6.ExpressionBodied6.Zombie("Fred", 30);

            Console.WriteLine(zombie.ToString());

            //3a. Note C#6 collection initialization
            List <Order> orders = new List <Order>()
            {
                new Order(), new Order(), new Order()
            };
            var processor = new OrderProcessor(orders);

            //4
            //Throw expressions - allow throw in expression bodied methods
            //                        (these could be used all throughout api stubs, like reference assemblies for compilation)
            //Also allows null coalescing (single line function calls)
            try
            {
                var person = new CSharp7.Person(null);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Caught throw expression:{ex}");
            }

            //*****************************************************
            //4. Local Functions
            int[] numbers = { 3, 8, 7, 5, 2, 1, 9, 6, 4 };
            LocalFunctions.QuickSort(numbers, 0, numbers.Length - 1);
            Console.WriteLine("Sorted items");
            numbers.ToList().ForEach(o => Console.WriteLine(o));

            //Ex 2
            LocalFunctions.Fibonacci(5);


            //*****************************************************
            //5. Out vars
            OutVars.Process();

            //*****************************************************
            //6. Pattern Matching

            var pm = new PatternMatching();

            pm.MatchSomething(new Circle(3.5d));
            pm.MatchSomething(new Rectangle(2d, 4d));


            //Int
            pm.PrintStars(5);

            //String
            pm.PrintStars("5");

            //Shape
            pm.PrintStars(new Rectangle(3, 4));


            //*****************************************************
            //8. Tuples

            //Now a valuetuple - NO GC PRESSURE. Stack based!

            //Lets check it out
            //https://docs.microsoft.com/en-us/dotnet/api/?view=netframework-4.6.2&term=ValueTuple
            //https://docs.microsoft.com/en-us/dotnet/api/?view=netframework-4.5&term=System.Tuple



            //Literals - note IL is optimized
            // [130 13 - 130 53]
            // IL_01c3: ldc.i4.1
            // IL_01c4: stloc.s a
            // IL_01c6: ldc.i4.2
            // IL_01c7: stloc.s b


            var(a, b, c, c1, c2) = (1, 2, 3, 4, 5);

            //We have variables now
            var addThemUp = a + b + c;


            //Tuple compatibility with System.Tuple
            (var userName, var pass) = Tuple.Create("adam", "91281821JASJHDAHssh2#h4H#H@#Hh2h3H#H");

            //Type inference - note right hand side intellisense
            (float i, int j, int k) = (1, 2, 3);

            //named
            (int p, int q, int r)theTup = (2, 3, 4);

            theTup   = (5, 6, 7);
            theTup.p = 8;

            //adam
            var adam = ("adam", "m", "tuliper");

            //123-44-1234
            (string firstName, string middleName, string lastName)cestMoi = adam;

            //If we don't care about names

            (string, string, string)stringTuple = default((string tup1, string tup2, string tup3));

            stringTuple.Item1 = "Mary";


            //var result = task.Result;


            Console.WriteLine($"{result.keyPhrases}\r\n{result.sentiment}\r\n{result.language}");


            //named type inference
            var speedAndHealth = (health : 100, speed : 10);

            //This isn't meant to be hungarian notation :)
            (int id1, int id2, int id3)t = (2, 3, 4);
            Console.WriteLine($"{t.id1} {t.id2} {t.id3}");


            //can't convert dbl to float, and also a:1 - 'a' will be ignored
            //(int a1, float b1, int c20) conversions = (a: 1, 2d, 3);


            var item = (num : 1f, count : 2f, name : "hello", person : new Person()
            {
                Name = "Mary"
            });

            item.Item1 = item.Item2 * item.Item1;

            //Tuple.Create("item1", "item2", "item", "item", "item", "item", "item7", Tuple.Create("item 8"))
            //     .Set(out var item1, out var item2, out var item3, out var item4, out var item5, out var item6, out var item7)
            //     .Set(out var item8);



            //8b. Deconstruction
            var point = new Point(5, 4);

            var(p1, p2) = point;

            //overloaded deconstruction
            var(x1, y1, q1) = point;

            //Note can't have a single value deconstruction or tuple
            //(int aqqqq) = (5);

            //Deconstruction, I only want one item
            (int a10, _, _, _, _) = (1, 2, 3, 4, 5);
            var(x, _)             = point;

            //Equality - checks
            var(first, address) = ("1", "2");
            return;
        }
Example #20
0
        protected override JobHandle OnUpdate(JobHandle jobs)
        {
            if (viewCmdStack.Count > 0)
            {
                return(jobs);
            }

            if (patternMatchRequest.IsCreated)
            {
                unswap.Clear();
            }

            var blocksToDelete = new NativeArray <int>(100, Allocator.TempJob);
            var jobCmdBuffer   = cmdBuffer.CreateCommandBuffer().ToConcurrent();

            var swapTestJob = new SwapTest()
            {
                level               = EntityManager.GetBuffer <Level>(levelEntity),
                levelInfo           = levelInfo,
                cmdBuff             = jobCmdBuffer,
                patternMatchRequest = patternMatchRequest.ToConcurrent(),
                viewCmdStack        = viewCmdStack.ToConcurrent()
            };

            var patternMatching = new PatternMatching()
            {
                patternsBufferLookup = GetBufferFromEntity <Pattern>(isReadOnly: true),
                patternMatchRequest  = patternMatchRequest,
                patternsInfo         = patterns,
                levelBufferLookup    = GetBufferFromEntity <Level>(isReadOnly: true),
                levelInfo            = levelInfo,
                blocksToDelete       = blocksToDelete,
                unswap = unswap.ToConcurrent()
            };

            var performSwap = new PerformSwap()
            {
                level        = EntityManager.GetBuffer <Level>(levelEntity),
                levelInfo    = levelInfo,
                unswap       = unswap,
                cmdBuffer    = jobCmdBuffer,
                viewCmdStack = viewCmdStack.ToConcurrent()
            };

            var deleteBlocks = new DeleteBlock()
            {
                blocksToDelete    = blocksToDelete,
                levelBufferLookup = GetBufferFromEntity <Level>(isReadOnly: false),
                levelInfo         = levelInfo,
                cmdBuffer         = jobCmdBuffer,
                viewCmdStack      = viewCmdStack.ToConcurrent()
            };

            var moveDownBlocks = new MoveDownBlocks()
            {
                levelInfo           = levelInfo,
                levelBufferLookup   = GetBufferFromEntity <Level>(isReadOnly: false),
                viewCmdStack        = viewCmdStack.ToConcurrent(),
                patternMatchRequest = patternMatchRequest.ToConcurrent()
            };

            jobs = swapTestJob.Schedule(this, jobs);
            jobs = patternMatching.Schedule(jobs);
            jobs = performSwap.Schedule(this, jobs);
            jobs = deleteBlocks.Schedule(blocksToDelete.Length, 2, jobs);
            jobs = moveDownBlocks.Schedule(levelInfo.size.x, 2, jobs);

            return(jobs);
        }
Example #21
0
        static void Main(string[] args)
        {
            (string p1, string p2, string keyLang, string keyNum) = (null, null, "", "");
            switch (args?.Length)
            {
            case 1:
                p1 = args[0];
                break;

            case 2:
                p2 = args[1];
                goto case 1;
            }
            if (!string.IsNullOrEmpty(p1))
            {
                Console.WriteLine("Demo Language (C# X) [5=C#5, 6=C#6, 7=C#7.0, 1=C#7.1, 2=C#7.2, 3=C#7.3");
                keyLang = Console.ReadKey().KeyChar.ToString();
            }
            else
            {
                keyLang = p1;
            }
            Console.WriteLine();
            if (!string.IsNullOrEmpty(p2))
            {
                Console.WriteLine("Demo Number (1-F)");
                keyNum = Console.ReadKey().KeyChar.ToString().ToUpper();
            }
            else
            {
                keyNum = p2;
            }
            Console.WriteLine($"Call demo: {keyLang}.{keyNum}");
            switch ($"{keyLang}.{keyNum}")
            {
            case "5.1":
                Console.WriteLine("Async Await");
                break;

            case "5.2":
                Console.WriteLine("Async Load");
                break;

            case "5.3":
                Console.WriteLine("CallerInfo");
                break;

            case "6.1":
                Console.WriteLine("Auto Props");
                break;

            case "6.2":
                Console.WriteLine("Collection Initializer");
                break;

            case "6.3":
                Console.WriteLine("Dictionaries");
                break;

            case "6.4":
                Console.WriteLine("Exception Filter");
                break;

            case "6.5":
                Console.WriteLine("ExpressionBodies");
                var eb = new ExpressionBodies.Zombie("Some Name", 100);
                Console.WriteLine($"Health = {eb.Health}; Name = {eb.Name}");
                break;

            case "6.6":
                Console.WriteLine("Index Init");
                break;

            case "6.7":
                Console.WriteLine("Interpolation");
                //2 Interpolation
                Interpolation.InterpolateDemo();
                break;

            case "6.8":
                Console.WriteLine("NameOf");
                break;

            case "6.9":
                Console.WriteLine("Null Conditional");
                break;

            case "6.10":
                Console.WriteLine("Partial Interface");
                //Review 1 Null Conditional
                var nullConditional = new NullConditional();
                nullConditional.PurchaseProduct();
                break;

            case "6.11":
                Console.WriteLine("Using Static");
                break;

            case "7.0":
                Console.WriteLine("DigitAndBinary");
                //1. Binary Literal and digit separator
                DigitAndBinary.Process();
                break;

            case "7.1":
                Console.WriteLine("RefReturnAndOuts");
                //2. Ref returns - pointer to a structure
                var refReturns = new RefReturnsAndOuts();
                refReturns.TestRefs();
                break;

            case "7.2":
                Console.WriteLine("ExpressionBodied");
                //3. Expression bodied accessors, constructors, destructor/finalizer
                // C# 6
                var zombie = new CSharp6.ExpressionBodies.Zombie("Fred", 30);
                Console.WriteLine(zombie.ToString());
                break;

            case "7.3":
                Console.WriteLine("LocalFunction");
                break;

            case "7.4":
                Console.WriteLine("Local Functions");
                int[] numbers = { 3, 8, 7, 5, 2, 1, 9, 6, 4 };
                LocalFunctions.QuickSort(numbers, 0, numbers.Length - 1);
                Console.WriteLine("Sorted items");
                numbers.ToList().ForEach(o => Console.WriteLine(o));
                //Ex 2
                LocalFunctions.Fibonacci(5);
                break;

            case "7.5":
                OutVars.Process();
                break;

            case "7.6":
                Console.WriteLine("PatternMatching");
                //6. Pattern Matching
                var pm = new PatternMatching();
                pm.MatchSomething(new Circle(3.5d));
                pm.MatchSomething(new Rectangle(2d, 4d));
                //Int
                pm.PrintStars(5);
                //String
                pm.PrintStars("5");
                //Shape
                pm.PrintStars(new Rectangle(3, 4));
                break;

            case "7.7":
                Console.WriteLine("ThrowExpression");
                try
                {
                    Person p = new Person("");
                    p.Name = null; // throws an exception
                }
                catch (Exception)
                {
                    Console.WriteLine("Exception thrown");
                }
                break;

            case "7.8":
                Console.WriteLine("Tupler");
                var task = Tupler.ProcessPageRead();
                task.Wait();
                var result = task.Result;
                Console.WriteLine($"{result.url} sent {result.data.Length} bytes");
                break;

            case "7.9":
                Console.WriteLine("Deconstruct");
                break;

            case "7.A":
                Console.WriteLine("GeneralizedAsyncReturn");
                break;

            // C# 7.1
            case "1.1":
                break;

            case "1.2":
                break;

            case "1.3":
                var dil = new DiscardsInLambdas();
                dil.Run();
                break;

            case "1.4":
                break;

            case "1.5":
                break;

            case "1.6":
                var tt = new TargetTypedDefault();
                Console.WriteLine($"Ausgabe: {tt.DoSomething()}"); // 0
                break;

            case "1.7":
                var tp = new TupleProjectionInitializers();
                tp.Run();
                break;

            // C# 7.2
            case "2.1":
                Console.WriteLine("ExpressionVariablesInInit");
                break;

            case "2.2":
                Console.WriteLine("MixedNamedArguments");
                MixedNamedArguments.Execute();
                break;

            case "2.3":
                Console.WriteLine("ReferenceSemanticsIn");
                break;

            // C# 7.3
            case "3.3":
                Console.WriteLine("Tuples Equality");
                break;
            }

            Console.WriteLine();
            Console.ReadLine();
        }
Example #22
0
        private static void PatternMatching()
        {
            var patternMatching = new PatternMatching();

            patternMatching.PrintPatternMatching();
        }
Example #23
0
        //public override NodeType NodeType {
        //    get { return NodeType.Member; }
        //}
		
		protected bool MatchMember(MemberDeclaration o, PatternMatching.Match match)
		{
			return MatchAttributesAndModifiers(o, match) && this.ReturnType.DoMatch(o.ReturnType, match)
				&& this.PrivateImplementationType.DoMatch(o.PrivateImplementationType, match) && MatchString(this.Name, o.Name);
		}
Example #24
0
		protected bool MatchAttributesAndModifiers (AttributedNode o, PatternMatching.Match match)
		{
			return (this.Modifiers == Modifiers.Any || this.Modifiers == o.Modifiers) && this.Attributes.DoMatch (o.Attributes, match);
		}
Example #25
0
 protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
 {
     CSharpModifierToken o = other as CSharpModifierToken;
     return o != null && this.modifier == o.modifier;
 }
Example #26
0
        public void RegExMatchingTests(string s, string p, bool result)
        {
            var pm = new PatternMatching();

            Assert.Equal(result, pm.IsMatch(s, p));
        }
Example #27
0
 public bool IsMatch(Value pattern, Value what)
 {
     return(PatternMatching.IsMatch(pattern, what));
 }
Example #28
0
 public void Null_IsMatched()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           PatternMatching.Match(null));
 }
Example #29
0
        public static void Main(string[] args)
        {
            int option    = 1;
            int i_option  = 1;
            int ii_option = 1;

            // YO AMO A MI ESPOSA :) LE VOY A COMPRAR MUCHOS REGALOS :)

            while (option != 0)
            {
                ConsoleUtility.WriteLine("Choose an option based in the next menu");
                ConsoleUtility.WriteLine("1.-Algorithm");
                ConsoleUtility.WriteLine("2.-DataStructures");
                ConsoleUtility.WriteLine("3.-Design Patterns");
                ConsoleUtility.WriteLine("4.-Language DotNet");
                option = Convert.ToInt32(Console.ReadLine());
                switch (option)
                {
                case 1:
                    ConsoleUtility.WriteLine("Algorithm");
                    ConsoleUtility.WriteLine("1.-Linear Table");
                    ConsoleUtility.WriteLine("2.-Linear Table Append");
                    ConsoleUtility.WriteLine("3.-Linear Table Delete");
                    ConsoleUtility.WriteLine("4.-Linear Table Insert");
                    ConsoleUtility.WriteLine("5.-Linear Table Search");
                    ConsoleUtility.WriteLine("6.-Factorial");
                    ConsoleUtility.WriteLine("7.-Bubble Sort");
                    ConsoleUtility.WriteLine("8.-Heap Sort");
                    ConsoleUtility.WriteLine("9.-Insert Sorting");
                    ConsoleUtility.WriteLine("10.-Merge Sort");
                    ConsoleUtility.WriteLine("11.-Quick Sort");
                    ConsoleUtility.WriteLine("12.-Select Sort");
                    ConsoleUtility.WriteLine("13.-Binary Search");
                    ConsoleUtility.WriteLine("14.-Fibonnacci");
                    ConsoleUtility.WriteLine("15.-Fibonacci with Memoization");
                    i_option = Convert.ToInt32(Console.ReadLine());
                    switch (i_option)
                    {
                    case 1:
                        ConsoleUtility.WriteLine("Running example of Linear Table");
                        LinearTable linearTable = new LinearTable();
                        linearTable.Run();
                        break;

                    case 2:
                        ConsoleUtility.WriteLine("Running example of Linear Table Append");
                        LinearTableAppend linearTableAppend = new LinearTableAppend();
                        linearTableAppend.Run();
                        break;

                    case 3:
                        ConsoleUtility.WriteLine("Running example of Linear Table Delete");
                        LinearTableDelete linearTableDelete = new LinearTableDelete();
                        linearTableDelete.Run();
                        break;

                    case 4:
                        ConsoleUtility.WriteLine("Running example of Linear Table Insert");
                        LinearTableInsert linearTableInsert = new LinearTableInsert();
                        linearTableInsert.Run();
                        break;

                    case 5:
                        ConsoleUtility.WriteLine("Running example of Linear Table Search");
                        LinearTableSearch linearTableSearch = new LinearTableSearch();
                        linearTableSearch.Run();
                        break;

                    case 6:
                        ConsoleUtility.WriteLine("Running example of Factorial");
                        Factorial factorial = new Factorial();
                        factorial.Run();
                        break;

                    case 7:
                        ConsoleUtility.WriteLine("Running example of Bubble Sort");
                        BubbleSort bubbleSort = new BubbleSort();
                        bubbleSort.Run();
                        break;

                    case 8:
                        ConsoleUtility.WriteLine("Running example of HeapSort");
                        HeapSort heapSort = new HeapSort();
                        heapSort.Run();
                        break;

                    case 9:
                        ConsoleUtility.WriteLine("Running example of InsertSorting");
                        InsertSorting insertSorting = new InsertSorting();
                        insertSorting.Run();
                        break;

                    case 10:
                        ConsoleUtility.WriteLine("Running example of Merge Sort");
                        MergeSort mergeSort = new MergeSort();
                        mergeSort.Run();
                        break;

                    case 11:
                        ConsoleUtility.WriteLine("Running example pf Quick Sort");
                        QuickSort quickSort = new QuickSort();
                        quickSort.Run();
                        break;

                    case 12:
                        ConsoleUtility.WriteLine("Running example of Select Sort");
                        SelectSort selectSort = new SelectSort();
                        selectSort.Run();
                        break;

                    case 13:
                        ConsoleUtility.WriteLine("Running example of Binary Search");
                        BinarySearch binarySearch = new BinarySearch();
                        binarySearch.Run();
                        break;

                    case 14:
                        ConsoleUtility.WriteLine("Running example of Fibonnacci");
                        Fibonnacci fibonnacci = new Fibonnacci();
                        fibonnacci.Run();
                        break;

                    case 15:
                        ConsoleUtility.WriteLine("Running example of Fibonnaci with Memoization");
                        FibonacciMemoization fibonacciMemoization = new FibonacciMemoization();
                        fibonacciMemoization.Run();
                        break;

                    default:
                        break;
                    }
                    break;

                case 2:
                    ConsoleUtility.WriteLine("Data Structures");
                    ConsoleUtility.WriteLine("1.-Binary Search Tree");
                    ConsoleUtility.WriteLine("2.-Binary Tree");
                    ConsoleUtility.WriteLine("3.-Doubly Linked List");
                    ConsoleUtility.WriteLine("4.-Double Linked List");
                    ConsoleUtility.WriteLine("5.-Hash Table");
                    ConsoleUtility.WriteLine("6.-Linked List");
                    ConsoleUtility.WriteLine("7.-One Way Circular List");
                    ConsoleUtility.WriteLine("8.-Queue");
                    ConsoleUtility.WriteLine("9.-Stack");
                    ConsoleUtility.WriteLine("10.-Two Way Circular List");
                    ConsoleUtility.WriteLine("11.-Unidirectional Linked List");
                    i_option = Convert.ToInt32(Console.ReadLine());
                    ConsoleUtility.WriteLine($"you choose option {i_option}");
                    switch (i_option)
                    {
                    case 1:
                        ConsoleUtility.WriteLine("Running example of Binary Search Tree");
                        BinarySearchTree binarySearchTree = new BinarySearchTree();
                        binarySearchTree.Run();
                        break;

                    case 2:
                        ConsoleUtility.WriteLine("Running example of Binary Tree");
                        BinaryTree binaryTree = new BinaryTree();
                        binaryTree.Run();
                        break;

                    case 3:
                        ConsoleUtility.WriteLine("Running example of DoublyLinkedList");
                        DoublyLinkedList doublyLinkedList = new DoublyLinkedList();
                        doublyLinkedList.Run();
                        break;

                    case 4:
                        ConsoleUtility.WriteLine("Running example of DoubleLinkedList");
                        DoubleLinkedList doubleLinkedList = new DoubleLinkedList();
                        doubleLinkedList.Run();
                        break;

                    case 5:
                        ConsoleUtility.WriteLine("Running example of HashTable");
                        HashTable hashTable = new HashTable();
                        hashTable.Run();
                        break;

                    case 6:
                        ConsoleUtility.WriteLine("Running example of Linked List");
                        LinkedList <int> linkedList = new LinkedList <int>();
                        linkedList.Run();
                        break;

                    case 7:
                        ConsoleUtility.WriteLine("Running example of One Way Circular List");
                        OneWayCircularList circularList = new OneWayCircularList();
                        circularList.Run();
                        break;

                    case 8:
                        ConsoleUtility.WriteLine("Running example of Queue");
                        Queue queue = new Queue();
                        queue.Run();
                        break;

                    case 9:
                        ConsoleUtility.WriteLine("Running example of Stack");
                        Stack stack = new Stack();
                        stack.Run();
                        break;

                    case 10:
                        ConsoleUtility.WriteLine("Running example of Two Way Circular List");
                        TwoWayCircularList twoWay = new TwoWayCircularList();
                        twoWay.Run();
                        break;

                    case 11:
                        ConsoleUtility.WriteLine("Running example fo Unidirectional Linked List");
                        UnidirectionalLinkedList unidirectionalLinkedList = new UnidirectionalLinkedList();
                        unidirectionalLinkedList.Run();
                        break;

                    default:
                        break;
                    }
                    break;

                case 3:
                    ConsoleUtility.WriteLine("Design Patterns");
                    ConsoleUtility.WriteLine("1.-Creational");
                    ConsoleUtility.WriteLine("2.-Structural");
                    ConsoleUtility.WriteLine("3.-Behavioral");
                    ConsoleUtility.WriteLine("4.-SOLID Principles");

                    i_option = Convert.ToInt32(Console.ReadLine());
                    ConsoleUtility.WriteLine($"you choose option {i_option}");
                    switch (i_option)
                    {
                    case 1:
                        ConsoleUtility.WriteLine("Example of creational design patterns");
                        ConsoleUtility.WriteLine("1.-Singleton");
                        ConsoleUtility.WriteLine("2.-Factory");
                        ConsoleUtility.WriteLine("3.-Builder");
                        ConsoleUtility.WriteLine("4.-Prototype");
                        ConsoleUtility.WriteLine("5.-Fluent Interface");
                        ConsoleUtility.WriteLine("6.-Factory Method");
                        ConsoleUtility.WriteLine("7.-Abstract Factory");
                        ConsoleUtility.WriteLine("Select one option");
                        ii_option = Convert.ToInt32(Console.ReadLine());
                        switch (ii_option)
                        {
                        case 1:
                            ConsoleUtility.WriteLine("Running example of singleton design pattern");
                            SingletonTest singletonTest = new SingletonTest();
                            singletonTest.Run();
                            break;

                        case 2:
                            ConsoleUtility.WriteLine("Runnig example of Factory design pattern");
                            FactoryTest factoryTest = new FactoryTest();
                            factoryTest.Run();
                            break;

                        case 3:
                            ConsoleUtility.WriteLine("Running example fo Builder Desiogn Pattern");
                            BuilderTest builderTest = new BuilderTest();
                            builderTest.Run();
                            break;

                        case 4:
                            ConsoleUtility.WriteLine("Running example of Prototype Design Pattern");
                            PrototypeTest prototype = new PrototypeTest();
                            prototype.Run();
                            break;

                        case 5:
                            ConsoleUtility.WriteLine("Running example of Fluent Interface Design Patter");
                            FluentInterface fluent = new FluentInterface();
                            fluent.Run();
                            break;

                        case 6:
                            ConsoleUtility.WriteLine("Running example of Factory Method Design Pattern");
                            FactoryMethodTest factory = new FactoryMethodTest();
                            factory.Run();
                            break;

                        case 7:
                            ConsoleUtility.WriteLine("Running example of Abstract Factory");
                            AbstractFactoryTest abstractFactory = new AbstractFactoryTest();
                            abstractFactory.Run();
                            break;

                        default:
                            break;
                        }
                        break;

                    case 2:
                        ConsoleUtility.WriteLine("Example of Structural Design Pattern");
                        ConsoleUtility.WriteLine("1.-Adapter");
                        ConsoleUtility.WriteLine("2.-Facade");
                        ConsoleUtility.WriteLine("3.-Decorator");
                        ConsoleUtility.WriteLine("4.-Composite");
                        ConsoleUtility.WriteLine("5.-Proxy");
                        ConsoleUtility.WriteLine("6.-Flyweight");
                        ConsoleUtility.WriteLine("7.-Bridge");
                        ii_option = Convert.ToInt32(Console.ReadLine());
                        switch (ii_option)
                        {
                        case 1:
                            ConsoleUtility.WriteLine("Running example of Adapter");
                            AdapterTest adapter = new AdapterTest();
                            adapter.Run();
                            break;

                        case 2:
                            ConsoleUtility.WriteLine("Running example of Facade");
                            FacadeTest facade = new FacadeTest();
                            facade.Run();
                            break;

                        case 3:
                            ConsoleUtility.WriteLine("Running example of Decorator");
                            DecoratorTest decorator = new DecoratorTest();
                            decorator.Run();
                            break;

                        case 4:
                            ConsoleUtility.WriteLine("Running example of Composite");
                            CompositeTest composite = new CompositeTest();
                            composite.Run();
                            break;

                        case 5:
                            ConsoleUtility.WriteLine("Running example of Proxy");
                            ProxyTest proxy = new ProxyTest();
                            proxy.Run();
                            break;

                        case 6:
                            ConsoleUtility.WriteLine("Running example of Flyweight");
                            FlyweightTest flyweight = new FlyweightTest();
                            flyweight.Run();
                            break;

                        case 7:
                            ConsoleUtility.WriteLine("Running example of Bridge");
                            BridgeTest bridge = new BridgeTest();
                            bridge.Run();
                            break;

                        default:
                            break;
                        }
                        break;

                    case 3:
                        ConsoleUtility.WriteLine("Example of Behavioral Design Pattern");
                        ConsoleUtility.WriteLine("1.-Chain of Responsability");
                        ConsoleUtility.WriteLine("2.-Command");
                        ConsoleUtility.WriteLine("3.-Observer");
                        ConsoleUtility.WriteLine("4.-Iterator");
                        ConsoleUtility.WriteLine("5.-State");
                        ConsoleUtility.WriteLine("6.-Template Method");
                        ConsoleUtility.WriteLine("7.-Visitor");
                        ConsoleUtility.WriteLine("8.-Strategy");
                        ConsoleUtility.WriteLine("9.-Mediator");
                        ConsoleUtility.WriteLine("10.-Memento");
                        ConsoleUtility.WriteLine("11.-Interpreter");
                        ii_option = Convert.ToInt32(Console.ReadLine());
                        switch (ii_option)
                        {
                        case 1:
                            ConsoleUtility.WriteLine("Running example of Change Of Responsability");
                            ChainOfResponsability chain = new ChainOfResponsability();
                            chain.Run();
                            break;

                        case 2:
                            ConsoleUtility.WriteLine("Running example of Command");
                            CommandTest command = new CommandTest();
                            command.Run();
                            break;

                        case 3:
                            ConsoleUtility.WriteLine("Running example of Observer");
                            ObserverTest observer = new ObserverTest();
                            observer.Run();
                            break;

                        case 4:
                            ConsoleUtility.WriteLine("Running example of Iterator");
                            IteratorTest iterator = new IteratorTest();
                            iterator.Run();
                            break;

                        case 5:
                            ConsoleUtility.WriteLine("Running example of State");
                            StateTest state = new StateTest();
                            state.Run();
                            break;

                        case 6:
                            ConsoleUtility.WriteLine("Running example of Template Method");
                            TemplateMehodTest templateMehod = new TemplateMehodTest();
                            templateMehod.Run();
                            break;

                        case 7:
                            ConsoleUtility.WriteLine("Running example of Visitor");
                            VisitorTest visitor = new VisitorTest();
                            visitor.Run();
                            break;

                        case 8:
                            ConsoleUtility.WriteLine("Running example of stratgegy");
                            StrategyTest strategy = new StrategyTest();
                            strategy.Run();
                            break;

                        case 9:
                            ConsoleUtility.WriteLine("Running example of Mediator");
                            MediatorTest mediator = new MediatorTest();
                            mediator.Run();
                            break;

                        case 10:
                            ConsoleUtility.WriteLine("Running example of Memento");
                            MementoTest memento = new MementoTest();
                            memento.Run();
                            break;

                        case 11:
                            ConsoleUtility.WriteLine("Running example of Interpreter");
                            InterpreterTest interpreter = new InterpreterTest();
                            interpreter.Run();
                            break;

                        default:
                            break;
                        }
                        break;

                    case 4:
                        ConsoleUtility.WriteLine("Example of SOLID Principles");
                        ConsoleUtility.WriteLine("1.-Single Responsibility Principle");
                        ConsoleUtility.WriteLine("2.-Open-Closed Principle");
                        ConsoleUtility.WriteLine("3.-Liskov Substitution Principle");
                        ConsoleUtility.WriteLine("4.-Interface Segregation Principle");
                        ConsoleUtility.WriteLine("5.-Dependency Inversion Principle");
                        ii_option = Convert.ToInt32(Console.ReadLine());
                        switch (ii_option)
                        {
                        case 1:
                            ConsoleUtility.WriteLine("Running example of Single Responsibility");
                            Invoice invoice = new Invoice();
                            invoice.Run();
                            break;

                        case 2:
                            ConsoleUtility.WriteLine("Running example of Open-Closed Principle");
                            InvoiceOCP invoiceOCP = new InvoiceOCP();
                            invoiceOCP.Run();
                            break;

                        case 3:
                            ConsoleUtility.WriteLine("Running example of Liskov Principle");
                            RunFruit run = new RunFruit();
                            run.Run();
                            break;

                        case 4:
                            ConsoleUtility.WriteLine("Running example of Interface Segregation Principle");
                            Printer printer = new Printer();
                            printer.Run();
                            break;

                        case 5:
                            ConsoleUtility.WriteLine("Running example of Dependency Inversion Principle");
                            RunDIP runDIP = new RunDIP();
                            runDIP.Run();
                            break;
                        }
                        break;

                    default:
                        break;
                    }
                    break;

                case 4:
                    ConsoleUtility.WriteLine("Language DotNet");
                    ConsoleUtility.WriteLine("1.-Abstract");
                    ConsoleUtility.WriteLine("2.-Action");
                    ConsoleUtility.WriteLine("3.-AsyncAwait");
                    ConsoleUtility.WriteLine("4.-Delegate");
                    ConsoleUtility.WriteLine("5.-Extensions");
                    ConsoleUtility.WriteLine("6.-Func");
                    ConsoleUtility.WriteLine("7.-Generics");
                    ConsoleUtility.WriteLine("8.-Predicate");
                    ConsoleUtility.WriteLine("9.-Lock");
                    ConsoleUtility.WriteLine("10.-Reflection");
                    ConsoleUtility.WriteLine("11.-IOC Implementation");
                    ConsoleUtility.WriteLine("12.-Task");
                    ConsoleUtility.WriteLine("13.-Out Variable");
                    ConsoleUtility.WriteLine("14.-Pattern Matching");
                    ConsoleUtility.WriteLine("15.-Digit Separator");
                    ConsoleUtility.WriteLine("16.-Tuples");
                    ConsoleUtility.WriteLine("17.-Ref locals and ref return");
                    ConsoleUtility.WriteLine("18.-AsynReturn");
                    i_option = Convert.ToInt32(Console.ReadLine());
                    switch (i_option)
                    {
                    case 1:
                        ConsoleUtility.WriteLine("Running example of Abstract Class");
                        Square square = new Square();
                        square.Run();
                        break;

                    case 2:
                        ConsoleUtility.WriteLine("Running example of Action");
                        LanguageDotNet.Action action = new LanguageDotNet.Action();
                        action.Run();
                        break;

                    case 3:
                        ConsoleUtility.WriteLine("Running example of AsyncAwait");
                        AsyncAwait asyncAwait = new AsyncAwait();
                        asyncAwait.Run();
                        break;

                    case 4:
                        ConsoleUtility.WriteLine("Running example of Delegate");
                        Number number = new Number();
                        number.Run();
                        break;

                    case 5:
                        ConsoleUtility.WriteLine("Running example of Extensions");
                        IntExtensions intExtensions = new IntExtensions();
                        intExtensions.Run();
                        break;

                    case 6:
                        ConsoleUtility.WriteLine("Running example of Func");
                        Func func = new Func();
                        func.Run();
                        break;

                    case 7:
                        ConsoleUtility.WriteLine("Running example of Generics");
                        Generic generic = new Generic();
                        generic.Run();
                        break;

                    case 8:
                        ConsoleUtility.WriteLine("Running example of Predicate");
                        Predicate predicate = new Predicate();
                        predicate.Run();
                        break;

                    case 9:
                        ConsoleUtility.WriteLine("Running example of Lock");
                        LockTest lockTest = new LockTest();
                        lockTest.runTest();
                        break;

                    case 10:
                        ConsoleUtility.WriteLine("Running example of Reflection");
                        Customer customer = new Customer();
                        customer.Run();
                        break;

                    case 11:
                        ConsoleUtility.WriteLine("Running example of IOC Implementation");
                        IOCImplementation.Run();
                        break;

                    case 12:
                        ConsoleUtility.WriteLine("Running example of Tasks");
                        TaskReturnValue taskReturnValue = new TaskReturnValue();
                        taskReturnValue.Run();
                        break;

                    case 13:
                        ConsoleUtility.WriteLine("Running example of Out variable");
                        OutVariables outVariables = new OutVariables();
                        outVariables.Run();
                        break;

                    case 14:
                        ConsoleUtility.WriteLine("Running example of Pattern Matching");
                        PatternMatching patternMatching = new PatternMatching();
                        patternMatching.Run();
                        break;

                    case 15:
                        ConsoleUtility.WriteLine("Running example of Digit Separators");
                        DigitSeparator digitSeparator = new DigitSeparator();
                        digitSeparator.Run();
                        break;

                    case 16:
                        ConsoleUtility.WriteLine("Running example of Tuple");
                        Tuples tuples = new Tuples();
                        tuples.Run();
                        break;

                    case 17:
                        ConsoleUtility.WriteLine("Running example of Ref locals and ref returns");
                        RefLocalRefReturn refLocalRefReturn = new RefLocalRefReturn();
                        refLocalRefReturn.Run();
                        break;

                    case 18:
                        ConsoleUtility.WriteLine("Running example of AsyncReturn");
                        AsyncReturn asyncReturn = new AsyncReturn();
                        asyncReturn.Run();
                        break;

                    default:
                        break;
                    }
                    break;

                default:
                    ConsoleUtility.WriteLine("Exit");
                    break;
                }
            }
        }
		public virtual void VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern)
		{
			VisitChildren (placeholder);
		}
Example #31
0
 public void Invalid_Argument_IsMatched()
 {
     Assert.Throws <ArgumentException>(() =>
                                       PatternMatching.Match(100));
 }
Example #32
0
		public void VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern)
		{
			StartNode(placeholder);
			VisitNodeInPattern(pattern);
			EndNode(placeholder);
		}
Example #33
0
 public void TestOldTypePattern()
 {
     Assert.AreEqual(PatternMatching.TypePatternOld(Rectangle), 20);
     Assert.Throws <ArgumentException>(() => PatternMatching.TypePatternOld(Square));
 }