Skip to content

Instantly share code, notes, and snippets.

@abdusco
Last active June 18, 2020 15:40
Show Gist options
  • Select an option

  • Save abdusco/d2a618323e6d87b34fd83a0d42d57a0e to your computer and use it in GitHub Desktop.

Select an option

Save abdusco/d2a618323e6d87b34fd83a0d42d57a0e to your computer and use it in GitHub Desktop.
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}");
}
}
}
}
@abdusco

abdusco commented Jun 18, 2020

Copy link
Copy Markdown
Author

array verdiginde bir parametre daha verip (null) variadic arguman olarak anlamasini engellemek gerek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment