本文整理汇总了C#中Recipe.Prepare方法的典型用法代码示例。如果您正苦于以下问题:C# Recipe.Prepare方法的具体用法?C# Recipe.Prepare怎么用?C# Recipe.Prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Recipe
的用法示例。
在下文中一共展示了Recipe.Prepare方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_build_a_single_expression_when_given_two_query_parameters_with_an_and
public void Should_build_a_single_expression_when_given_two_query_parameters_with_an_and( )
{
var r = new Recipe<SampleData>( "Address lk 'Test' and Value gt '20'" );
var data = new SampleRepository
{
DataSource = new[ ]
{
new SampleData {Address = "Test 2", Value = 21},
new SampleData {Address = "Test 3", Value = 19},
new SampleData {Address = "Not like anything else", Value = 30},
}
}.DataSource;
data = data.Where( r.Prepare( ) );
Assert.AreEqual( 1, data.Count( ) );
}
示例2: Should_build_a_single_expression_when_given_a_complex_parameter_string
public void Should_build_a_single_expression_when_given_a_complex_parameter_string( )
{
var r = new Recipe<SampleData>( "Address lk 'Test' and (Value gt '20' or Id eq '1')" );
var data = new SampleRepository
{
DataSource = new[ ]
{
new SampleData {Address = "Test 2", Value = 21, Id = 2},
new SampleData {Address = "Test 3", Value = 19, Id = 13},
new SampleData
{Address = "Test else", Value = 18, Id = 1},
new SampleData
{Address = "Not like anything else", Value = 30, Id = 4},
}
}.DataSource;
data = data.Where( r.Prepare( ) );
Assert.AreEqual( 2, data.Count( ) );
}
示例3: Should_build_a_working_expression_given_one_value_query
public void Should_build_a_working_expression_given_one_value_query( )
{
var r = new Recipe<SampleData>( "Address lk 'Test'" );
var data = new SampleRepository
{
DataSource = new[ ]
{
new SampleData {Address = "Test 2"},
new SampleData {Address = "Test 3"},
new SampleData {Address = "Not like anything else"},
}
}.DataSource;
data = data.Where( r.Prepare( ) );
Assert.AreEqual( 2, data.Count( ) );
}
示例4: Should_build_a_single_instruction_when_provided_one_value_query
public void Should_build_a_single_instruction_when_provided_one_value_query( )
{
var r = new Recipe<SampleData>( "Address lk 'Test'" );
Assert.IsNotNull( r.Prepare( ) );
}
示例5: Main
static void Main(string[ ] args)
{
CustomerRepository repository = new CustomerRepository
{
DataSource = new[ ]
{
new Customer
{
FirstName = "John",
LastName = "Smith",
CreditLimit = 10000,
Address = "156 Langolier Drive",
State = "NJ"
},
new Customer
{
FirstName = "Herbert",
LastName = "Jenkins",
CreditLimit = 5000,
Address = "123 Penny Lane",
State = "OR"
},
new Customer
{
FirstName = "Fred",
LastName = "Jones",
CreditLimit = 1500,
Address = "155 Poor Street",
State = "NJ"
}
}
};
//string recipeInstructions = "CreditLimit gte '5000' and LastName lk 'Jen' or CreditLimit lt '1600'";
//Recipe<Customer> customerRecipe = new Recipe<Customer>( recipeInstructions );
//var results = repository.DataSource.Where( customerRecipe.Prepare( ) );
//foreach ( var result in results )
//{
// Console.WriteLine( result );
//}
while ( true )
{
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.Clear( );
Console.WriteLine( "Query" );
Console.WriteLine( new string( '-', 30 ) );
Console.Write( ">" );
var recipe = Console.ReadLine( );
if ( recipe.Equals( "quit", StringComparison.InvariantCultureIgnoreCase ) )
break;
Recipe<Customer> customerRecipe = new Recipe<Customer>( recipe );
if ( customerRecipe.Invalid )
break;
var results = repository.DataSource.Where( customerRecipe.Prepare( ) );
Console.WriteLine( "First Name\t\tLastName\t\tState\t\tAddress\t\tCredit Limit" );
Console.WriteLine( new string( '-', 100 ) );
foreach ( var result in results )
{
Console.WriteLine( string.Format( "{0}\t\t{1}\t\t{2}", result.FirstName, result.LastName,
result.Address ) );
}
Console.WriteLine( "Any key to continue" );
Console.ReadKey( );
}
}