本文整理汇总了C#中ICSharpCode.NRefactory.Ast.LambdaExpression类的典型用法代码示例。如果您正苦于以下问题:C# LambdaExpression类的具体用法?C# LambdaExpression怎么用?C# LambdaExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LambdaExpression类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了LambdaExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModifyLambdaForSelectMany
private static INode ModifyLambdaForSelectMany(LambdaExpression lambdaExpression,
ParenthesizedExpression parenthesizedlambdaExpression,
InvocationExpression invocationExpression)
{
INode node = lambdaExpression;
var argPos = invocationExpression.Arguments.IndexOf(lambdaExpression);
switch (argPos)
{
case 0: // first one, select the collection
// need to enter a cast for (IEnumerable<dynamic>) on the end of the lambda body
var selectManyExpression = new LambdaExpression
{
ExpressionBody =
new CastExpression(new TypeReference("IEnumerable<dynamic>"),
new ParenthesizedExpression(lambdaExpression.ExpressionBody), CastType.Cast),
Parameters = lambdaExpression.Parameters,
};
node = new CastExpression(new TypeReference("Func<dynamic, IEnumerable<dynamic>>"),
new ParenthesizedExpression(selectManyExpression), CastType.Cast);
break;
case 1: // the transformation func
node = new CastExpression(new TypeReference("Func<dynamic, dynamic, dynamic>"), parenthesizedlambdaExpression,
CastType.Cast);
break;
}
return node;
}
示例2: VisitLambdaExpression
public override object VisitLambdaExpression(LambdaExpression lambdaExpression, object data)
{
if (lambdaExpression.StatementBody == null || lambdaExpression.StatementBody.IsNull)
return base.VisitLambdaExpression(lambdaExpression, data);
var text = QueryParsingUtils.ToText(lambdaExpression);
throw new SecurityException("Lambda expression can only consist of a single expression, not a statement, but got: " + text);
}
示例3: LocalLookupVariable
public LocalLookupVariable(string name, TypeReference typeRef, Location startPos, Location endPos, bool isConst, bool isLoopVariable, Expression initializer, LambdaExpression parentLambdaExpression)
{
this.Name = name;
this.TypeRef = typeRef;
this.StartPos = startPos;
this.EndPos = endPos;
this.IsConst = isConst;
this.IsLoopVariable = isLoopVariable;
this.Initializer = initializer;
this.ParentLambdaExpression = parentLambdaExpression;
}
示例4: VisitAnonymousMethodExpression
public override object VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data)
{
base.VisitAnonymousMethodExpression(anonymousMethodExpression, data);
if (anonymousMethodExpression.Body.Children.Count == 1) {
ReturnStatement rs = anonymousMethodExpression.Body.Children[0] as ReturnStatement;
if (rs != null) {
LambdaExpression lambda = new LambdaExpression();
lambda.ExpressionBody = rs.Expression;
lambda.Parameters = anonymousMethodExpression.Parameters;
ReplaceCurrentNode(lambda);
}
}
return null;
}
示例5: AddDocumentIdFieldToLambdaIfCreatingNewObject
private static void AddDocumentIdFieldToLambdaIfCreatingNewObject(LambdaExpression lambdaExpression)
{
if (lambdaExpression.ExpressionBody is ObjectCreateExpression == false)
return;
var objectInitializer = ((ObjectCreateExpression)lambdaExpression.ExpressionBody).ObjectInitializer;
var identifierExpression = new IdentifierExpression(lambdaExpression.Parameters[0].ParameterName);
objectInitializer.CreateExpressions.Add(
new NamedArgumentExpression
{
Name = "__document_id",
Expression = new MemberReferenceExpression(identifierExpression, "__document_id")
});
}
示例6: LambdaParameterReturnType
public LambdaParameterReturnType(LambdaExpression lambda, string name, NRefactoryResolver resolver)
{
if (lambda == null)
throw new ArgumentNullException("lambda");
if (name == null)
throw new ArgumentNullException("name");
if (resolver == null)
throw new ArgumentNullException("resolver");
this.lambda = lambda;
this.parameterName = name;
this.parameterIndex = lambda.Parameters.FindIndex(p => p.ParameterName == name);
this.resolver = resolver;
if (parameterIndex < 0)
throw new ArgumentException("there is no lambda parameter with that name");
}
示例7: LambdaReturnType
internal LambdaReturnType(LambdaExpression expression, NRefactoryResolver resolver)
: base(resolver.CompilationUnit)
{
this.resolver = resolver;
this.lambdaExpression = expression;
base.MethodParameters = new List<IParameter>();
foreach (ParameterDeclarationExpression param in expression.Parameters) {
base.MethodParameters.Add(NRefactoryASTConvertVisitor.CreateParameter(param, resolver.CallingMember as IMethod, resolver.CallingClass, resolver.CompilationUnit));
}
if (expression.ExpressionBody.IsNull)
expression.StatementBody.AcceptVisitor(new ReturnStatementFinder(returnExpressions), null);
else
returnExpressions.Add(expression.ExpressionBody);
}
示例8: AddVariable
public void AddVariable(TypeReference typeRef, string name,
Location startPos, Location endPos, bool isConst,
bool isLoopVariable, Expression initializer,
LambdaExpression parentLambdaExpression)
{
if (name == null || name.Length == 0) {
return;
}
List<LocalLookupVariable> list;
if (!variables.ContainsKey(name)) {
variables[name] = list = new List<LocalLookupVariable>();
} else {
list = (List<LocalLookupVariable>)variables[name];
}
list.Add(new LocalLookupVariable(name, typeRef, startPos, endPos, isConst, isLoopVariable, initializer, parentLambdaExpression));
}
示例9: LambdaExpr
void LambdaExpr(
#line 1995 "VBNET.ATG"
out Expression expr) {
#line 1997 "VBNET.ATG"
Expression inner = null;
LambdaExpression lambda = new LambdaExpression();
lambda.StartLocation = la.Location;
Expect(114);
if (la.kind == 25) {
lexer.NextToken();
if (StartOf(4)) {
FormalParameterList(
#line 2003 "VBNET.ATG"
lambda.Parameters);
}
Expect(26);
}
Expr(
#line 2004 "VBNET.ATG"
out inner);
#line 2006 "VBNET.ATG"
lambda.ExpressionBody = inner;
lambda.EndLocation = t.EndLocation; // la.Location?
expr = lambda;
}
示例10: VisitLambdaExpression
public override object VisitLambdaExpression(LambdaExpression lambdaExpression, object data)
{
foreach (ParameterDeclarationExpression p in lambdaExpression.Parameters) {
AddVariable(p.TypeReference, p.ParameterName,
lambdaExpression.StartLocation, lambdaExpression.ExtendedEndLocation,
false, false, null, lambdaExpression, false, lambdaExpression.StartLocation);
}
return base.VisitLambdaExpression(lambdaExpression, data);
}
示例11: VisitAnonymousMethodExpression
public override object VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data)
{
base.VisitAnonymousMethodExpression(anonymousMethodExpression, data);
LambdaExpression lambda = new LambdaExpression();
lambda.Parameters = anonymousMethodExpression.Parameters;
if (anonymousMethodExpression.Body.Children.Count == 1) {
ReturnStatement rs = anonymousMethodExpression.Body.Children[0] as ReturnStatement;
if (rs != null)
lambda.ExpressionBody = rs.Expression;
else {
lambda.StatementBody = anonymousMethodExpression.Body.Children[0] as Statement;
lambda.ReturnType = new TypeReference("System.Void", true);
}
} else {
var visitor = new ReturnStatementVisitor();
anonymousMethodExpression.AcceptVisitor(visitor, null);
lambda.StatementBody = anonymousMethodExpression.Body;
if (!visitor.HasReturn)
lambda.ReturnType = new TypeReference("System.Void", true);
}
ReplaceCurrentNode(lambda);
return null;
}
示例12: LambdaExpressionBody
void LambdaExpressionBody(
#line 2174 "cs.ATG"
LambdaExpression lambda) {
#line 2175 "cs.ATG"
Expression expr; BlockStatement stmt;
if (la.kind == 16) {
Block(
#line 2178 "cs.ATG"
out stmt);
#line 2178 "cs.ATG"
lambda.StatementBody = stmt;
} else if (StartOf(6)) {
Expr(
#line 2179 "cs.ATG"
out expr);
#line 2179 "cs.ATG"
lambda.ExpressionBody = expr;
} else SynErr(214);
#line 2181 "cs.ATG"
lambda.EndLocation = t.EndLocation;
#line 2182 "cs.ATG"
lambda.ExtendedEndLocation = la.Location;
}
示例13: SubLambdaExpression
void SubLambdaExpression(
//#line 2219 "VBNET.ATG"
out LambdaExpression lambda) {
//#line 2221 "VBNET.ATG"
lambda = new LambdaExpression();
lambda.ReturnType = new TypeReference("System.Void", true);
Expression inner = null;
Statement statement = null;
lambda.StartLocation = la.Location;
Expect(210);
if (la.kind == 37) {
lexer.NextToken();
if (StartOf(6)) {
FormalParameterList(
//#line 2228 "VBNET.ATG"
lambda.Parameters);
}
Expect(38);
}
if (StartOf(42)) {
if (StartOf(24)) {
Expr(
//#line 2231 "VBNET.ATG"
out inner);
//#line 2233 "VBNET.ATG"
lambda.ExpressionBody = inner;
lambda.EndLocation = t.EndLocation; // la.Location?
lambda.ExtendedEndLocation = la.Location;
} else {
EmbeddedStatement(
//#line 2238 "VBNET.ATG"
out statement);
//#line 2240 "VBNET.ATG"
lambda.StatementBody = statement;
lambda.EndLocation = t.EndLocation;
lambda.ExtendedEndLocation = la.Location;
}
} else if (la.kind == 1) {
lexer.NextToken();
Block(
//#line 2247 "VBNET.ATG"
out statement);
Expect(113);
Expect(210);
//#line 2250 "VBNET.ATG"
lambda.StatementBody = statement;
lambda.EndLocation = t.EndLocation;
lambda.ExtendedEndLocation = la.Location;
} else SynErr(296);
}
示例14: ModifyLambdaForMinMax
private static INode ModifyLambdaForMinMax(LambdaExpression lambdaExpression,
ParenthesizedExpression parenthesizedlambdaExpression)
{
var node = new CastExpression(new TypeReference("Func<dynamic, int>"), parenthesizedlambdaExpression, CastType.Cast);
var castExpression = lambdaExpression.ExpressionBody as CastExpression;
if (castExpression != null)
{
node = new CastExpression(new TypeReference("Func", new List<TypeReference>
{
new TypeReference("dynamic"),
castExpression.CastTo
}), parenthesizedlambdaExpression, CastType.Cast);
}
return node;
}
示例15: LambdaExpressionBody
void LambdaExpressionBody(
#line 2147 "Frames/cs.ATG"
LambdaExpression lambda) {
#line 2148 "Frames/cs.ATG"
Expression expr; BlockStatement stmt;
if (la.kind == 16) {
BlockInsideExpression(
#line 2151 "Frames/cs.ATG"
out stmt);
#line 2151 "Frames/cs.ATG"
lambda.StatementBody = stmt;
} else if (StartOf(6)) {
Expr(
#line 2152 "Frames/cs.ATG"
out expr);
#line 2152 "Frames/cs.ATG"
lambda.ExpressionBody = expr;
} else SynErr(214);
#line 2154 "Frames/cs.ATG"
lambda.EndLocation = t.EndLocation;
#line 2155 "Frames/cs.ATG"
lambda.ExtendedEndLocation = la.Location;
}