Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3123 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
7 changed files with 169 additions and 41 deletions
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.AstBuilder |
||||
{ |
||||
#if NET35
|
||||
/// <summary>
|
||||
/// Extension methods for NRefactory.Ast.Expression.
|
||||
/// </summary>
|
||||
public static class ExpressionBuilder |
||||
{ |
||||
public static IdentifierExpression Identifier(string identifier) |
||||
{ |
||||
return new IdentifierExpression(identifier); |
||||
} |
||||
|
||||
public static MemberReferenceExpression Member(this Expression targetObject, string memberName) |
||||
{ |
||||
if (targetObject == null) |
||||
throw new ArgumentNullException("targetObject"); |
||||
return new MemberReferenceExpression(targetObject, memberName); |
||||
} |
||||
|
||||
public static InvocationExpression Call(this Expression callTarget, string methodName, params Expression[] arguments) |
||||
{ |
||||
if (callTarget == null) |
||||
throw new ArgumentNullException("callTarget"); |
||||
return Call(Member(callTarget, methodName), arguments); |
||||
} |
||||
|
||||
public static InvocationExpression Call(this Expression callTarget, params Expression[] arguments) |
||||
{ |
||||
if (callTarget == null) |
||||
throw new ArgumentNullException("callTarget"); |
||||
if (arguments == null) |
||||
throw new ArgumentNullException("arguments"); |
||||
return new InvocationExpression(callTarget, new List<Expression>(arguments)); |
||||
} |
||||
|
||||
public static ObjectCreateExpression New(this TypeReference createType, params Expression[] arguments) |
||||
{ |
||||
if (createType == null) |
||||
throw new ArgumentNullException("createType"); |
||||
if (arguments == null) |
||||
throw new ArgumentNullException("arguments"); |
||||
return new ObjectCreateExpression(createType, new List<Expression>(arguments)); |
||||
} |
||||
} |
||||
#endif
|
||||
} |
||||
@ -0,0 +1,61 @@
@@ -0,0 +1,61 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.Ast; |
||||
|
||||
namespace ICSharpCode.NRefactory.AstBuilder |
||||
{ |
||||
#if NET35
|
||||
/// <summary>
|
||||
/// Extension methods for NRefactory.Ast.Expression.
|
||||
/// </summary>
|
||||
public static class StatementBuilder |
||||
{ |
||||
public static void AddStatement(this BlockStatement block, Statement statement) |
||||
{ |
||||
if (block == null) |
||||
throw new ArgumentNullException("block"); |
||||
if (statement == null) |
||||
throw new ArgumentNullException("statement"); |
||||
block.AddChild(statement); |
||||
statement.Parent = block; |
||||
} |
||||
|
||||
public static void AddStatement(this BlockStatement block, Expression expressionStatement) |
||||
{ |
||||
if (expressionStatement == null) |
||||
throw new ArgumentNullException("expressionStatement"); |
||||
AddStatement(block, new ExpressionStatement(expressionStatement)); |
||||
} |
||||
|
||||
public static void Throw(this BlockStatement block, Expression expression) |
||||
{ |
||||
if (expression == null) |
||||
throw new ArgumentNullException("expression"); |
||||
AddStatement(block, new ThrowStatement(expression)); |
||||
} |
||||
|
||||
public static void Return(this BlockStatement block, Expression expression) |
||||
{ |
||||
if (expression == null) |
||||
throw new ArgumentNullException("expression"); |
||||
AddStatement(block, new ReturnStatement(expression)); |
||||
} |
||||
|
||||
public static void Assign(this BlockStatement block, Expression left, Expression right) |
||||
{ |
||||
if (left == null) |
||||
throw new ArgumentNullException("left"); |
||||
if (right == null) |
||||
throw new ArgumentNullException("right"); |
||||
AddStatement(block, new AssignmentExpression(left, AssignmentOperatorType.Assign, right)); |
||||
} |
||||
} |
||||
#endif
|
||||
} |
||||
Loading…
Reference in new issue