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, IEnumerable arguments ) : DynamicExpression
binder CallSiteBinder The runtime binder for the dynamic operation.
returnType Type The result type of the dynamic expression.
arguments IEnumerable The arguments to the dynamic operation.
return DynamicExpression
        public static DynamicExpression Dynamic(CallSiteBinder binder, Type returnType, IEnumerable<Expression> arguments)
        {
            ContractUtils.RequiresNotNull(arguments, nameof(arguments));
            ContractUtils.RequiresNotNull(returnType, nameof(returnType));

            var args = arguments.ToReadOnly();
            ContractUtils.RequiresNotEmpty(args, nameof(args));
            return MakeDynamic(binder, returnType, args);
        }

Same methods

Expression::Dynamic ( CallSiteBinder binder, Type returnType ) : DynamicExpression
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

Usage Example

コード例 #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