.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

217 lines
4.9 KiB

// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
public class QueryExpressions
{
public class Customer
{
public int CustomerID;
public IEnumerable<Order> Orders;
public string Name;
public string Country;
public string City;
}
public class Order
{
public int OrderID;
public DateTime OrderDate;
public Customer Customer;
public int CustomerID;
public decimal Total;
public IEnumerable<OrderDetail> Details;
}
public class OrderDetail
{
public decimal UnitPrice;
public int Quantity;
}
public IEnumerable<Customer> customers;
public IEnumerable<Order> orders;
public object MultipleWhere()
{
return from c in this.customers
where c.Orders.Count() > 10
where c.Country == "DE"
select c;
}
public object SelectManyFollowedBySelect()
{
return from c in this.customers
from o in c.Orders
select new {
c.Name,
o.OrderID,
o.Total
};
}
public object SelectManyFollowedByOrderBy()
{
return from c in this.customers
from o in c.Orders
orderby o.Total descending
select new {
c.Name,
o.OrderID,
o.Total
};
}
public object MultipleSelectManyFollowedBySelect()
{
return from c in this.customers
from o in c.Orders
from d in o.Details
select new {
c.Name,
o.OrderID,
d.Quantity
};
}
public object MultipleSelectManyFollowedByLet()
{
return from c in this.customers
from o in c.Orders
from d in o.Details
let x = (decimal)d.Quantity * d.UnitPrice
select new {
c.Name,
o.OrderID,
x
};
}
public object FromLetWhereSelect()
{
return from o in this.orders
let t = o.Details.Sum((OrderDetail d) => d.UnitPrice * (decimal)d.Quantity)
where t >= 1000m
select new {
OrderID = o.OrderID,
Total = t
};
}
public object MultipleLet()
{
return from a in this.customers
let b = a.Country
let c = a.Name
select b + c;
}
public object Join()
{
return from c in this.customers
join o in this.orders on c.CustomerID equals o.CustomerID
select new {
c.Name,
o.OrderDate,
o.Total
};
}
public object JoinInto()
{
return from c in this.customers
join o in this.orders on c.CustomerID equals o.CustomerID into co
let n = co.Count()
where n >= 10
select new {
Name = c.Name,
OrderCount = n
};
}
public object OrderBy()
{
return from o in this.orders
orderby o.Customer.Name, o.Total descending
select o;
}
public object GroupBy()
{
return from c in this.customers
group c.Name by c.Country;
}
public object ExplicitType()
{
return from Customer c in this.customers
where c.City == "London"
select c;
}
public object QueryContinuation()
{
return from c in this.customers
group c by c.Country into g
select new {
Country = g.Key,
CustCount = g.Count()
};
}
public object Issue437(bool[] bools)
{
return from x in bools
where x
select (x);
}
public static Maybe<TB> Cast<TA, TB>(Maybe<TA> a) where TB : class
{
return from m in a
let t = m as TB
where t != null
select t;
}
}
public struct Maybe<T>
{
public T Value;
public bool HasValue;
}
public static class MaybeExtensions
{
public static Maybe<TResult> Select<T, TResult>(this Maybe<T> a, Func<T, TResult> fn)
{
return default(Maybe<TResult>);
}
public static Maybe<T> Where<T>(this Maybe<T> a, Func<T, bool> predicate)
{
return default(Maybe<T>);
}
}
}