CodeArrayCreateExpression.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. //
  2. // System.CodeDom CodeArrayCreateExpression Class implementation
  3. //
  4. // Author:
  5. // Miguel de Icaza ([email protected])
  6. // Daniel Stodden ([email protected])
  7. //
  8. // (C) 2001 Ximian, Inc.
  9. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System.Runtime.InteropServices;
  31. namespace System.CodeDom {
  32. [Serializable]
  33. [ClassInterface(ClassInterfaceType.AutoDispatch)]
  34. [ComVisible(true)]
  35. public class CodeArrayCreateExpression
  36. : CodeExpression
  37. {
  38. private CodeTypeReference createType;
  39. private CodeExpressionCollection initializers;
  40. private CodeExpression sizeExpression;
  41. private int size;
  42. //
  43. // Constructors
  44. //
  45. public CodeArrayCreateExpression ()
  46. {
  47. }
  48. public CodeArrayCreateExpression (CodeTypeReference createType,
  49. CodeExpression size )
  50. {
  51. this.createType = createType;
  52. this.sizeExpression = size;
  53. }
  54. public CodeArrayCreateExpression (CodeTypeReference createType,
  55. params CodeExpression[] initializers )
  56. {
  57. this.createType = createType;
  58. this.Initializers.AddRange( initializers );
  59. }
  60. public CodeArrayCreateExpression (CodeTypeReference createType,
  61. int size)
  62. {
  63. this.createType = createType;
  64. this.size = size;
  65. }
  66. public CodeArrayCreateExpression (string createType,
  67. CodeExpression size)
  68. {
  69. this.createType = new CodeTypeReference( createType );
  70. this.sizeExpression = size;
  71. }
  72. public CodeArrayCreateExpression (string createType,
  73. params CodeExpression[] initializers)
  74. {
  75. this.createType = new CodeTypeReference( createType );
  76. this.Initializers.AddRange( initializers );
  77. }
  78. public CodeArrayCreateExpression (string createType,
  79. int size)
  80. {
  81. this.createType = new CodeTypeReference( createType );
  82. this.size = size;
  83. }
  84. public CodeArrayCreateExpression (Type createType,
  85. CodeExpression size)
  86. {
  87. this.createType = new CodeTypeReference( createType );
  88. this.sizeExpression = size;
  89. }
  90. public CodeArrayCreateExpression (Type createType,
  91. params CodeExpression[] initializers)
  92. {
  93. this.createType = new CodeTypeReference( createType );
  94. this.Initializers.AddRange( initializers );
  95. }
  96. public CodeArrayCreateExpression (Type createType,
  97. int size)
  98. {
  99. this.createType = new CodeTypeReference( createType );
  100. this.size = size;
  101. }
  102. //
  103. // Properties
  104. //
  105. public CodeTypeReference CreateType {
  106. get {
  107. if (createType == null) {
  108. createType = new CodeTypeReference (typeof (void));
  109. }
  110. return createType;
  111. }
  112. set {
  113. createType = value;
  114. }
  115. }
  116. public CodeExpressionCollection Initializers {
  117. get {
  118. if ( initializers == null )
  119. initializers = new CodeExpressionCollection();
  120. return initializers;
  121. }
  122. }
  123. public CodeExpression SizeExpression {
  124. get {
  125. return sizeExpression;
  126. }
  127. set {
  128. sizeExpression = value;
  129. }
  130. }
  131. public int Size {
  132. get {
  133. return size;
  134. }
  135. set {
  136. size = value;
  137. // NOTE: Setting Size in ms.Net does
  138. // not supersede SizeExpression
  139. // values. Instead, the CodeGenerator
  140. // seems to always prefer
  141. // SizeExpression if set to a value !=
  142. // null.
  143. }
  144. }
  145. }
  146. }