PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 36ms app.codeStats 1ms

/Microsoft.Scripting/Actions/Calls/ParameterBinder.cs

https://bitbucket.org/stefanrusek/xronos
C# | 81 lines | 50 code | 14 blank | 17 comment | 2 complexity | e761e8f03635b737ad5d99feca194f08 MD5 | raw file
 1/* ****************************************************************************
 2 *
 3 * Copyright (c) Microsoft Corporation. 
 4 *
 5 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 6 * copy of the license can be found in the License.html file at the root of this distribution. If 
 7 * you cannot locate the  Microsoft Public License, please send an email to 
 8 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 9 * by the terms of the Microsoft Public License.
10 *
11 * You must not remove this notice, or any other, from this software.
12 *
13 *
14 * ***************************************************************************/
15
16#if CODEPLEX_40
17using System;
18#else
19using System; using Microsoft;
20#endif
21using System.Collections.Generic;
22#if CODEPLEX_40
23using System.Dynamic;
24using System.Linq.Expressions;
25#else
26using Microsoft.Scripting;
27using Microsoft.Linq.Expressions;
28#endif
29using System.Reflection;
30using Microsoft.Scripting.Utils;
31
32namespace Microsoft.Scripting.Actions.Calls {
33    /// <summary>
34    /// Helper class for emitting calls via the MethodBinder.
35    /// </summary>
36    public class ParameterBinder {
37        private readonly ActionBinder _actionBinder;
38        private List<ParameterExpression> _temps;
39
40        public ParameterBinder(ActionBinder actionBinder) {
41            Assert.NotNull(actionBinder);
42
43            _actionBinder = actionBinder;
44        }
45
46        public ActionBinder Binder {
47            get { return _actionBinder; }
48        }
49
50        internal List<ParameterExpression> Temps {
51            get { return _temps; }
52        }
53
54        internal ParameterExpression GetTemporary(Type type, string name) {
55            Assert.NotNull(type);
56
57            if (_temps == null) {
58                _temps = new List<ParameterExpression>();
59            }
60
61            ParameterExpression res = Expression.Variable(type, name);
62            _temps.Add(res);
63            return res;
64        }
65
66        public virtual Expression ConvertExpression(Expression expr, ParameterInfo info, Type toType) {
67            Assert.NotNull(expr, toType);
68
69            return _actionBinder.ConvertExpression(expr, toType, ConversionResultKind.ExplicitCast, null);
70        }
71
72        public virtual Func<object[], object> ConvertObject(int index, DynamicMetaObject knownType, ParameterInfo info, Type toType) {
73            throw new NotImplementedException();
74        }
75
76        public virtual Expression GetDynamicConversion(Expression value, Type type) {
77            return Expression.Dynamic(OldConvertToAction.Make(_actionBinder, type), type, value);
78        }
79    }
80
81}