System.Linq.Expressions.Expression.Dynamic C# (CSharp) Method

Dynamic() public static method

Creates a DynamicExpression that represents a dynamic operation bound by the provided CallSiteBinder.
The DelegateType property of the result will be inferred from the types of the arguments and the specified return type.
public static Dynamic ( CallSiteBinder binder, Type returnType ) : DynamicExpression
binder CallSiteBinder The runtime binder for the dynamic operation.
returnType Type The result type of the dynamic expression.
return DynamicExpression
        public static DynamicExpression Dynamic(CallSiteBinder binder, Type returnType, params Expression[] arguments)
        {
            return Dynamic(binder, returnType, (IEnumerable<Expression>)arguments);
        }

Same methods

Expression::Dynamic ( CallSiteBinder binder, Type returnType, Expression arg0 ) : DynamicExpression
Expression::Dynamic ( CallSiteBinder binder, Type returnType, Expression arg0, Expression arg1 ) : DynamicExpression
Expression::Dynamic ( CallSiteBinder binder, Type returnType, Expression arg0, Expression arg1, Expression arg2 ) : DynamicExpression
Expression::Dynamic ( CallSiteBinder binder, Type returnType, Expression arg0, Expression arg1, Expression arg2, Expression arg3 ) : DynamicExpression
Expression::Dynamic ( CallSiteBinder binder, Type returnType, IEnumerable arguments ) : DynamicExpression

Usage Example

Ejemplo n.º 1
0
        private object CastResult(object result, Type targetType)
        {
            if (result == null || result == DependencyProperty.UnsetValue || result == System.Windows.Data.Binding.DoNothing || targetType == null || targetType == typeof(object))
            {
                return(result);
            }

            if (targetType == typeof(string))
            {
                return(result.ToString());
            }

            Func <object, object> cast;

            if (!castFunctions.TryGetValue(targetType, out cast))
            {
                ParameterExpression par = Expression.Parameter(typeof(object));
                cast = Expression.Lambda <Func <object, object> >(Expression.Convert(Expression.Dynamic(Binder.Convert(CSharpBinderFlags.ConvertExplicit, targetType, typeof(object)), targetType, par), typeof(object)), par).Compile();
                castFunctions.TryAdd(targetType, cast);
            }
            if (cast != null)
            {
                try
                {
                    result = cast(result);
                }
                catch
                {
                    castFunctions[targetType] = null;
                }
            }
            return(result);
        }
All Usage Examples Of System.Linq.Expressions.Expression::Dynamic
Expression