Customer Filter Operator w/o deferred execution
parent
512d8304e7
commit
46766de185
|
@ -1,9 +1,22 @@
|
||||||
namespace Queries
|
using System;
|
||||||
|
|
||||||
|
namespace Queries
|
||||||
{
|
{
|
||||||
public class Movie
|
public class Movie
|
||||||
{
|
{
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
public float Rating { get; set; }
|
public float Rating { get; set; }
|
||||||
public int Year { get; set; }
|
private int _year;
|
||||||
|
public int Year {
|
||||||
|
get
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Returning {_year} for {Title}");
|
||||||
|
return _year;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_year = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,7 +5,7 @@ using System.Reflection;
|
||||||
|
|
||||||
namespace Queries
|
namespace Queries
|
||||||
{
|
{
|
||||||
public static class MyLInq
|
public static class MyLinq
|
||||||
{
|
{
|
||||||
public static IEnumerable<T> Filter<T>(this IEnumerable<T> source,
|
public static IEnumerable<T> Filter<T>(this IEnumerable<T> source,
|
||||||
Func<T, bool> predicate)
|
Func<T, bool> predicate)
|
|
@ -17,6 +17,8 @@ namespace Queries
|
||||||
};
|
};
|
||||||
|
|
||||||
// filter operator from LINQ
|
// filter operator from LINQ
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Filter operator from LINQ");
|
||||||
var query = movies.Where(m => m.Year > 2000);
|
var query = movies.Where(m => m.Year > 2000);
|
||||||
foreach (var movie in query)
|
foreach (var movie in query)
|
||||||
{
|
{
|
||||||
|
@ -24,6 +26,8 @@ namespace Queries
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter operator using customized Filter extension
|
// filter operator using customized Filter extension
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Customerized Filter operator");
|
||||||
var query2 = movies.Filter(m => m.Year > 2000);
|
var query2 = movies.Filter(m => m.Year > 2000);
|
||||||
foreach (var movie in query2)
|
foreach (var movie in query2)
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Features", "Features\Featur
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Queries", "Queries\Queries.csproj", "{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Queries", "Queries\Queries.csproj", "{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "yield_test", "yield_test\yield_test.csproj", "{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -58,5 +60,17 @@ Global
|
||||||
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Release|x64.Build.0 = Release|Any CPU
|
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Release|x86.ActiveCfg = Release|Any CPU
|
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Release|x86.Build.0 = Release|Any CPU
|
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|
Loading…
Reference in New Issue