private BindingRestrictions EnumRestrictions() { return(BindingRestrictions.GetTypeRestriction( Expression, typeof(ComTypeEnumDesc) ).Merge( // ((ComTypeEnumDesc)<arg>).TypeLib.Guid == <guid> BindingRestrictions.GetExpressionRestriction( Expression.Equal( Expression.Property( Expression.Property( Helpers.Convert(Expression, typeof(ComTypeEnumDesc)), typeof(ComTypeDesc).GetProperty(nameof(ComTypeDesc.TypeLib))), typeof(ComTypeLibDesc).GetProperty(nameof(ComTypeLibDesc.Guid))), Expression.Constant(_desc.TypeLib.Guid) ) ) ).Merge( BindingRestrictions.GetExpressionRestriction( Expression.Equal( Expression.Property( Helpers.Convert(Expression, typeof(ComTypeEnumDesc)), typeof(ComTypeEnumDesc).GetProperty(nameof(ComTypeEnumDesc.TypeName)) ), Expression.Constant(_desc.TypeName) ) ) )); }
public override DynamicMetaObject FallbackBinaryOperation(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion) { return(new DynamicMetaObject( Expression.Convert(Expression.Constant(3), typeof(object)), BindingRestrictions.GetExpressionRestriction(Expression.Constant(true)) )); }
/// <summary> /// Tries to perform binding of the dynamic Convert operation. /// </summary> /// <param name="binder">An instance of the <see cref="ConvertBinder"/> that represents the details of the dynamic operation.</param> /// <param name="instance">The target of the dynamic operation.</param> /// <param name="result">The new <see cref="DynamicMetaObject"/> representing the result of the binding.</param> /// <returns>true if operation was bound successfully; otherwise, false.</returns> public static bool TryConvert(ConvertBinder binder, DynamicMetaObject instance, out DynamicMetaObject result) { ContractUtils.RequiresNotNull(binder, "binder"); ContractUtils.RequiresNotNull(instance, "instance"); if (IsComObject(instance.Value)) { // Converting a COM object to any interface is always considered possible - it will result in // a QueryInterface at runtime if (binder.Type.IsInterface) { result = new DynamicMetaObject( Expression.Convert( instance.Expression, binder.Type ), BindingRestrictions.GetExpressionRestriction( Expression.Call( typeof(ComObject).GetMethod("IsComObject", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic), Helpers.Convert(instance.Expression, typeof(object)) ) ) ); return(true); } } result = null; return(false); }
public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder) { if (Value is KumaInstance) { // Check to see which method we should try to call var KumaName = InteropBinder.MapExpressionType(binder.Operation); if (KumaName == null) { return(InteropBinder.Unary.Bind(binder, this)); } if ( InteropBinder.InvokeMember.SearchForFunction(((KumaInstance)Value).Class, KumaName, (KumaInstance)Value, L(), true) != null) { return (InteropBinder.InvokeMember.Bind( new InteropBinder.InvokeMember(KumaName, new CallInfo(0), Scope), this, _DMO(DMO(Scope)))); } var clrName = InteropBinder.ToClrOperatorName(KumaName); if ( InteropBinder.InvokeMember.SearchForFunction(((KumaInstance)Value).Class, clrName, (KumaInstance)Value, L(), true) != null) { return(InteropBinder.Unary.Bind(binder, this)); } return(new DynamicMetaObject(Expression.Constant(null), BindingRestrictions.GetExpressionRestriction(Expression.Constant(true)))); } return(InteropBinder.Unary.Bind(binder, this)); }
private BindingRestrictions EnumRestrictions() { return(BindingRestrictionsHelpers.GetRuntimeTypeRestriction( Expression, typeof(ComTypeEnumDesc) ).Merge( // ((ComTypeEnumDesc)<arg>).TypeLib.Guid == <guid> BindingRestrictions.GetExpressionRestriction( Expression.Equal( Expression.Property( Expression.Property( AstUtils.Convert(Expression, typeof(ComTypeEnumDesc)), typeof(ComTypeDesc).GetProperty("TypeLib")), typeof(ComTypeLibDesc).GetProperty("Guid")), AstUtils.Constant(_desc.TypeLib.Guid) ) ) ).Merge( BindingRestrictions.GetExpressionRestriction( Expression.Equal( Expression.Property( AstUtils.Convert(Expression, typeof(ComTypeEnumDesc)), typeof(ComTypeEnumDesc).GetProperty("TypeName") ), AstUtils.Constant(_desc.TypeName) ) ) )); }
public BindingRestrictions GetRestriction(Expression codeContext) { BindingRestrictions extCheck; if (_id == ExtensionMethodSet.OutOfIds) { extCheck = BindingRestrictions.GetInstanceRestriction( Expression.Call( typeof(PythonOps).GetMethod(nameof(PythonOps.GetExtensionMethodSet)), codeContext ), this ); } else { extCheck = BindingRestrictions.GetExpressionRestriction( Expression.Call( typeof(PythonOps).GetMethod(nameof(PythonOps.IsExtensionSet)), codeContext, Expression.Constant(_id) ) ); } return(extCheck); }
internal static BindingRestrictions PSGetMethodArgumentRestriction(this DynamicMetaObject obj) { BindingRestrictions typeRestriction; Expression expression; object obj2 = PSObject.Base(obj.Value); if ((obj2 == null) || !obj2.GetType().Equals(typeof(object[]))) { return(obj.PSGetTypeRestriction()); } Type type = Adapter.EffectiveArgumentType(obj.Value); MethodInfo method = !type.Equals(typeof(object[])) ? CachedReflectionInfo.PSInvokeMemberBinder_IsHomogenousArray.MakeGenericMethod(new Type[] { type.GetElementType() }) : CachedReflectionInfo.PSInvokeMemberBinder_IsHeterogeneousArray; if (obj.Value != obj2) { typeRestriction = BindingRestrictions.GetTypeRestriction(obj.Expression, typeof(PSObject)); ParameterExpression left = Expression.Variable(typeof(object[])); expression = Expression.Block(new ParameterExpression[] { left }, new Expression[] { Expression.Assign(left, Expression.TypeAs(Expression.Call(CachedReflectionInfo.PSObject_Base, obj.Expression), typeof(object[]))), Expression.AndAlso(Expression.NotEqual(left, ExpressionCache.NullObjectArray), Expression.Call(method, left)) }); } else { typeRestriction = BindingRestrictions.GetTypeRestriction(obj.Expression, typeof(object[])); Expression expression3 = obj.Expression.Cast(typeof(object[])); expression = Expression.Call(method, expression3); } return(typeRestriction.Merge(BindingRestrictions.GetExpressionRestriction(expression))); }
/// <summary> /// Map関数を呼び出す。 /// </summary> /// <param name="target">関数</param> /// <param name="arg">リスト</param> /// <param name="errorSuggestion"></param> /// <returns>リスト</returns> public override DynamicMetaObject FallbackBinaryOperation(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion) { Expression expr = null; Expression rest = null; var funcType = typeof(Func <object, object>); if (target.LimitType == funcType) { var funcExpr = BinderHelper.Wrap(target.Expression, funcType); expr = ExpressionHelper.BetaReduction <Func <object, object>, object, object>( (func, lst) => ListLib.Map(func, lst), funcExpr, arg.Expression); rest = Expression.TypeIs(target.Expression, funcType); } funcType = typeof(SuffixFunc <Func <object, object> >); if (target.LimitType == funcType) { expr = ExpressionHelper.BetaReduction <SuffixFunc <Func <object, object> >, object, object>( (sfxFunc, lst) => ListLib.Map(sfxFunc.Func, lst), BinderHelper.Wrap(target.Expression, funcType), arg.Expression); rest = Expression.TypeIs(target.Expression, funcType); } // ----- ----- ----- return ----- ----- ----- if (expr != null && rest != null) { return(new DynamicMetaObject( BinderHelper.Wrap(expr, this.ReturnType), BindingRestrictions.GetExpressionRestriction(rest))); } else { return(ThrowArgumentException( target.LimitType + "を用いて射影(それぞれ)できません。", BindingRestrictions.GetTypeRestriction(target.Expression, target.LimitType))); } }
public override DynamicMetaObject FallbackBinaryOperation(DynamicMetaObject left, DynamicMetaObject right, DynamicMetaObject errorSuggestion) { Expression expr; BindingRestrictions rest; if (left.Value == null) { expr = BinderHelper.Wrap(right.Expression, this.ReturnType); rest = BindingRestrictions.GetExpressionRestriction(BinderHelper.IsNull(left.Expression)); } else if (left.LimitType == typeof(bool)) { expr = BinderHelper.Wrap( Expression.Condition(BinderHelper.Wrap(left.Expression, typeof(bool)), left.Expression, right.Expression), this.ReturnType); rest = BindingRestrictions.GetTypeRestriction(left.Expression, typeof(bool)); } else { expr = BinderHelper.Wrap(left.Expression, this.ReturnType); rest = BindingRestrictions.GetExpressionRestriction( Expression.AndAlso( BinderHelper.IsNotNull(left.Expression), Expression.Not(Expression.TypeIs(left.Expression, typeof(bool))))); } return(new DynamicMetaObject(expr, rest)); }
private DynamicMetaObject TryBindGetMember(string name) { if (_lib.HasMember(name)) { BindingRestrictions restrictions = BindingRestrictions.GetTypeRestriction( Expression, typeof(ComTypeLibDesc) ).Merge( BindingRestrictions.GetExpressionRestriction( Expression.Equal( Expression.Property( AstUtils.Convert( Expression, typeof(ComTypeLibDesc) ), typeof(ComTypeLibDesc).GetProperty(nameof(ComTypeLibDesc.Guid)) ), Expression.Constant(_lib.Guid) ) ) ); return(new DynamicMetaObject( Expression.Constant( ((ComTypeLibDesc)Value).GetTypeLibObjectDesc(name) ), restrictions )); } return(null); }
public void MergeCombinesDeeper() { foreach (bool w in new[] { false, true }) { BindingRestrictions bW = BindingRestrictions.GetExpressionRestriction(Expression.Constant(w)); foreach (bool x in new[] { false, true }) { BindingRestrictions bX = BindingRestrictions.GetExpressionRestriction(Expression.Constant(x)); foreach (bool y in new[] { false, true }) { BindingRestrictions bY = BindingRestrictions.GetExpressionRestriction(Expression.Constant(y)); BindingRestrictions merged = bW.Merge(bX).Merge(bY); Assert.Equal(w & x & y, Expression.Lambda <Func <bool> >(merged.ToExpression()).Compile()()); foreach (bool z in new[] { false, true }) { BindingRestrictions bZ = BindingRestrictions.GetExpressionRestriction( Expression.Constant(z)); merged = bW.Merge(bX).Merge(bY).Merge(bZ); Assert.Equal( w & x & y & z, Expression.Lambda <Func <bool> >(merged.ToExpression()).Compile()()); } } } } }
private static DynamicMetaObject ConstantDynamicMetaObject(string output) { var expr = Expression.Constant(output); var restriction = BindingRestrictions.GetExpressionRestriction(Constants.True); return(new DynamicMetaObject(expr, restriction, output)); }
public override DynamicMetaObject FallbackUnaryOperation(DynamicMetaObject target, DynamicMetaObject errorSuggestion) { const string errorMsg = "{0}を符号反転出来ません。"; if (target.Value == null) { var msg = String.Format(errorMsg, ConstantNames.NullText); var ctorInfo = typeof(InvalidOperationException).GetConstructor(new[] { typeof(string) }); var expr = Expression.Throw(Expression.New(ctorInfo, Expression.Constant(errorMsg)), this.ReturnType); var rest = BindingRestrictions.GetExpressionRestriction(BinderHelper.IsNull(target.Expression)); return(new DynamicMetaObject(expr, rest)); } try { var expr = BinderHelper.Wrap(Expression.Negate(Expression.Convert(target.Expression, target.LimitType)), this.ReturnType); var rest = BindingRestrictions.GetTypeRestriction(target.Expression, target.LimitType); return(new DynamicMetaObject(expr, rest)); } catch (InvalidOperationException) { var msgExpr = ExpressionHelper.BetaReduction <string, object, string>( (format, obj) => String.Format(format, obj), Expression.Constant(errorMsg), target.Expression); var ctorInfo = typeof(InvalidOperationException).GetConstructor(new[] { typeof(string) }); var expr = Expression.Throw(Expression.New(ctorInfo, msgExpr), this.ReturnType); var rest = BindingRestrictions.GetTypeRestriction(target.Expression, target.LimitType); return(new DynamicMetaObject(expr, rest)); } }
internal static DynamicMetaObject /*!*/ ConvertComArgument(DynamicMetaObject /*!*/ arg) { Expression expr = arg.Expression; BindingRestrictions restrictions; if (arg.Value != null) { Type type = arg.Value.GetType(); if (type == typeof(BigInteger)) { expr = Ast.Convert(AstUtils.Convert(arg.Expression, typeof(BigInteger)), typeof(double)); } else if (type == typeof(MutableString)) { // TODO: encoding? expr = Ast.Convert(AstUtils.Convert(arg.Expression, typeof(MutableString)), typeof(string)); } else if (type == typeof(RubySymbol)) { // TODO: encoding? expr = Ast.Convert(AstUtils.Convert(arg.Expression, typeof(RubySymbol)), typeof(string)); } restrictions = BindingRestrictions.GetTypeRestriction(arg.Expression, type); } else { restrictions = BindingRestrictions.GetExpressionRestriction(Ast.Equal(arg.Expression, AstUtils.Constant(null))); } return(arg.Clone(expr, restrictions)); }
public void MergedRestrictionsProperties() { var exps = new Expression[] { Expression.Constant(false), Expression.Constant(true), Expression.Equal(Expression.Constant(2), Expression.Constant(3)) }; BindingRestrictions br = BindingRestrictions.Empty; var restrictions = new List <BindingRestrictions>(); foreach (var exp in exps) { BindingRestrictions res = BindingRestrictions.GetExpressionRestriction(exp); restrictions.Add(res); br = br.Merge(res); } if (BindingRestrictionsDebugViewType == null) { throw new SkipTestException("Didn't find DebuggerTypeProxyAttribute on BindingRestrictions."); } BindingRestrictionsProxyProxy view = GetDebugViewObject(br); Assert.False(view.IsEmpty); Assert.Equal(br.ToExpression().ToString(), view.ToString()); BindingRestrictions[] viewedRestrictions = view.Restrictions; // Check equal to source restrictions, but not insisting on order. Assert.Equal(3, viewedRestrictions.Length); Assert.True(viewedRestrictions.All(r => restrictions.Contains(r))); }
internal BindingRestrictions NotInstanceMember(DynamicMetaObject target) { ParameterExpression expression = Expression.Variable(typeof(PSMemberInfo)); MethodCallExpression expression2 = Expression.Call(CachedReflectionInfo.PSGetMemberBinder_TryGetInstanceMember, target.Expression.Cast(typeof(object)), Expression.Constant(base.Name), expression); return(BindingRestrictions.GetExpressionRestriction(Expression.Block(new ParameterExpression[] { expression }, new Expression[] { Expression.Not(expression2) }))); }
public void MergedRestrictionsProperties() { var exps = new Expression[] { Expression.Constant(false), Expression.Constant(true), Expression.Equal(Expression.Constant(2), Expression.Constant(3)) }; var br = BindingRestrictions.Empty; var restrictions = new List <BindingRestrictions>(); foreach (var exp in exps) { var res = BindingRestrictions.GetExpressionRestriction(exp); restrictions.Add(res); br = br.Merge(res); } var view = GetDebugViewObject(br); Assert.False(view.IsEmpty); Assert.Equal(br.ToExpression().ToString(), view.ToString()); var viewedRestrictions = view.Restrictions; // Check equal to source restrictions, but not insisting on order. Assert.Equal(3, viewedRestrictions.Length); Assert.True(viewedRestrictions.All(r => restrictions.Contains(r))); }
/// <summary> /// 左辺、右辺ともに、nullだった場合 /// </summary> private DynamicMetaObject CompareBotheNull(DynamicMetaObject left, DynamicMetaObject right) { Contract.Requires <ArgumentException>(left.Value == null); Contract.Requires <ArgumentException>(right.Value == null); Expression value = null; switch (this.Operation) { case ExpressionType.LessThan: case ExpressionType.GreaterThan: value = Expression.Constant(false); break; case ExpressionType.LessThanOrEqual: case ExpressionType.GreaterThanOrEqual: value = Expression.Constant(true); break; } var expr = BinderHelper.Wrap(value, this.ReturnType); var rest = BindingRestrictions.GetExpressionRestriction( Expression.And( BinderHelper.IsNull(left.Expression), BinderHelper.IsNull(right.Expression))); return(new DynamicMetaObject(expr, rest)); }
public void CustomRestrictionsNotEqualIfExpressionsNotSame() { BindingRestrictions x = BindingRestrictions.GetExpressionRestriction(Expression.Constant(false)); BindingRestrictions y = BindingRestrictions.GetExpressionRestriction(Expression.Constant(false)); Assert.NotEqual(x, y); }
public override DynamicMetaObject FallbackUnaryOperation(DynamicMetaObject target, DynamicMetaObject errorSuggestion) { Expression boolExpr; BindingRestrictions rest; if (target.Value == null) { boolExpr = Expression.Constant(true); rest = BindingRestrictions.GetExpressionRestriction(BinderHelper.IsNull(target.Expression)); } else if (target.LimitType == typeof(bool)) { boolExpr = Expression.Not(BinderHelper.Wrap(target.Expression, typeof(bool))); rest = BindingRestrictions.GetTypeRestriction(target.Expression, typeof(bool)); } else { boolExpr = Expression.Constant(false); rest = BindingRestrictions.GetExpressionRestriction( Expression.AndAlso( BinderHelper.IsNotNull(target.Expression), Expression.Not(Expression.TypeIs(target.Expression, typeof(bool))))); } var expr = BinderHelper.Wrap(boolExpr, this.ReturnType); return(new DynamicMetaObject(expr, rest)); }
/// <summary> /// 左辺か右辺のいずれかがnullの場合の比較 /// </summary> private DynamicMetaObject FallbackOnNull(DynamicMetaObject left, DynamicMetaObject right) { bool value = this.Operation == ExpressionType.Equal; Expression restExpr = null; if (left.Value == null && right.Value == null) { restExpr = Expression.And( BinderHelper.IsNull(left.Expression), BinderHelper.IsNull(right.Expression)); } else if (left.Value == null) { value ^= true; restExpr = Expression.AndAlso( BinderHelper.IsNull(left.Expression), BinderHelper.IsNotNull(right.Expression)); } else { value ^= true; restExpr = Expression.AndAlso( BinderHelper.IsNull(right.Expression), BinderHelper.IsNotNull(left.Expression)); } var expr = BinderHelper.Wrap(Expression.Constant(value), this.ReturnType); var rest = BindingRestrictions.GetExpressionRestriction(restExpr); return(new DynamicMetaObject(expr, rest)); }
internal static BindingRestrictions PSGetTypeRestriction(this DynamicMetaObject obj) { if (obj.Restrictions != BindingRestrictions.Empty) { return(obj.Restrictions); } if (obj.Value == null) { return(BindingRestrictions.GetInstanceRestriction(obj.Expression, null)); } object obj2 = PSObject.Base(obj.Value); if (obj2 == null) { return(BindingRestrictions.GetExpressionRestriction(Expression.Equal(obj.Expression, Expression.Constant(AutomationNull.Value)))); } BindingRestrictions typeRestriction = BindingRestrictions.GetTypeRestriction(obj.Expression, obj.LimitType); if (obj.Value != obj2) { return(typeRestriction.Merge(BindingRestrictions.GetTypeRestriction(Expression.Call(CachedReflectionInfo.PSObject_Base, obj.Expression), obj2.GetType()))); } if (obj2 is PSObject) { typeRestriction = typeRestriction.Merge(BindingRestrictions.GetExpressionRestriction(Expression.Equal(Expression.Call(CachedReflectionInfo.PSObject_Base, obj.Expression), obj.Expression))); } return(typeRestriction); }
public void ExpressionRestrictionFromNonBooleanExpression() { AssertExtensions.Throws <ArgumentException>( "expression", () => BindingRestrictions.GetExpressionRestriction(Expression.Empty())); AssertExtensions.Throws <ArgumentException>( "expression", () => BindingRestrictions.GetExpressionRestriction(Expression.Constant(""))); }
MethodBase[] ResolveMethods(DynamicMetaObject ctx, string name, string nameOpt, ref BindingRestrictions restrictions) { var ctxInstance = (Context)ctx.Value; var routine = ctxInstance.GetDeclaredFunction(name) ?? ((nameOpt != null) ? ctxInstance.GetDeclaredFunction(nameOpt) : null); if (routine is Reflection.PhpRoutineInfo) { var phproutine = (Reflection.PhpRoutineInfo)routine; // restriction: ctx.CheckFunctionDeclared(index, handle) var checkExpr = Expression.Call( ctx.Expression, typeof(Context).GetMethod("CheckFunctionDeclared", typeof(int), typeof(RuntimeMethodHandle)), Expression.Constant(phproutine.Index), Expression.Constant(phproutine.Handle)); Combine(ref restrictions, BindingRestrictions.GetExpressionRestriction(checkExpr)); // return(new[] { MethodBase.GetMethodFromHandle(phproutine.Handle) }); } else if (routine == null) { return(null); } // CLR routines persists across whole app, no restriction needed // return(routine.Handles.Select(MethodBase.GetMethodFromHandle).ToArray()); }
public void MergeWithSelfHasSameExpression() { Expression exp = Expression.Constant(true); BindingRestrictions allowAll = BindingRestrictions.GetExpressionRestriction(exp); BindingRestrictions doubled = allowAll.Merge(allowAll); Assert.Same(exp, doubled.ToExpression()); }
public static DynamicMetaObject CheckTargetNullReference(DynamicMetaObject target, string context) { return(CreateThrow( target, null, BindingRestrictions.GetExpressionRestriction(Expression.Equal(Expression.Constant(null, typeof(object)), target.Expression)), typeof(NullReferenceException), context)); }
private DynamicMetaObject InvokeWorker(DynamicMetaObjectBinder /*!*/ callAction, DynamicMetaObject /*!*/[] args) { PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "Method Invoke " + args.Length); PerfTrack.NoteEvent(PerfTrack.Categories.BindingTarget, "Method"); CallSignature signature = BindingHelpers.GetCallSignature(callAction); DynamicMetaObject self = Restrict(typeof(Method)); BindingRestrictions restrictions = self.Restrictions; // restrict to non-null self (Method is immutable so this is an invariant test) restrictions = restrictions.Merge( BindingRestrictions.GetExpressionRestriction( Ast.NotEqual( GetSelfExpression(self), AstUtils.Constant(null) ) ) ); DynamicMetaObject[] newArgs = ArrayUtils.Insert(GetMetaFunction(self), GetMetaSelf(self), args); var newSig = new CallSignature(ArrayUtils.Insert(new Argument(ArgumentType.Simple), signature.GetArgumentInfos())); var call = new DynamicMetaObject( DynamicExpression.Dynamic( PythonContext.GetPythonContext(callAction).Invoke( newSig ).GetLightExceptionBinder(callAction.SupportsLightThrow()), typeof(object), ArrayUtils.Insert(PythonContext.GetCodeContext(callAction), DynamicUtils.GetExpressions(newArgs)) ), BindingRestrictions.Empty ); /* * call = func.Invoke( * new CallBinder( * PythonContext.GetBinderState(callAction), * newSig * ), * newArgs * );*/ if (call.HasValue) { return(new DynamicMetaObject( call.Expression, restrictions.Merge(call.Restrictions), call.Value )); } else { return(new DynamicMetaObject( call.Expression, restrictions.Merge(call.Restrictions) )); } }
public void MergedRestrictionsExpressions() { var exps = new Expression[] { Expression.Constant(false), Expression.Constant(true), Expression.Equal(Expression.Constant(2), Expression.Constant(3)) }; BindingRestrictions br = BindingRestrictions.Empty; foreach (var exp in exps) { br = br.Merge(BindingRestrictions.GetExpressionRestriction(exp)); } if (BindingRestrictionsDebugViewType == null) { return; } BindingRestrictionsProxyProxy view = GetDebugViewObject(br); // The expression in the view will be a tree of AndAlso nodes. // If we examine the expression of the restriction a new AndAlso // will be created, so we strip out the leaf expressions and compare // with the initial set. var notAndAlso = new List <Expression>(); Expression vExp = view.Test; Assert.Equal(ExpressionType.AndAlso, vExp.NodeType); Stack <Expression> toSplit = new Stack <Expression>(); for (;;) { if (vExp.NodeType == ExpressionType.AndAlso) { var bin = (BinaryExpression)vExp; toSplit.Push(bin.Left); vExp = bin.Right; } else { notAndAlso.Add(vExp); if (toSplit.Count == 0) { break; } vExp = toSplit.Pop(); } } // Check equal to source expressions, but not insisting on order. Assert.Equal(3, notAndAlso.Count); Assert.True(notAndAlso.All(ex => exps.Contains(ex))); }
private BindingRestrictions CreateRestrictions() { if (typeof(Expression).IsAssignableFrom(Expression.Type)) { return(BindingRestrictions.Empty); } return(BindingRestrictions.GetExpressionRestriction(Expression.TypeIs(Expression, typeof(ISupplier <Expression>)))); }
public override BindingRestrictions GetRestrictions() { if (_type == typeof(DynamicNull)) { return(BindingRestrictions.GetExpressionRestriction(Expression.Equal(ArgumentExpression, Expression.Constant(null)))); } return(BindingRestrictions.GetTypeRestriction(ArgumentExpression, _type)); }