PropertyBuilder.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. //
  24. // System.Reflection.Emit/PropertyBuilder.cs
  25. //
  26. // Author:
  27. // Paolo Molaro ([email protected])
  28. //
  29. // (C) 2001 Ximian, Inc. http://www.ximian.com
  30. //
  31. #if MONO_FEATURE_SRE
  32. using System;
  33. using System.Reflection;
  34. using System.Reflection.Emit;
  35. using System.Globalization;
  36. using System.Runtime.CompilerServices;
  37. using System.Runtime.InteropServices;
  38. namespace System.Reflection.Emit {
  39. #if !MOBILE
  40. [ComVisible (true)]
  41. [ComDefaultInterface (typeof (_PropertyBuilder))]
  42. [ClassInterface (ClassInterfaceType.None)]
  43. partial class PropertyBuilder : _PropertyBuilder
  44. {
  45. void _PropertyBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
  46. {
  47. throw new NotImplementedException ();
  48. }
  49. void _PropertyBuilder.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
  50. {
  51. throw new NotImplementedException ();
  52. }
  53. void _PropertyBuilder.GetTypeInfoCount (out uint pcTInfo)
  54. {
  55. throw new NotImplementedException ();
  56. }
  57. void _PropertyBuilder.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
  58. {
  59. throw new NotImplementedException ();
  60. }
  61. }
  62. #endif
  63. [StructLayout (LayoutKind.Sequential)]
  64. public sealed partial class PropertyBuilder : PropertyInfo {
  65. // Managed version of MonoReflectionPropertyBuilder
  66. #pragma warning disable 169, 414
  67. private PropertyAttributes attrs;
  68. private string name;
  69. private Type type;
  70. private Type[] parameters;
  71. private CustomAttributeBuilder[] cattrs;
  72. private object def_value;
  73. private MethodBuilder set_method;
  74. private MethodBuilder get_method;
  75. private int table_idx = 0;
  76. internal TypeBuilder typeb;
  77. private Type[] returnModReq;
  78. private Type[] returnModOpt;
  79. private Type[][] paramModReq;
  80. private Type[][] paramModOpt;
  81. CallingConventions callingConvention;
  82. #pragma warning restore 169, 414
  83. internal PropertyBuilder (TypeBuilder tb, string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnModReq, Type[] returnModOpt, Type[] parameterTypes, Type[][] paramModReq, Type[][] paramModOpt)
  84. {
  85. this.name = name;
  86. this.attrs = attributes;
  87. this.callingConvention = callingConvention;
  88. this.type = returnType;
  89. this.returnModReq = returnModReq;
  90. this.returnModOpt = returnModOpt;
  91. this.paramModReq = paramModReq;
  92. this.paramModOpt = paramModOpt;
  93. if (parameterTypes != null) {
  94. this.parameters = new Type [parameterTypes.Length];
  95. System.Array.Copy (parameterTypes, this.parameters, this.parameters.Length);
  96. }
  97. typeb = tb;
  98. table_idx = tb.get_next_table_index (this, 0x17, 1);
  99. }
  100. public override PropertyAttributes Attributes {
  101. get {return attrs;}
  102. }
  103. public override bool CanRead {
  104. get {return get_method != null;}
  105. }
  106. public override bool CanWrite {
  107. get {return set_method != null;}
  108. }
  109. public override Type DeclaringType {
  110. get {return typeb;}
  111. }
  112. public override string Name {
  113. get {return name;}
  114. }
  115. public PropertyToken PropertyToken {
  116. get {return new PropertyToken ();}
  117. }
  118. public override Type PropertyType {
  119. get {return type;}
  120. }
  121. public override Type ReflectedType {
  122. get {return typeb;}
  123. }
  124. public void AddOtherMethod( MethodBuilder mdBuilder) {
  125. }
  126. public override MethodInfo[] GetAccessors( bool nonPublic) {
  127. return null;
  128. }
  129. public override object[] GetCustomAttributes(bool inherit) {
  130. throw not_supported ();
  131. }
  132. public override object[] GetCustomAttributes(Type attributeType, bool inherit) {
  133. throw not_supported ();
  134. }
  135. public override MethodInfo GetGetMethod( bool nonPublic) {
  136. return get_method;
  137. }
  138. public override ParameterInfo[] GetIndexParameters() {
  139. throw not_supported ();
  140. }
  141. public override MethodInfo GetSetMethod( bool nonPublic) {
  142. return set_method;
  143. }
  144. public override object GetValue(object obj, object[] index) {
  145. return null;
  146. }
  147. public override object GetValue( object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture) {
  148. throw not_supported ();
  149. }
  150. public override bool IsDefined( Type attributeType, bool inherit) {
  151. throw not_supported ();
  152. }
  153. public void SetConstant( object defaultValue) {
  154. def_value = defaultValue;
  155. }
  156. public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
  157. string attrname = customBuilder.Ctor.ReflectedType.FullName;
  158. if (attrname == "System.Runtime.CompilerServices.SpecialNameAttribute") {
  159. attrs |= PropertyAttributes.SpecialName;
  160. return;
  161. }
  162. if (cattrs != null) {
  163. CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
  164. cattrs.CopyTo (new_array, 0);
  165. new_array [cattrs.Length] = customBuilder;
  166. cattrs = new_array;
  167. } else {
  168. cattrs = new CustomAttributeBuilder [1];
  169. cattrs [0] = customBuilder;
  170. }
  171. }
  172. [ComVisible (true)]
  173. public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
  174. SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
  175. }
  176. public void SetGetMethod( MethodBuilder mdBuilder) {
  177. get_method = mdBuilder;
  178. }
  179. public void SetSetMethod( MethodBuilder mdBuilder) {
  180. set_method = mdBuilder;
  181. }
  182. public override void SetValue( object obj, object value, object[] index) {
  183. }
  184. public override void SetValue( object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture) {
  185. }
  186. public override Module Module {
  187. get {
  188. return base.Module;
  189. }
  190. }
  191. private Exception not_supported ()
  192. {
  193. return new NotSupportedException ("The invoked member is not supported in a dynamic module.");
  194. }
  195. }
  196. }
  197. #endif