本文整理汇总了C#中ExpressionList.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionList.Add方法的具体用法?C# ExpressionList.Add怎么用?C# ExpressionList.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionList
的用法示例。
在下文中一共展示了ExpressionList.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyToTest
public void CopyToTest()
{
ExpressionList<ConstantTypes.Integer> list = new ExpressionList<ConstantTypes.Integer>();
var zero = new ConstantTypes.Integer(0);
var one = new ConstantTypes.Integer(1);
list.Add(zero);
list.Add(one);
ConstantTypes.Integer[] array = new ConstantTypes.Integer[2];
list.CopyTo(array, 0);
Assert.IsTrue(array.Length == 2);
Assert.IsTrue(array[0] == zero);
Assert.IsTrue(array[1] == one);
}
示例2: AddTest
public void AddTest()
{
var list = new ExpressionList<ConstantTypes.Integer>();
var one = new ConstantTypes.Integer(1);
list.Add(one);
Assert.IsTrue(list.Contains(one));
}
示例3: SearchedCase
public SearchedCase(params KeyValuePair<Predicate, Expression>[] cases)
{
SearchCases = new ExpressionList<SearchedCaseExpression>();
foreach (var kvp in cases)
{
SearchCases.Add(new SearchedCaseExpression(kvp.Key, kvp.Value));
}
}
示例4: ClearTest
public void ClearTest()
{
var list = new ExpressionList<ConstantTypes.Integer>();
var one = new ConstantTypes.Integer(1);
list.Add(one);
Assert.IsTrue(list.Count == 1);
list.Clear();
Assert.IsTrue(list.Count == 0);
}
示例5: VisitRefTypeExpression
public override Expression VisitRefTypeExpression(RefTypeExpression reftypexp) {
if (reftypexp == null) return null;
Expression result = base.VisitRefTypeExpression (reftypexp);
if (result != reftypexp) return result;
UnaryExpression refanytype = new UnaryExpression(reftypexp.Operand, NodeType.Refanytype, SystemTypes.RuntimeTypeHandle, reftypexp.SourceContext);
ExpressionList arguments = new ExpressionList(1);
arguments.Add(refanytype);
MemberBinding mb = new MemberBinding(null, Runtime.GetTypeFromHandle);
return new MethodCall(mb, arguments, NodeType.Call, SystemTypes.Type);
}
示例6: Parse
ExpressionList Parse (int start, int end)
{
if (string.IsNullOrWhiteSpace (source))
return new ExpressionList ();
var ret = new ExpressionList ();
while (start < end) {
int bak = start;
ret.Add (ParseSingle (ref start, end));
if (bak == start)
throw new Exception ("Parser failed to progress token position: " + source);
}
return ret;
}
示例7: VisitExpressionList
public virtual ExpressionList VisitExpressionList(ExpressionList expressions, ExpressionList changes, ExpressionList deletions, ExpressionList insertions){
if (changes == null || deletions == null || insertions == null) return expressions;
int n = expressions == null ? 0 : expressions.Count;
if (n > changes.Count){Debug.Assert(false); n = changes.Count;}
if (n > deletions.Count){Debug.Assert(false); n = deletions.Count;}
if (n > insertions.Count){Debug.Assert(false); n = insertions.Count;}
if (expressions != null)
for (int i = 0; i < n; i++)
expressions[i] = this.VisitExpression(expressions[i], changes[i], deletions[i], insertions[i]);
ExpressionList result = new ExpressionList(insertions.Count-n);
for (int i = n, m = insertions.Count; i < m; i++)
result.Add(insertions[i]);
return result;
}
示例8: AddCallSerializer
void AddCallSerializer(TypeNode srcType, StatementList statements, Expression src, Identifier writer, Expression rootName, Expression rootNamespace ) {
TypeNode type = Unwrap(srcType);
Class memberSerializer = this.CreateSerializerFor(type);
// call the Serialize method on it, passing the member we're serializing.
ExpressionList args = new ExpressionList();
args.Add(src);
args.Add(writer);
args.Add(rootName);
args.Add(rootNamespace);
MethodCall call = new MethodCall();
Method serialize = memberSerializer.GetMethod(Identifier.For("Serialize"), new TypeNode[4] { type, Runtime.XmlSerializationWriter, SystemTypes.String, SystemTypes.String} );
call.Callee = new MemberBinding(new MemberBinding(null, memberSerializer), serialize);
call.Operands = args;
statements.Add( new ExpressionStatement( call ) );
}
示例9: AddCallDeserializer
void AddCallDeserializer(TypeNode type, StatementList statements, Identifier reader,
Expression target, Expression required, Expression result) {
Class memberSerializer = this.CreateSerializerFor(type);
// call the Deserialize method on it, and assign result to target object.
ExpressionList args = new ExpressionList();
args.Add(reader);
args.Add(required);
if (result is Local)
result = new UnaryExpression(result, NodeType.AddressOf);
args.Add(result);
MethodCall call = new MethodCall();
Method deserialize = memberSerializer.GetMethod(Identifier.For("Deserialize"), new TypeNode[3] { Runtime.XmlSerializationReader, SystemTypes.Boolean, SystemTypes.Boolean.GetReferenceType() } );
call.Callee = new MemberBinding(new MemberBinding(null, memberSerializer), deserialize);
call.Operands = args;
statements.Add(new AssignmentStatement(target, call));
}
示例10: AddError
void AddError(StatementList statements, Identifier reader, RuntimeError code, params Expression[] args) {
ExpressionList list = new ExpressionList();
list.Add(new Literal(code, Runtime.RuntimeError));
foreach (Expression e in args) list.Add(e);
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(reader, Identifier.For("Error")), list)));
}
示例11: AddReadOptional
void AddReadOptional(Block block, StatementList statements, Member mem, Expression target, Identifier reader, Expression result) {
TypeNode boxed = Checker.GetMemberType(mem);
TypeNode type = Checker.GetCollectionElementType(boxed);
statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(reader, Identifier.For("MoveToContent")), new ExpressionList())));
Local nameLocal = new Local(Identifier.For("name"),SystemTypes.String, block);
Local nsLocal = new Local(Identifier.For("ns"),SystemTypes.String, block);
statements.Add(new AssignmentStatement(nameLocal, new QualifiedIdentifier(reader, Identifier.For("LocalName"))));
statements.Add(new AssignmentStatement(nsLocal, new QualifiedIdentifier(reader, Identifier.For("NamespaceURI"))));
StringBuilder expecting = new StringBuilder();
Expression isFound = null;
if (mem.IsAnonymous) {
isFound = IsStartOf(block, type, statements, nameLocal, nsLocal, expecting);
} else {
ExpressionList args = new ExpressionList();
args.Add(new Literal(mem.Name.Name, SystemTypes.String));
isFound = new MethodCall(new QualifiedIdentifier(reader, Identifier.For("IsStartElement")), args);
}
StatementList trueStatements = new StatementList();
If ifIsFound = new If(isFound, new Block(trueStatements), null);
statements.Add(ifIsFound);
if (!AddReadSimpleType(type, trueStatements, reader, target, result, false)) {
Local localRequired = new Local(Identifier.Empty,SystemTypes.Boolean,block);
statements.Add(new AssignmentStatement(localRequired, Literal.True));
AddCallDeserializer(type, trueStatements, reader, target, localRequired, result);
}
}
示例12: VisitMethodCall
public override Expression VisitMethodCall(MethodCall call)
{
// We only reach this point for calls to predicate methods within "wait"
// join conditions.
ZMethod method = (ZMethod)((MemberBinding)call.Callee).BoundMember;
ExpressionList ctorArgs;
QualifiedIdentifier methodClass = new QualifiedIdentifier(
new QualifiedIdentifier(
new QualifiedIdentifier(Identifier.For("Z"), Identifier.For("Application")),
method.DeclaringType.Name),
method.Name);
MethodCall predCall =
new MethodCall(
new QualifiedIdentifier(Identifier.For("p"), Identifier.For("CallPredicateMethod")),
new ExpressionList(
new Construct(
new MemberBinding(null, new TypeExpression(methodClass)),
ctorArgs = new ExpressionList())));
ctorArgs.Add(Identifier.For("application"));
if (!method.IsStatic)
ctorArgs.Add(this.VisitExpression(((MemberBinding)call.Callee).TargetObject));
for (int i = 0, n = call.Operands.Count; i < n; i++)
ctorArgs.Add(this.VisitExpression(call.Operands[i]));
return predCall;
}
示例13: VisitBooleanExpression
public virtual Expression VisitBooleanExpression(Expression expr) {
UnaryExpression uexpr = expr as UnaryExpression;
if (uexpr != null && uexpr.NodeType == NodeType.LogicalNot) {
Expression e = uexpr.Operand = this.VisitBooleanExpression(uexpr.Operand);
if (e == null) return null;
MethodCall mcall = e as MethodCall;
if (mcall != null) {
MemberBinding mb = mcall.Callee as MemberBinding;
Member m = null;
if (mb == null || (m = mb.BoundMember) == null) return null;
if (m == this.GetTypeView(m.DeclaringType).GetOpTrue()) {
Method meth = this.GetTypeView(m.DeclaringType).GetOpFalse();
if (meth != null) {
mb.BoundMember = meth; return mcall;
}
} else if (m == this.GetTypeView(m.DeclaringType).GetOpFalse()) {
Method meth = this.GetTypeView(m.DeclaringType).GetOpTrue();
if (meth != null) {
mb.BoundMember = meth; return mcall;
}
}
}
} else
expr = this.VisitExpression(expr);
TypeNode eType = null;
if (expr == null || (eType = expr.Type) == null) return null;
if (!this.typeSystem.ImplicitCoercionFromTo(eType, SystemTypes.Boolean, this.TypeViewer)) {
Method opTrue = this.GetTypeView(eType).GetOpTrue();
if (opTrue != null) {
ExpressionList args = new ExpressionList(1);
args.Add(this.typeSystem.ImplicitCoercion(expr, opTrue.DeclaringType, this.TypeViewer));
return new MethodCall(new MemberBinding(null, opTrue), args, NodeType.Call, SystemTypes.Boolean, expr.SourceContext);
}
}
return this.typeSystem.ImplicitCoercion(expr, SystemTypes.Boolean, this.TypeViewer);
}
示例14: StringValueComparison
public virtual Expression StringValueComparison(BinaryExpression binaryExpression){
if (binaryExpression == null) return null;
ExpressionList arguments = new ExpressionList(2);
arguments.Add(binaryExpression.Operand1);
arguments.Add(binaryExpression.Operand2);
MethodCall mcall = new MethodCall(new MemberBinding(null, Runtime.StringEquals), arguments, NodeType.Call);
mcall.Type = SystemTypes.Boolean;
mcall.SourceContext = binaryExpression.SourceContext;
if (binaryExpression.NodeType == NodeType.Eq) return mcall;
UnaryExpression uex = new UnaryExpression(mcall, NodeType.LogicalNot);
uex.Type = SystemTypes.Boolean;
uex.SourceContext = binaryExpression.SourceContext;
return uex;
}
示例15: VisitBinaryExpression
public virtual Expression VisitBinaryExpression(BinaryExpression binaryExpression, Expression opnd1, Expression opnd2, TypeNode t1, TypeNode t2){
if (binaryExpression == null){Debug.Assert(false); return null;}
if (t1 == SystemTypes.String || t2 == SystemTypes.String) {
switch (binaryExpression.NodeType) {
case NodeType.Add:
if (opnd1 is Literal && opnd2 is Literal && t1 == SystemTypes.String && t2 == SystemTypes.String) {
string s1 = ((Literal)opnd1).Value as string;
string s2 = ((Literal)opnd2).Value as string;
return new Literal(s1 + s2, SystemTypes.String, binaryExpression.SourceContext);
}
Method operatorMethod = this.GetBinaryOperatorOverload(binaryExpression);
if (operatorMethod != null) break;
if (this.typeSystem.ImplicitCoercionFromTo(t1, SystemTypes.String, this.TypeViewer) && this.typeSystem.ImplicitCoercionFromTo(t2, SystemTypes.String, this.TypeViewer))
return new MethodCall(new MemberBinding(null, Runtime.StringConcatStrings), new ExpressionList(opnd1, opnd2),
NodeType.Call, SystemTypes.String, binaryExpression.SourceContext);
else
return new MethodCall(new MemberBinding(null, Runtime.StringConcatObjects), new ExpressionList(opnd1, opnd2),
NodeType.Call, SystemTypes.String, binaryExpression.SourceContext);
case NodeType.Eq:
case NodeType.Ne:
binaryExpression.Type = SystemTypes.Boolean;
if (t1 == SystemTypes.String && t2 == SystemTypes.String)
return this.StringValueComparison(binaryExpression);
else if (t1 == SystemTypes.Object || t2 == SystemTypes.Object)
return binaryExpression;
else
break;
}
}
if ((t1 is DelegateNode) && (t2 is DelegateNode) && t1 != t2 && (binaryExpression.NodeType == NodeType.Eq || binaryExpression.NodeType == NodeType.Ne)) {
this.HandleError(binaryExpression, Error.BadBinaryOps,
binaryExpression.NodeType == NodeType.Eq ? "==" : "!=", this.GetTypeName(t1), this.GetTypeName(t2));
return null;
}
if ((t1 != SystemTypes.Object && t2 != SystemTypes.Object) ||
!(binaryExpression.NodeType == NodeType.Eq || binaryExpression.NodeType == NodeType.Ne) ||
(t1.Template == SystemTypes.GenericBoxed || t2.Template == SystemTypes.GenericBoxed)){
Method operatorMethod = this.GetBinaryOperatorOverload(binaryExpression);
if (operatorMethod != null) {
MemberBinding callee = new MemberBinding(null, operatorMethod);
ExpressionList arguments = new ExpressionList(2);
if (t1 == SystemTypes.Delegate && t2 is DelegateNode && (binaryExpression.NodeType == NodeType.Eq || binaryExpression.NodeType == NodeType.Ne)) {
if (opnd1 is MemberBinding && ((MemberBinding)opnd1).BoundMember is Method)
opnd1 = this.VisitExpression(new Construct(new MemberBinding(null, t2), new ExpressionList(opnd1)));
}
arguments.Add(opnd1);
if (t1 is DelegateNode && t2 == SystemTypes.Delegate && (binaryExpression.NodeType == NodeType.Eq || binaryExpression.NodeType == NodeType.Ne)) {
if (opnd2 is MemberBinding && ((MemberBinding)opnd2).BoundMember is Method)
opnd2 = this.VisitExpression(new Construct(new MemberBinding(null, t1), new ExpressionList(opnd2)));
}
arguments.Add(opnd2);
MethodCall call = new MethodCall(callee, arguments);
call.SourceContext = binaryExpression.SourceContext;
call.Type = operatorMethod.ReturnType;
switch (binaryExpression.NodeType) {
case NodeType.LogicalAnd:
case NodeType.LogicalOr:
binaryExpression.Operand1 = new Local(call.Type);
binaryExpression.Operand2 = call;
binaryExpression.Type = call.Type;
return binaryExpression;
}
return call;
}else if ((t1 == SystemTypes.String || t2 == SystemTypes.String) &&
(binaryExpression.NodeType == NodeType.Eq || binaryExpression.NodeType == NodeType.Ne) &&
this.typeSystem.ImplicitCoercionFromTo(t1, SystemTypes.String, this.TypeViewer) &&
this.typeSystem.ImplicitCoercionFromTo(t2, SystemTypes.String, this.TypeViewer)){
return this.StringValueComparison(binaryExpression);
}
}
if (t1 is DelegateNode || t2 is DelegateNode){
if (binaryExpression.NodeType == NodeType.Add || binaryExpression.NodeType == NodeType.Sub) {
binaryExpression.Type = this.typeSystem.ImplicitCoercionFromTo(opnd1, t1, t2, this.TypeViewer) ? t2 : t1;
return binaryExpression;
}
}
if ((t1 is Pointer || t2 is Pointer) && (binaryExpression.NodeType == NodeType.Add || binaryExpression.NodeType == NodeType.Sub)){
TypeNode elementType = t1 is Pointer ? ((Pointer)t1).ElementType : ((Pointer)t2).ElementType;
Expression sizeOf = this.VisitUnaryExpression(new UnaryExpression(new Literal(elementType, SystemTypes.Type), NodeType.Sizeof, SystemTypes.UInt32));
if (binaryExpression.NodeType == NodeType.Sub) {
if (elementType == SystemTypes.Void) {
this.HandleError(binaryExpression, Error.VoidError);
return null;
}
if (t1 is Pointer && t2 is Pointer && ((Pointer)t1).ElementType == ((Pointer)t2).ElementType) {
binaryExpression.Operand1 = new BinaryExpression(opnd1, new Literal(SystemTypes.Int64, SystemTypes.Type), NodeType.ExplicitCoercion, SystemTypes.Int64, opnd1.SourceContext);
binaryExpression.Operand2 = new BinaryExpression(opnd2, new Literal(SystemTypes.Int64, SystemTypes.Type), NodeType.ExplicitCoercion, SystemTypes.Int64, opnd2.SourceContext);
binaryExpression.Type = SystemTypes.Int64;
return new BinaryExpression(binaryExpression, sizeOf, NodeType.Div, SystemTypes.Int64, binaryExpression.SourceContext);
}
}
if (!(t1 is Pointer && t2 is Pointer)) {
binaryExpression.Type = t1 is Pointer ? t1 : t2;
if (elementType == SystemTypes.Void) {
this.HandleError(binaryExpression, Error.VoidError);
return null;
}
sizeOf.Type = SystemTypes.IntPtr;
if (t1 is Pointer) {
Literal lit = binaryExpression.Operand2 as Literal;
//.........这里部分代码省略.........