PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/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. #if CODEPLEX_40
  16. using System;
  17. #else
  18. using System; using Microsoft;
  19. #endif
  20. using System.Collections.Generic;
  21. #if CODEPLEX_40
  22. using System.Dynamic;
  23. using System.Linq.Expressions;
  24. #else
  25. using Microsoft.Scripting;
  26. using Microsoft.Linq.Expressions;
  27. #endif
  28. using System.Reflection;
  29. using Microsoft.Scripting.Utils;
  30. namespace Microsoft.Scripting.Actions.Calls {
  31. /// <summary>
  32. /// Helper class for emitting calls via the MethodBinder.
  33. /// </summary>
  34. public class ParameterBinder {
  35. private readonly ActionBinder _actionBinder;
  36. private List<ParameterExpression> _temps;
  37. public ParameterBinder(ActionBinder actionBinder) {
  38. Assert.NotNull(actionBinder);
  39. _actionBinder = actionBinder;
  40. }
  41. public ActionBinder Binder {
  42. get { return _actionBinder; }
  43. }
  44. internal List<ParameterExpression> Temps {
  45. get { return _temps; }
  46. }
  47. internal ParameterExpression GetTemporary(Type type, string name) {
  48. Assert.NotNull(type);
  49. if (_temps == null) {
  50. _temps = new List<ParameterExpression>();
  51. }
  52. ParameterExpression res = Expression.Variable(type, name);
  53. _temps.Add(res);
  54. return res;
  55. }
  56. public virtual Expression ConvertExpression(Expression expr, ParameterInfo info, Type toType) {
  57. Assert.NotNull(expr, toType);
  58. return _actionBinder.ConvertExpression(expr, toType, ConversionResultKind.ExplicitCast, null);
  59. }
  60. public virtual Func<object[], object> ConvertObject(int index, DynamicMetaObject knownType, ParameterInfo info, Type toType) {
  61. throw new NotImplementedException();
  62. }
  63. public virtual Expression GetDynamicConversion(Expression value, Type type) {
  64. return Expression.Dynamic(OldConvertToAction.Make(_actionBinder, type), type, value);
  65. }
  66. }
  67. }