Last active
June 18, 2020 15:40
-
-
Save abdusco/d2a618323e6d87b34fd83a0d42d57a0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Linq.Dynamic.Core; | |
| namespace LinqDemo.Cli | |
| { | |
| class Person | |
| { | |
| public string Name { get; set; } | |
| } | |
| class Program | |
| { | |
| private static IQueryable<Person> People = new List<Person> | |
| { | |
| new Person {Name = "ali"}, | |
| new Person {Name = "veli"}, | |
| new Person {Name = "ahmet"}, | |
| }.AsQueryable(); | |
| static void Main(string[] args) | |
| { | |
| FilterWithArray(new[] {"veli", "ali"}); | |
| FilterWithDict(new[] {"veli", "ali"}); | |
| } | |
| private static void FilterWithDict(string[] values) | |
| { | |
| Console.WriteLine("filtering with dict"); | |
| var data = new Dictionary<string, object> | |
| { | |
| {"@values", values} | |
| }; | |
| var filtered = People | |
| .Where("@values.Contains(name)", data) | |
| .ToList(); | |
| foreach (var person in filtered) | |
| { | |
| Console.WriteLine($"filtered: {person.Name}"); | |
| } | |
| } | |
| private static void FilterWithArray(string[] values) | |
| { | |
| Console.WriteLine("filtering with array"); | |
| var filtered = People | |
| .Where(@"@0.Contains(name)", values, null) | |
| .ToList(); | |
| foreach (var person in filtered) | |
| { | |
| Console.WriteLine($"filtered: {person.Name}"); | |
| } | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
array verdiginde bir parametre daha verip (null) variadic arguman olarak anlamasini engellemek gerek