PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Languages/IronPython/IronPythonTest/Conversions.cs

http://github.com/IronLanguages/main
C# | 93 lines | 55 code | 16 blank | 22 comment | 0 complexity | 9ef79811b456c8e01297f04c507812bb MD5 | raw file
Possible License(s): CPL-1.0, BSD-3-Clause, ISC, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. /* ****************************************************************************
  2. *
  3. * Copyright (c) Microsoft Corporation.
  4. *
  5. * This source code is subject to terms and conditions of the Apache License, Version 2.0. 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 Apache License, Version 2.0, please send an email to
  8. * ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. * by the terms of the Apache License, Version 2.0.
  10. *
  11. * You must not remove this notice, or any other, from this software.
  12. *
  13. *
  14. * ***************************************************************************/
  15. using System.Collections;
  16. using System.Collections.Generic;
  17. namespace IronPythonTest {
  18. /// <summary>
  19. /// Base used for implicit operator tests where the operator is defined
  20. /// on the "derived" class
  21. /// </summary>
  22. public class Base {
  23. public int value;
  24. public Base(int value) {
  25. this.value = value;
  26. }
  27. }
  28. public class Derived {
  29. public Derived(int value) {
  30. this.value = value;
  31. }
  32. public int value;
  33. public static implicit operator Base(Derived d) {
  34. return new Base(d.value);
  35. }
  36. }
  37. /// <summary>
  38. /// Base class used where the implicit operator is defined on the
  39. /// "base" class
  40. /// </summary>
  41. public class Base2 {
  42. public int value;
  43. public Base2(int value) {
  44. this.value = value;
  45. }
  46. public static implicit operator Base2(Derived2 d) {
  47. return new Base2(d.value);
  48. }
  49. }
  50. public class Derived2 {
  51. public int value;
  52. public Derived2(int value) {
  53. this.value = value;
  54. }
  55. }
  56. public class ConversionStorage {
  57. public Base Base;
  58. public Derived Derived;
  59. public Base2 Base2;
  60. public Derived2 Derived2;
  61. }
  62. public class DoubleToFloat {
  63. public static float ToFloat(double val) { return (float)val; }
  64. }
  65. public class DictConversion {
  66. public static IList<object> ToIDictionary(IDictionary dict) {
  67. List<object> res = new List<object>();
  68. foreach (DictionaryEntry de in dict) {
  69. res.Add(de.Key);
  70. }
  71. foreach (DictionaryEntry de in dict) {
  72. res.Add(de.Value);
  73. }
  74. return res;
  75. }
  76. }
  77. }