PropertyBuilder.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // System.Reflection.Emit/PropertyBuilder.cs
  3. //
  4. // Author:
  5. // Paolo Molaro ([email protected])
  6. //
  7. // (C) 2001 Ximian, Inc. http://www.ximian.com
  8. //
  9. using System;
  10. using System.Reflection;
  11. using System.Reflection.Emit;
  12. using System.Globalization;
  13. using System.Runtime.CompilerServices;
  14. namespace System.Reflection.Emit {
  15. public sealed class PropertyBuilder : PropertyInfo {
  16. private PropertyAttributes attrs;
  17. private string name;
  18. private Type type;
  19. private Type[] parameters;
  20. private CustomAttributeBuilder[] cattrs;
  21. private object def_value;
  22. private MethodBuilder set_method;
  23. private MethodBuilder get_method;
  24. private int table_idx = 0;
  25. internal TypeBuilder typeb;
  26. internal PropertyBuilder (TypeBuilder tb, string name, PropertyAttributes attributes, Type returnType, Type[] parameterTypes) {
  27. this.name = name;
  28. this.attrs = attributes;
  29. this.type = returnType;
  30. if (parameterTypes != null) {
  31. this.parameters = new Type [parameterTypes.Length];
  32. System.Array.Copy (parameterTypes, this.parameters, this.parameters.Length);
  33. }
  34. typeb = tb;
  35. table_idx = tb.get_next_table_index (this, 0x17, true);
  36. }
  37. public override PropertyAttributes Attributes {
  38. get {return attrs;}
  39. }
  40. public override bool CanRead {
  41. get {return get_method != null;}
  42. }
  43. public override bool CanWrite {
  44. get {return set_method != null;}
  45. }
  46. public override Type DeclaringType {
  47. get {return typeb;}
  48. }
  49. public override string Name {
  50. get {return name;}
  51. }
  52. public PropertyToken PropertyToken {
  53. get {return new PropertyToken ();}
  54. }
  55. public override Type PropertyType {
  56. get {return type;}
  57. }
  58. public override Type ReflectedType {
  59. get {return typeb;}
  60. }
  61. public void AddOtherMethod( MethodBuilder mdBuilder) {
  62. }
  63. public override MethodInfo[] GetAccessors( bool nonPublic) {
  64. return null;
  65. }
  66. public override object[] GetCustomAttributes(bool inherit) {
  67. return null;
  68. }
  69. public override object[] GetCustomAttributes(Type attributeType, bool inherit) {
  70. return null;
  71. }
  72. public override MethodInfo GetGetMethod( bool nonPublic) {
  73. return get_method;
  74. }
  75. public override ParameterInfo[] GetIndexParameters() {
  76. return null;
  77. }
  78. public override MethodInfo GetSetMethod( bool nonPublic) {
  79. return set_method;
  80. }
  81. public override object GetValue(object obj, object[] index) {
  82. return null;
  83. }
  84. public override object GetValue( object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture) {
  85. return null;
  86. }
  87. public override bool IsDefined( Type attributeType, bool inherit) {
  88. return false;
  89. }
  90. public void SetConstant( object defaultValue) {
  91. def_value = defaultValue;
  92. }
  93. public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
  94. if (cattrs != null) {
  95. CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
  96. cattrs.CopyTo (new_array, 0);
  97. new_array [cattrs.Length] = customBuilder;
  98. cattrs = new_array;
  99. } else {
  100. cattrs = new CustomAttributeBuilder [1];
  101. cattrs [0] = customBuilder;
  102. }
  103. }
  104. public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
  105. SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
  106. }
  107. public void SetGetMethod( MethodBuilder mdBuilder) {
  108. get_method = mdBuilder;
  109. }
  110. public void SetSetMethod( MethodBuilder mdBuilder) {
  111. set_method = mdBuilder;
  112. }
  113. public override void SetValue( object obj, object value, object[] index) {
  114. }
  115. public override void SetValue( object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture) {
  116. }
  117. }
  118. }