PageRenderTime 29ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Test/ClrAssembly/Src/indexerdefinitionsvb.vb

http://github.com/IronLanguages/main
Visual Basic | 156 lines | 117 code | 19 blank | 20 comment | 0 complexity | 7fc7bf4c5c6bb44d7d037d718077633b 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. Imports System.Reflection
  16. Namespace Merlin.Testing.Indexer
  17. Public Class ClassWithIndexer
  18. Private array As Integer()
  19. Sub Init()
  20. array = New Integer() {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
  21. End Sub
  22. Public Property PropertyName(ByVal arg As Integer) As Integer
  23. Get
  24. Return array(arg)
  25. End Get
  26. Set(ByVal value As Integer)
  27. array(arg) = value
  28. End Set
  29. End Property
  30. End Class
  31. Public Structure StructWithIndexer
  32. Private array As Integer()
  33. Sub Init()
  34. array = New Integer() {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
  35. End Sub
  36. Public Property PropertyName(ByVal arg As Integer) As Integer
  37. Get
  38. Return array(arg)
  39. End Get
  40. Set(ByVal value As Integer)
  41. array(arg) = value
  42. End Set
  43. End Property
  44. End Structure
  45. Public Class ClassWithSignature
  46. Private array As Integer() = New Integer() {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
  47. Public Property PropertyName(ByVal arg1 As Integer, Optional ByVal arg2 As Integer = 2) As Integer
  48. Get
  49. Return array(arg1 + arg2)
  50. End Get
  51. Set(ByVal value As Integer)
  52. array(arg1 + arg2) = value
  53. End Set
  54. End Property
  55. End Class
  56. Public Class ClassWithOnlyOptional
  57. Private array As Integer() = New Integer() {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
  58. Public Property PropertyName(Optional ByVal arg As Integer = 2) As Integer
  59. Get
  60. Return array(arg)
  61. End Get
  62. Set(ByVal value As Integer)
  63. array(arg) = value
  64. End Set
  65. End Property
  66. End Class
  67. Public Class ClassWithOnlyParamArray
  68. Private saved As Integer = -99
  69. Private array As Integer() = New Integer() {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
  70. Public Property PropertyName(ByVal ParamArray arg As Integer()) As Integer
  71. Get
  72. If arg.Length = 0 Then
  73. Return saved
  74. Else
  75. Return array(arg(0))
  76. End If
  77. End Get
  78. Set(ByVal value As Integer)
  79. If arg.Length = 0 Then
  80. saved = value
  81. Else
  82. array(arg(0)) = value
  83. End If
  84. End Set
  85. End Property
  86. End Class
  87. 'Public Class C
  88. ' Sub test()
  89. ' Dim x As ClassWithOnlyOptional = New ClassWithOnlyOptional()
  90. ' Dim y As Integer = x.PropertyName()
  91. ' End Sub
  92. 'End Class
  93. Public Class ClassWithStaticIndexer
  94. Private Shared saved As Integer
  95. Public Shared Property PropertyName(ByVal arg As Integer) As Integer
  96. Get
  97. Return saved + arg
  98. End Get
  99. Set(ByVal value As Integer)
  100. saved = arg + value
  101. End Set
  102. End Property
  103. End Class
  104. Public Class ClassWithStaticIndexer2
  105. Private Shared saved As Integer
  106. Public Shared Property PropertyName(ByVal arg As Integer) As Integer
  107. Get
  108. Return saved + arg
  109. End Get
  110. Set(ByVal value As Integer)
  111. saved = arg + value
  112. End Set
  113. End Property
  114. End Class
  115. Public Class ClassWithOverloadedIndexers
  116. Private array As Integer()
  117. Sub Init()
  118. array = New Integer() {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
  119. End Sub
  120. Public Property PropertyName(ByVal arg As Integer) As Integer
  121. Get
  122. Return array(arg)
  123. End Get
  124. Set(ByVal value As Integer)
  125. array(arg) = value
  126. End Set
  127. End Property
  128. Public Property PropertyName() As Integer
  129. Get
  130. Return array(2)
  131. End Get
  132. Set(ByVal value As Integer)
  133. array(2) = value
  134. End Set
  135. End Property
  136. End Class
  137. End Namespace