PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/DICK.B1/IronPython.Modules/xxsubtype.cs

https://bitbucket.org/williamybs/uidipythontool
C# | 108 lines | 68 code | 17 blank | 23 comment | 1 complexity | 8bf3f17e8b9bfecf14473624570ef842 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. using System;
  16. using System.Collections.Generic;
  17. using Microsoft.Scripting;
  18. using IronPython.Runtime;
  19. using IronPython.Runtime.Operations;
  20. using IronPython.Runtime.Types;
  21. [assembly: PythonModule("xxsubtype", typeof(IronPython.Modules.xxsubtype))]
  22. namespace IronPython.Modules {
  23. /// <summary>
  24. /// Samples on how to subtype built-in types from C#
  25. /// </summary>
  26. public static class xxsubtype {
  27. public const string __doc__ = "Provides samples on how to subtype built-in types from .NET.";
  28. [PythonType]
  29. public class spamlist : List {
  30. public spamlist()
  31. : base() {
  32. }
  33. public spamlist(object sequence)
  34. : base(sequence) {
  35. }
  36. private int _state;
  37. /// <summary>
  38. /// an int variable for demonstration purposes
  39. /// </summary>
  40. public int state {
  41. get {
  42. return _state;
  43. }
  44. set {
  45. _state = value;
  46. }
  47. }
  48. public int getstate() {
  49. return state;
  50. }
  51. public void setstate(int value) {
  52. state = value;
  53. }
  54. public static object staticmeth([ParamDictionary]IDictionary<object, object> dict, params object[] args) {
  55. return PythonTuple.MakeTuple(null, PythonTuple.MakeTuple(args), dict);
  56. }
  57. [ClassMethod]
  58. public static object classmeth(PythonType cls, [ParamDictionary]IDictionary<object, object> dict, params object[] args) {
  59. return PythonTuple.MakeTuple(cls, PythonTuple.MakeTuple(args), dict);
  60. }
  61. }
  62. [PythonType]
  63. public class spamdict : PythonDictionary {
  64. private int _state;
  65. /// <summary>
  66. /// an int variable for demonstration purposes
  67. /// </summary>
  68. public int state {
  69. get {
  70. return _state;
  71. }
  72. set {
  73. _state = value;
  74. }
  75. }
  76. public int getstate() {
  77. return state;
  78. }
  79. public void setstate(int value) {
  80. state = value;
  81. }
  82. }
  83. public static double bench(CodeContext context, object x, string name) {
  84. double start = PythonTime.clock();
  85. for (int i = 0; i < 1001; i++) {
  86. PythonOps.GetBoundAttr(context, x, name);
  87. }
  88. return PythonTime.clock() - start;
  89. }
  90. }
  91. }