@ -0,0 +1,142 @@
@@ -0,0 +1,142 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Linq; |
||||
using ICSharpCode.NRefactory.CSharp; |
||||
using ICSharpCode.NRefactory.CSharp.PatternMatching; |
||||
|
||||
namespace ICSharpCode.Decompiler.Ast.Transforms |
||||
{ |
||||
/// <summary>
|
||||
/// Combines query expressions and removes transparent identifiers.
|
||||
/// </summary>
|
||||
public class CombineQueryExpressions : IAstTransform |
||||
{ |
||||
readonly DecompilerContext context; |
||||
|
||||
public CombineQueryExpressions(DecompilerContext context) |
||||
{ |
||||
this.context = context; |
||||
} |
||||
|
||||
public void Run(AstNode compilationUnit) |
||||
{ |
||||
if (!context.Settings.QueryExpressions) |
||||
return; |
||||
CombineQueries(compilationUnit); |
||||
} |
||||
|
||||
static readonly InvocationExpression castPattern = new InvocationExpression { |
||||
Target = new MemberReferenceExpression { |
||||
Target = new AnyNode("inExpr"), |
||||
MemberName = "Cast", |
||||
TypeArguments = { new AnyNode("targetType") } |
||||
}}; |
||||
|
||||
void CombineQueries(AstNode node) |
||||
{ |
||||
for (AstNode child = node.FirstChild; child != null; child = child.NextSibling) { |
||||
CombineQueries(child); |
||||
} |
||||
QueryExpression query = node as QueryExpression; |
||||
if (query != null) { |
||||
QueryFromClause fromClause = (QueryFromClause)query.Clauses.First(); |
||||
QueryExpression innerQuery = fromClause.Expression as QueryExpression; |
||||
if (innerQuery != null) { |
||||
if (TryRemoveTransparentIdentifier(query, fromClause, innerQuery)) { |
||||
RemoveTransparentIdentifierReferences(query); |
||||
} else { |
||||
QueryContinuationClause continuation = new QueryContinuationClause(); |
||||
continuation.PrecedingQuery = innerQuery.Detach(); |
||||
continuation.Identifier = fromClause.Identifier; |
||||
fromClause.ReplaceWith(continuation); |
||||
} |
||||
} else { |
||||
Match m = castPattern.Match(fromClause.Expression); |
||||
if (m != null) { |
||||
fromClause.Type = m.Get<AstType>("targetType").Single().Detach(); |
||||
fromClause.Expression = m.Get<Expression>("inExpr").Single().Detach(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
static readonly QuerySelectClause selectTransparentIdentifierPattern = new QuerySelectClause { |
||||
Expression = new ObjectCreateExpression { |
||||
Initializer = new ArrayInitializerExpression { |
||||
Elements = { |
||||
new NamedNode("nae1", new NamedArgumentExpression { Expression = new IdentifierExpression() }), |
||||
new NamedNode("nae2", new NamedArgumentExpression { Expression = new AnyNode() }) |
||||
} |
||||
} |
||||
}}; |
||||
|
||||
bool IsTransparentIdentifier(string identifier) |
||||
{ |
||||
return identifier.StartsWith("<>", StringComparison.Ordinal) && identifier.Contains("TransparentIdentifier"); |
||||
} |
||||
|
||||
bool TryRemoveTransparentIdentifier(QueryExpression query, QueryFromClause fromClause, QueryExpression innerQuery) |
||||
{ |
||||
if (!IsTransparentIdentifier(fromClause.Identifier)) |
||||
return false; |
||||
Match match = selectTransparentIdentifierPattern.Match(innerQuery.Clauses.Last()); |
||||
if (match == null) |
||||
return false; |
||||
QuerySelectClause selectClause = (QuerySelectClause)innerQuery.Clauses.Last(); |
||||
NamedArgumentExpression nae1 = match.Get<NamedArgumentExpression>("nae1").Single(); |
||||
NamedArgumentExpression nae2 = match.Get<NamedArgumentExpression>("nae2").Single(); |
||||
if (nae1.Identifier != ((IdentifierExpression)nae1.Expression).Identifier) |
||||
return false; |
||||
IdentifierExpression nae2IdentExpr = nae2.Expression as IdentifierExpression; |
||||
if (nae2IdentExpr != null && nae2.Identifier == nae2IdentExpr.Identifier) { |
||||
// from * in (from x in ... select new { x = x, y = y }) ...
|
||||
// =>
|
||||
// from x in ... ...
|
||||
fromClause.Remove(); |
||||
selectClause.Remove(); |
||||
// Move clauses from innerQuery to query
|
||||
QueryClause insertionPos = null; |
||||
foreach (var clause in innerQuery.Clauses) { |
||||
query.Clauses.InsertAfter(insertionPos, insertionPos = clause.Detach()); |
||||
} |
||||
} else { |
||||
// from * in (from x in ... select new { x = x, y = expr }) ...
|
||||
// =>
|
||||
// from x in ... let y = expr ...
|
||||
fromClause.Remove(); |
||||
selectClause.Remove(); |
||||
// Move clauses from innerQuery to query
|
||||
QueryClause insertionPos = null; |
||||
foreach (var clause in innerQuery.Clauses) { |
||||
query.Clauses.InsertAfter(insertionPos, insertionPos = clause.Detach()); |
||||
} |
||||
query.Clauses.InsertAfter(insertionPos, new QueryLetClause { Identifier = nae2.Identifier, Expression = nae2.Expression.Detach() }); |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes all occurrences of transparent identifiers
|
||||
/// </summary>
|
||||
void RemoveTransparentIdentifierReferences(AstNode node) |
||||
{ |
||||
foreach (AstNode child in node.Children) { |
||||
RemoveTransparentIdentifierReferences(child); |
||||
} |
||||
MemberReferenceExpression mre = node as MemberReferenceExpression; |
||||
if (mre != null) { |
||||
IdentifierExpression ident = mre.Target as IdentifierExpression; |
||||
if (ident != null && IsTransparentIdentifier(ident.Identifier)) { |
||||
IdentifierExpression newIdent = new IdentifierExpression(mre.MemberName); |
||||
mre.TypeArguments.MoveTo(newIdent.TypeArguments); |
||||
newIdent.CopyAnnotationsFrom(mre); |
||||
newIdent.RemoveAnnotations<PropertyDeclaration>(); // remove the reference to the property of the anonymous type
|
||||
mre.ReplaceWith(newIdent); |
||||
return; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Linq; |
||||
using ICSharpCode.NRefactory.CSharp; |
||||
using Mono.Cecil; |
||||
|
||||
namespace ICSharpCode.Decompiler.Ast.Transforms |
||||
{ |
||||
/// <summary>
|
||||
/// Converts extension method calls into infix syntax.
|
||||
/// </summary>
|
||||
public class IntroduceExtensionMethods : IAstTransform |
||||
{ |
||||
readonly DecompilerContext context; |
||||
|
||||
public IntroduceExtensionMethods(DecompilerContext context) |
||||
{ |
||||
this.context = context; |
||||
} |
||||
|
||||
public void Run(AstNode compilationUnit) |
||||
{ |
||||
foreach (InvocationExpression invocation in compilationUnit.Descendants.OfType<InvocationExpression>()) { |
||||
MemberReferenceExpression mre = invocation.Target as MemberReferenceExpression; |
||||
MethodReference methodReference = invocation.Annotation<MethodReference>(); |
||||
if (mre != null && mre.Target is TypeReferenceExpression && methodReference != null && invocation.Arguments.Any()) { |
||||
MethodDefinition d = methodReference.Resolve(); |
||||
if (d != null) { |
||||
foreach (var ca in d.CustomAttributes) { |
||||
if (ca.AttributeType.Name == "ExtensionAttribute" && ca.AttributeType.Namespace == "System.Runtime.CompilerServices") { |
||||
mre.Target = invocation.Arguments.First().Detach(); |
||||
if (invocation.Arguments.Any()) { |
||||
// HACK: removing type arguments should be done indepently from whether a method is an extension method,
|
||||
// just by testing whether the arguments can be inferred
|
||||
mre.TypeArguments.Clear(); |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,280 @@
@@ -0,0 +1,280 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using System.Linq; |
||||
using ICSharpCode.NRefactory.CSharp; |
||||
|
||||
namespace ICSharpCode.Decompiler.Ast.Transforms |
||||
{ |
||||
/// <summary>
|
||||
/// Decompiles query expressions.
|
||||
/// Based on C# 4.0 spec, §7.16.2 Query expression translation
|
||||
/// </summary>
|
||||
public class IntroduceQueryExpressions : IAstTransform |
||||
{ |
||||
readonly DecompilerContext context; |
||||
|
||||
public IntroduceQueryExpressions(DecompilerContext context) |
||||
{ |
||||
this.context = context; |
||||
} |
||||
|
||||
public void Run(AstNode compilationUnit) |
||||
{ |
||||
if (!context.Settings.QueryExpressions) |
||||
return; |
||||
DecompileQueries(compilationUnit); |
||||
// After all queries were decompiled, detect degenerate queries (queries not property terminated with 'select' or 'group')
|
||||
// and fix them, either by adding a degenerate select, or by combining them with another query.
|
||||
foreach (QueryExpression query in compilationUnit.Descendants.OfType<QueryExpression>()) { |
||||
QueryFromClause fromClause = (QueryFromClause)query.Clauses.First(); |
||||
if (IsDegenerateQuery(query)) { |
||||
// introduce select for degenerate query
|
||||
query.Clauses.Add(new QuerySelectClause { Expression = new IdentifierExpression(fromClause.Identifier) }); |
||||
} |
||||
// See if the data source of this query is a degenerate query,
|
||||
// and combine the queries if possible.
|
||||
QueryExpression innerQuery = fromClause.Expression as QueryExpression; |
||||
while (IsDegenerateQuery(innerQuery)) { |
||||
QueryFromClause innerFromClause = (QueryFromClause)innerQuery.Clauses.First(); |
||||
if (fromClause.Identifier != innerFromClause.Identifier) |
||||
break; |
||||
// Replace the fromClause with all clauses from the inner query
|
||||
fromClause.Remove(); |
||||
QueryClause insertionPos = null; |
||||
foreach (var clause in innerQuery.Clauses) { |
||||
query.Clauses.InsertAfter(insertionPos, insertionPos = clause.Detach()); |
||||
} |
||||
fromClause = innerFromClause; |
||||
innerQuery = fromClause.Expression as QueryExpression; |
||||
} |
||||
} |
||||
} |
||||
|
||||
bool IsDegenerateQuery(QueryExpression query) |
||||
{ |
||||
if (query == null) |
||||
return false; |
||||
var lastClause = query.Clauses.LastOrDefault(); |
||||
return !(lastClause is QuerySelectClause || lastClause is QueryGroupClause); |
||||
} |
||||
|
||||
void DecompileQueries(AstNode node) |
||||
{ |
||||
QueryExpression query = DecompileQuery(node as InvocationExpression); |
||||
if (query != null) |
||||
node.ReplaceWith(query); |
||||
for (AstNode child = (query ?? node).FirstChild; child != null; child = child.NextSibling) { |
||||
DecompileQueries(child); |
||||
} |
||||
} |
||||
|
||||
QueryExpression DecompileQuery(InvocationExpression invocation) |
||||
{ |
||||
if (invocation == null) |
||||
return null; |
||||
MemberReferenceExpression mre = invocation.Target as MemberReferenceExpression; |
||||
if (mre == null) |
||||
return null; |
||||
switch (mre.MemberName) { |
||||
case "Select": |
||||
{ |
||||
if (invocation.Arguments.Count != 1) |
||||
return null; |
||||
string parameterName; |
||||
Expression body; |
||||
if (MatchSimpleLambda(invocation.Arguments.Single(), out parameterName, out body)) { |
||||
QueryExpression query = new QueryExpression(); |
||||
query.Clauses.Add(new QueryFromClause { Identifier = parameterName, Expression = mre.Target.Detach() }); |
||||
query.Clauses.Add(new QuerySelectClause { Expression = body.Detach() }); |
||||
return query; |
||||
} |
||||
return null; |
||||
} |
||||
case "GroupBy": |
||||
{ |
||||
if (invocation.Arguments.Count == 2) { |
||||
string parameterName1, parameterName2; |
||||
Expression keySelector, elementSelector; |
||||
if (MatchSimpleLambda(invocation.Arguments.ElementAt(0), out parameterName1, out keySelector) |
||||
&& MatchSimpleLambda(invocation.Arguments.ElementAt(1), out parameterName2, out elementSelector) |
||||
&& parameterName1 == parameterName2) |
||||
{ |
||||
QueryExpression query = new QueryExpression(); |
||||
query.Clauses.Add(new QueryFromClause { Identifier = parameterName1, Expression = mre.Target.Detach() }); |
||||
query.Clauses.Add(new QueryGroupClause { Projection = elementSelector.Detach(), Key = keySelector.Detach() }); |
||||
return query; |
||||
} |
||||
} else if (invocation.Arguments.Count == 1) { |
||||
string parameterName; |
||||
Expression keySelector; |
||||
if (MatchSimpleLambda(invocation.Arguments.Single(), out parameterName, out keySelector)) { |
||||
QueryExpression query = new QueryExpression(); |
||||
query.Clauses.Add(new QueryFromClause { Identifier = parameterName, Expression = mre.Target.Detach() }); |
||||
query.Clauses.Add(new QueryGroupClause { Projection = new IdentifierExpression(parameterName), Key = keySelector.Detach() }); |
||||
return query; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
case "SelectMany": |
||||
{ |
||||
if (invocation.Arguments.Count != 2) |
||||
return null; |
||||
string parameterName; |
||||
Expression collectionSelector; |
||||
if (!MatchSimpleLambda(invocation.Arguments.ElementAt(0), out parameterName, out collectionSelector)) |
||||
return null; |
||||
LambdaExpression lambda = invocation.Arguments.ElementAt(1) as LambdaExpression; |
||||
if (lambda != null && lambda.Parameters.Count == 2 && lambda.Body is Expression) { |
||||
ParameterDeclaration p1 = lambda.Parameters.ElementAt(0); |
||||
ParameterDeclaration p2 = lambda.Parameters.ElementAt(1); |
||||
if (p1.Name == parameterName) { |
||||
QueryExpression query = new QueryExpression(); |
||||
query.Clauses.Add(new QueryFromClause { Identifier = p1.Name, Expression = mre.Target.Detach() }); |
||||
query.Clauses.Add(new QueryFromClause { Identifier = p2.Name, Expression = collectionSelector.Detach() }); |
||||
query.Clauses.Add(new QuerySelectClause { Expression = ((Expression)lambda.Body).Detach() }); |
||||
return query; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
case "Where": |
||||
{ |
||||
if (invocation.Arguments.Count != 1) |
||||
return null; |
||||
string parameterName; |
||||
Expression body; |
||||
if (MatchSimpleLambda(invocation.Arguments.Single(), out parameterName, out body)) { |
||||
QueryExpression query = new QueryExpression(); |
||||
query.Clauses.Add(new QueryFromClause { Identifier = parameterName, Expression = mre.Target.Detach() }); |
||||
query.Clauses.Add(new QueryWhereClause { Condition = body.Detach() }); |
||||
return query; |
||||
} |
||||
return null; |
||||
} |
||||
case "OrderBy": |
||||
case "OrderByDescending": |
||||
case "ThenBy": |
||||
case "ThenByDescending": |
||||
{ |
||||
if (invocation.Arguments.Count != 1) |
||||
return null; |
||||
string parameterName; |
||||
Expression orderExpression; |
||||
if (MatchSimpleLambda(invocation.Arguments.Single(), out parameterName, out orderExpression)) { |
||||
if (ValidateThenByChain(invocation, parameterName)) { |
||||
QueryOrderClause orderClause = new QueryOrderClause(); |
||||
InvocationExpression tmp = invocation; |
||||
while (mre.MemberName == "ThenBy" || mre.MemberName == "ThenByDescending") { |
||||
// insert new ordering at beginning
|
||||
orderClause.Orderings.InsertAfter( |
||||
null, new QueryOrdering { |
||||
Expression = orderExpression.Detach(), |
||||
Direction = (mre.MemberName == "ThenBy" ? QueryOrderingDirection.None : QueryOrderingDirection.Descending) |
||||
}); |
||||
|
||||
tmp = (InvocationExpression)mre.Target; |
||||
mre = (MemberReferenceExpression)tmp.Target; |
||||
MatchSimpleLambda(tmp.Arguments.Single(), out parameterName, out orderExpression); |
||||
} |
||||
// insert new ordering at beginning
|
||||
orderClause.Orderings.InsertAfter( |
||||
null, new QueryOrdering { |
||||
Expression = orderExpression.Detach(), |
||||
Direction = (mre.MemberName == "OrderBy" ? QueryOrderingDirection.None : QueryOrderingDirection.Descending) |
||||
}); |
||||
|
||||
QueryExpression query = new QueryExpression(); |
||||
query.Clauses.Add(new QueryFromClause { Identifier = parameterName, Expression = mre.Target.Detach() }); |
||||
query.Clauses.Add(orderClause); |
||||
return query; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
case "Join": |
||||
case "GroupJoin": |
||||
{ |
||||
if (invocation.Arguments.Count != 4) |
||||
return null; |
||||
Expression source1 = mre.Target; |
||||
Expression source2 = invocation.Arguments.ElementAt(0); |
||||
string elementName1, elementName2; |
||||
Expression key1, key2; |
||||
if (!MatchSimpleLambda(invocation.Arguments.ElementAt(1), out elementName1, out key1)) |
||||
return null; |
||||
if (!MatchSimpleLambda(invocation.Arguments.ElementAt(2), out elementName2, out key2)) |
||||
return null; |
||||
LambdaExpression lambda = invocation.Arguments.ElementAt(3) as LambdaExpression; |
||||
if (lambda != null && lambda.Parameters.Count == 2 && lambda.Body is Expression) { |
||||
ParameterDeclaration p1 = lambda.Parameters.ElementAt(0); |
||||
ParameterDeclaration p2 = lambda.Parameters.ElementAt(1); |
||||
if (p1.Name == elementName1 && (p2.Name == elementName2 || mre.MemberName == "GroupJoin")) { |
||||
QueryExpression query = new QueryExpression(); |
||||
query.Clauses.Add(new QueryFromClause { Identifier = elementName1, Expression = source1.Detach() }); |
||||
QueryJoinClause joinClause = new QueryJoinClause(); |
||||
joinClause.JoinIdentifier = elementName2; // join elementName2
|
||||
joinClause.InExpression = source2.Detach(); // in source2
|
||||
joinClause.OnExpression = key1.Detach(); // on key1
|
||||
joinClause.EqualsExpression = key2.Detach(); // equals key2
|
||||
if (mre.MemberName == "GroupJoin") { |
||||
joinClause.IntoIdentifier = p2.Name; // into p2.Name
|
||||
} |
||||
query.Clauses.Add(joinClause); |
||||
query.Clauses.Add(new QuerySelectClause { Expression = ((Expression)lambda.Body).Detach() }); |
||||
return query; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
default: |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Ensure that all ThenBy's are correct, and that the list of ThenBy's is terminated by an 'OrderBy' invocation.
|
||||
/// </summary>
|
||||
bool ValidateThenByChain(InvocationExpression invocation, string expectedParameterName) |
||||
{ |
||||
if (invocation == null || invocation.Arguments.Count != 1) |
||||
return false; |
||||
MemberReferenceExpression mre = invocation.Target as MemberReferenceExpression; |
||||
if (mre == null) |
||||
return false; |
||||
string parameterName; |
||||
Expression body; |
||||
if (!MatchSimpleLambda(invocation.Arguments.Single(), out parameterName, out body)) |
||||
return false; |
||||
if (parameterName != expectedParameterName) |
||||
return false; |
||||
|
||||
if (mre.MemberName == "OrderBy" || mre.MemberName == "OrderByDescending") |
||||
return true; |
||||
else if (mre.MemberName == "ThenBy" || mre.MemberName == "ThenByDescending") |
||||
return ValidateThenByChain(mre.Target as InvocationExpression, expectedParameterName); |
||||
else |
||||
return false; |
||||
} |
||||
|
||||
/// <summary>Matches simple lambdas of the form "a => b"</summary>
|
||||
bool MatchSimpleLambda(Expression expr, out string parameterName, out Expression body) |
||||
{ |
||||
LambdaExpression lambda = expr as LambdaExpression; |
||||
if (lambda != null && lambda.Parameters.Count == 1 && lambda.Body is Expression) { |
||||
ParameterDeclaration p = lambda.Parameters.Single(); |
||||
if (p.ParameterModifier == ParameterModifier.None) { |
||||
parameterName = p.Name; |
||||
body = (Expression)lambda.Body; |
||||
return true; |
||||
} |
||||
} |
||||
parameterName = null; |
||||
body = null; |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
public class CallOverloadedMethod |
||||
{ |
||||
public void OverloadedMethod(object a) |
||||
{ |
||||
} |
||||
|
||||
public void OverloadedMethod(int? a) |
||||
{ |
||||
} |
||||
|
||||
public void OverloadedMethod(string a) |
||||
{ |
||||
} |
||||
|
||||
public void Call() |
||||
{ |
||||
this.OverloadedMethod("(string)"); |
||||
this.OverloadedMethod((object)"(object)"); |
||||
this.OverloadedMethod(5); |
||||
this.OverloadedMethod((object)5); |
||||
this.OverloadedMethod(5L); |
||||
this.OverloadedMethod((object)null); |
||||
this.OverloadedMethod((string)null); |
||||
this.OverloadedMethod((int?)null); |
||||
} |
||||
|
||||
public void CallMethodUsingInterface(List<int> list) |
||||
{ |
||||
((ICollection<int>)list).Clear(); |
||||
} |
||||
} |
||||
@ -0,0 +1,149 @@
@@ -0,0 +1,149 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
public class QueryExpressions |
||||
{ |
||||
public class Customer |
||||
{ |
||||
public int CustomerID; |
||||
public IEnumerable<QueryExpressions.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<QueryExpressions.OrderDetail> Details; |
||||
} |
||||
|
||||
public class OrderDetail |
||||
{ |
||||
public decimal UnitPrice; |
||||
public int Quantity; |
||||
} |
||||
|
||||
public IEnumerable<QueryExpressions.Customer> customers; |
||||
public IEnumerable<QueryExpressions.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 = 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(d => d.UnitPrice * d.Quantity) |
||||
where t >= 1000 |
||||
select new { 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 customers |
||||
join o in orders on c.CustomerID equals o.CustomerID |
||||
select new { c.Name, o.OrderDate, o.Total }; |
||||
} |
||||
|
||||
public object JoinInto() |
||||
{ |
||||
return |
||||
from c in customers |
||||
join o in orders on c.CustomerID equals o.CustomerID into co |
||||
let n = co.Count() |
||||
where n >= 10 |
||||
select new { c.Name, OrderCount = n }; |
||||
} |
||||
|
||||
public object OrderBy() |
||||
{ |
||||
return |
||||
from o in orders |
||||
orderby o.Customer.Name, o.Total descending |
||||
select o; |
||||
} |
||||
|
||||
public object GroupBy() |
||||
{ |
||||
return |
||||
from c in customers |
||||
group c.Name by c.Country; |
||||
} |
||||
|
||||
public object ExplicitType() |
||||
{ |
||||
return |
||||
from Customer c in customers |
||||
where c.City == "London" |
||||
select c; |
||||
} |
||||
|
||||
public object QueryContinuation() |
||||
{ |
||||
return |
||||
from c in customers |
||||
group c by c.Country into g |
||||
select new { Country = g.Key, CustCount = g.Count() }; |
||||
} |
||||
} |
||||
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
|
||||
|
||||
// Copyright (c) 2011 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; |
||||
|
||||
namespace ICSharpCode.ILSpy |
||||
{ |
||||
internal enum AccessOverlayIcon |
||||
{ |
||||
Public, |
||||
Protected, |
||||
Internal, |
||||
ProtectedInternal, |
||||
Private, |
||||
} |
||||
} |
||||
|
Before Width: | Height: | Size: 733 B After Width: | Height: | Size: 470 B |
|
After Width: | Height: | Size: 468 B |
|
Before Width: | Height: | Size: 908 B After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 680 B After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 631 B |
|
Before Width: | Height: | Size: 640 B After Width: | Height: | Size: 494 B |
|
Before Width: | Height: | Size: 488 B After Width: | Height: | Size: 567 B |
|
Before Width: | Height: | Size: 655 B After Width: | Height: | Size: 411 B |
|
After Width: | Height: | Size: 404 B |
|
After Width: | Height: | Size: 658 B |
|
After Width: | Height: | Size: 689 B |
|
Before Width: | Height: | Size: 449 B After Width: | Height: | Size: 500 B |
|
Before Width: | Height: | Size: 610 B After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 881 B |
|
Before Width: | Height: | Size: 916 B |
|
Before Width: | Height: | Size: 821 B |
|
Before Width: | Height: | Size: 775 B |
|
Before Width: | Height: | Size: 575 B |
|
Before Width: | Height: | Size: 416 B After Width: | Height: | Size: 586 B |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
// Copyright (c) 2011 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; |
||||
|
||||
namespace ICSharpCode.ILSpy |
||||
{ |
||||
internal enum MemberIcon |
||||
{ |
||||
Literal, |
||||
FieldReadOnly, |
||||
Field, |
||||
EnumValue, |
||||
Property, |
||||
Indexer, |
||||
Method, |
||||
Constructor, |
||||
VirtualMethod, |
||||
Operator, |
||||
ExtensionMethod, |
||||
Event |
||||
} |
||||
} |
||||
|
Before Width: | Height: | Size: 621 B After Width: | Height: | Size: 532 B |
|
Before Width: | Height: | Size: 235 B After Width: | Height: | Size: 526 B |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 401 B |
|
After Width: | Height: | Size: 352 B |
|
After Width: | Height: | Size: 440 B |
|
After Width: | Height: | Size: 312 B |
|
Before Width: | Height: | Size: 920 B |
|
Before Width: | Height: | Size: 925 B |
|
Before Width: | Height: | Size: 845 B |
|
Before Width: | Height: | Size: 781 B |
|
Before Width: | Height: | Size: 642 B |
|
Before Width: | Height: | Size: 900 B After Width: | Height: | Size: 746 B |
|
Before Width: | Height: | Size: 864 B |
|
Before Width: | Height: | Size: 937 B |
|
Before Width: | Height: | Size: 784 B |
|
Before Width: | Height: | Size: 753 B |
|
Before Width: | Height: | Size: 556 B |
|
Before Width: | Height: | Size: 575 B After Width: | Height: | Size: 562 B |
|
After Width: | Height: | Size: 803 B |
|
After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 422 B After Width: | Height: | Size: 564 B |
|
Before Width: | Height: | Size: 262 B After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 267 B After Width: | Height: | Size: 1.3 KiB |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
// Copyright (c) 2011 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; |
||||
|
||||
namespace ICSharpCode.ILSpy |
||||
{ |
||||
internal enum TypeIcon |
||||
{ |
||||
Class, |
||||
Enum, |
||||
Struct, |
||||
Interface, |
||||
Delegate |
||||
} |
||||
} |
||||
|
After Width: | Height: | Size: 412 B |