MonoGenericClass.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. //
  2. // System.Reflection.MonoGenericClass
  3. //
  4. // Sean MacIsaac ([email protected])
  5. // Paolo Molaro ([email protected])
  6. // Patrik Torstensson ([email protected])
  7. //
  8. // (C) 2001 Ximian, Inc.
  9. //
  10. //
  11. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  12. //
  13. // Permission is hereby granted, free of charge, to any person obtaining
  14. // a copy of this software and associated documentation files (the
  15. // "Software"), to deal in the Software without restriction, including
  16. // without limitation the rights to use, copy, modify, merge, publish,
  17. // distribute, sublicense, and/or sell copies of the Software, and to
  18. // permit persons to whom the Software is furnished to do so, subject to
  19. // the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be
  22. // included in all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  28. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  29. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  30. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  31. //
  32. using System.Reflection;
  33. using System.Reflection.Emit;
  34. using System.Collections;
  35. using System.Runtime.CompilerServices;
  36. using System.Globalization;
  37. using System.Runtime.Serialization;
  38. using System.Text;
  39. namespace System.Reflection
  40. {
  41. /*
  42. * MonoGenericClass represents an instantiation of a generic TypeBuilder. MS
  43. * calls this class TypeBuilderInstantiation (a much better name). MS returns
  44. * NotImplementedException for many of the methods but we can't do that as gmcs
  45. * depends on them.
  46. */
  47. internal class MonoGenericClass : MonoType
  48. {
  49. #region Keep in sync with object-internals.h
  50. #pragma warning disable 649
  51. internal TypeBuilder generic_type;
  52. Type[] type_arguments;
  53. bool initialized;
  54. #pragma warning restore 649
  55. #endregion
  56. Hashtable fields, ctors, methods;
  57. int event_count;
  58. internal MonoGenericClass ()
  59. : base (null)
  60. {
  61. // this should not be used
  62. throw new InvalidOperationException ();
  63. }
  64. internal MonoGenericClass (TypeBuilder tb, Type[] args) : base (null)
  65. {
  66. this.generic_type = tb;
  67. this.type_arguments = args;
  68. }
  69. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  70. extern void initialize (MethodInfo[] methods, ConstructorInfo[] ctors, FieldInfo[] fields, PropertyInfo[] properties, EventInfo[] events);
  71. private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic |
  72. BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
  73. void initialize ()
  74. {
  75. if (initialized)
  76. return;
  77. MonoGenericClass parent = GetParentType () as MonoGenericClass;
  78. if (parent != null)
  79. parent.initialize ();
  80. EventInfo[] events = generic_type.GetEvents_internal (flags);
  81. event_count = events.Length;
  82. initialize (generic_type.GetMethods (flags),
  83. generic_type.GetConstructorsInternal (flags),
  84. generic_type.GetFields (flags),
  85. generic_type.GetProperties (flags),
  86. events);
  87. initialized = true;
  88. }
  89. Type GetParentType ()
  90. {
  91. return InflateType (generic_type.BaseType);
  92. }
  93. internal Type InflateType (Type type)
  94. {
  95. return InflateType (type, null);
  96. }
  97. internal Type InflateType (Type type, Type[] method_args)
  98. {
  99. if (type == null)
  100. return null;
  101. if (!type.IsGenericParameter && !type.ContainsGenericParameters)
  102. return type;
  103. if (type.IsGenericParameter) {
  104. if (type.DeclaringMethod == null)
  105. return type_arguments [type.GenericParameterPosition];
  106. if (method_args != null)
  107. return method_args [type.GenericParameterPosition];
  108. return type;
  109. }
  110. if (type.IsPointer)
  111. return InflateType (type.GetElementType (), method_args).MakePointerType ();
  112. if (type.IsByRef)
  113. return InflateType (type.GetElementType (), method_args).MakeByRefType ();
  114. if (type.IsArray) {
  115. if (type.GetArrayRank () > 1)
  116. return InflateType (type.GetElementType (), method_args).MakeArrayType (type.GetArrayRank ());
  117. #if BOOTSTRAP_NET_2_0
  118. if (type.ToString ().EndsWith ("[*]"))
  119. #else
  120. if (type.ToString ().EndsWith ("[*]", StringComparison.Ordinal)) /*FIXME, the reflection API doesn't offer a way around this*/
  121. #endif
  122. return InflateType (type.GetElementType (), method_args).MakeArrayType (1);
  123. return InflateType (type.GetElementType (), method_args).MakeArrayType ();
  124. }
  125. Type[] args = type.GetGenericArguments ();
  126. for (int i = 0; i < args.Length; ++i)
  127. args [i] = InflateType (args [i], method_args);
  128. Type gtd = type.IsGenericTypeDefinition ? type : type.GetGenericTypeDefinition ();
  129. return gtd.MakeGenericType (args);
  130. }
  131. public override Type BaseType {
  132. get {
  133. Type parent = GetParentType ();
  134. return parent != null ? parent : generic_type.BaseType;
  135. }
  136. }
  137. Type[] GetInterfacesInternal ()
  138. {
  139. if (generic_type.interfaces == null)
  140. return new Type [0];
  141. Type[] res = new Type [generic_type.interfaces.Length];
  142. for (int i = 0; i < res.Length; ++i)
  143. res [i] = InflateType (generic_type.interfaces [i]);
  144. return res;
  145. }
  146. public override Type[] GetInterfaces ()
  147. {
  148. if (!generic_type.IsCompilerContext)
  149. throw new NotSupportedException ();
  150. return GetInterfacesInternal ();
  151. }
  152. protected override bool IsValueTypeImpl ()
  153. {
  154. return generic_type.IsValueType;
  155. }
  156. internal override MethodInfo GetMethod (MethodInfo fromNoninstanciated)
  157. {
  158. initialize ();
  159. if (!(fromNoninstanciated is MethodBuilder))
  160. throw new InvalidOperationException ("Inflating non MethodBuilder objects is not supported: " + fromNoninstanciated.GetType ());
  161. MethodBuilder mb = (MethodBuilder)fromNoninstanciated;
  162. if (methods == null)
  163. methods = new Hashtable ();
  164. if (!methods.ContainsKey (mb))
  165. methods [mb] = new MethodOnTypeBuilderInst (this, mb);
  166. return (MethodInfo)methods [mb];
  167. }
  168. internal override ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
  169. {
  170. initialize ();
  171. if (!(fromNoninstanciated is ConstructorBuilder))
  172. throw new InvalidOperationException ("Inflating non ConstructorBuilder objects is not supported: " + fromNoninstanciated.GetType ());
  173. ConstructorBuilder cb = (ConstructorBuilder)fromNoninstanciated;
  174. if (ctors == null)
  175. ctors = new Hashtable ();
  176. if (!ctors.ContainsKey (cb))
  177. ctors [cb] = new ConstructorOnTypeBuilderInst (this, cb);
  178. return (ConstructorInfo)ctors [cb];
  179. }
  180. internal override FieldInfo GetField (FieldInfo fromNoninstanciated)
  181. {
  182. initialize ();
  183. if (!(fromNoninstanciated is FieldBuilder))
  184. throw new InvalidOperationException ("Inflating non FieldBuilder objects is not supported: " + fromNoninstanciated.GetType ());
  185. FieldBuilder fb = (FieldBuilder)fromNoninstanciated;
  186. if (fields == null)
  187. fields = new Hashtable ();
  188. if (!fields.ContainsKey (fb))
  189. fields [fb] = new FieldOnTypeBuilderInst (this, fb);
  190. return (FieldInfo)fields [fb];
  191. }
  192. public override MethodInfo[] GetMethods (BindingFlags bf)
  193. {
  194. if (!generic_type.IsCompilerContext)
  195. throw new NotSupportedException ();
  196. ArrayList l = new ArrayList ();
  197. //
  198. // Walk up our class hierarchy and retrieve methods from our
  199. // parent classes.
  200. //
  201. Type current_type = this;
  202. do {
  203. MonoGenericClass gi = current_type as MonoGenericClass;
  204. if (gi != null)
  205. l.AddRange (gi.GetMethodsInternal (bf, this));
  206. else if (current_type is TypeBuilder)
  207. l.AddRange (current_type.GetMethods (bf));
  208. else {
  209. // If we encounter a `MonoType', its
  210. // GetMethodsByName() will return all the methods
  211. // from its parent type(s), so we can stop here.
  212. MonoType mt = (MonoType) current_type;
  213. l.AddRange (mt.GetMethodsByName (null, bf, false, this));
  214. break;
  215. }
  216. if ((bf & BindingFlags.DeclaredOnly) != 0)
  217. break;
  218. current_type = current_type.BaseType;
  219. } while (current_type != null);
  220. MethodInfo[] result = new MethodInfo [l.Count];
  221. l.CopyTo (result);
  222. return result;
  223. }
  224. MethodInfo[] GetMethodsInternal (BindingFlags bf, MonoGenericClass reftype)
  225. {
  226. if (generic_type.num_methods == 0)
  227. return new MethodInfo [0];
  228. ArrayList l = new ArrayList ();
  229. bool match;
  230. MethodAttributes mattrs;
  231. initialize ();
  232. for (int i = 0; i < generic_type.num_methods; ++i) {
  233. MethodInfo c = generic_type.methods [i];
  234. match = false;
  235. mattrs = c.Attributes;
  236. if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
  237. if ((bf & BindingFlags.Public) != 0)
  238. match = true;
  239. } else {
  240. if ((bf & BindingFlags.NonPublic) != 0)
  241. match = true;
  242. }
  243. if (!match)
  244. continue;
  245. match = false;
  246. if ((mattrs & MethodAttributes.Static) != 0) {
  247. if ((bf & BindingFlags.Static) != 0)
  248. match = true;
  249. } else {
  250. if ((bf & BindingFlags.Instance) != 0)
  251. match = true;
  252. }
  253. if (!match)
  254. continue;
  255. c = TypeBuilder.GetMethod (this, c);
  256. l.Add (c);
  257. }
  258. MethodInfo[] result = new MethodInfo [l.Count];
  259. l.CopyTo (result);
  260. return result;
  261. }
  262. public override ConstructorInfo[] GetConstructors (BindingFlags bf)
  263. {
  264. if (!generic_type.IsCompilerContext)
  265. throw new NotSupportedException ();
  266. ArrayList l = new ArrayList ();
  267. Type current_type = this;
  268. do {
  269. MonoGenericClass gi = current_type as MonoGenericClass;
  270. if (gi != null)
  271. l.AddRange (gi.GetConstructorsInternal (bf, this));
  272. else if (current_type is TypeBuilder)
  273. l.AddRange (current_type.GetConstructors (bf));
  274. else {
  275. MonoType mt = (MonoType) current_type;
  276. l.AddRange (mt.GetConstructors_internal (bf, this));
  277. break;
  278. }
  279. if ((bf & BindingFlags.DeclaredOnly) != 0)
  280. break;
  281. current_type = current_type.BaseType;
  282. } while (current_type != null);
  283. ConstructorInfo[] result = new ConstructorInfo [l.Count];
  284. l.CopyTo (result);
  285. return result;
  286. }
  287. ConstructorInfo[] GetConstructorsInternal (BindingFlags bf, MonoGenericClass reftype)
  288. {
  289. if (generic_type.ctors == null)
  290. return new ConstructorInfo [0];
  291. ArrayList l = new ArrayList ();
  292. bool match;
  293. MethodAttributes mattrs;
  294. initialize ();
  295. for (int i = 0; i < generic_type.ctors.Length; i++) {
  296. ConstructorInfo c = generic_type.ctors [i];
  297. match = false;
  298. mattrs = c.Attributes;
  299. if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
  300. if ((bf & BindingFlags.Public) != 0)
  301. match = true;
  302. } else {
  303. if ((bf & BindingFlags.NonPublic) != 0)
  304. match = true;
  305. }
  306. if (!match)
  307. continue;
  308. match = false;
  309. if ((mattrs & MethodAttributes.Static) != 0) {
  310. if ((bf & BindingFlags.Static) != 0)
  311. match = true;
  312. } else {
  313. if ((bf & BindingFlags.Instance) != 0)
  314. match = true;
  315. }
  316. if (!match)
  317. continue;
  318. l.Add (TypeBuilder.GetConstructor (this, c));
  319. }
  320. ConstructorInfo[] result = new ConstructorInfo [l.Count];
  321. l.CopyTo (result);
  322. return result;
  323. }
  324. public override FieldInfo[] GetFields (BindingFlags bf)
  325. {
  326. if (!generic_type.IsCompilerContext)
  327. throw new NotSupportedException ();
  328. ArrayList l = new ArrayList ();
  329. Type current_type = this;
  330. do {
  331. MonoGenericClass gi = current_type as MonoGenericClass;
  332. if (gi != null)
  333. l.AddRange (gi.GetFieldsInternal (bf, this));
  334. else if (current_type is TypeBuilder)
  335. l.AddRange (current_type.GetFields (bf));
  336. else {
  337. MonoType mt = (MonoType) current_type;
  338. l.AddRange (mt.GetFields_internal (bf, this));
  339. break;
  340. }
  341. if ((bf & BindingFlags.DeclaredOnly) != 0)
  342. break;
  343. current_type = current_type.BaseType;
  344. } while (current_type != null);
  345. FieldInfo[] result = new FieldInfo [l.Count];
  346. l.CopyTo (result);
  347. return result;
  348. }
  349. FieldInfo[] GetFieldsInternal (BindingFlags bf, MonoGenericClass reftype)
  350. {
  351. if (generic_type.num_fields == 0)
  352. return new FieldInfo [0];
  353. ArrayList l = new ArrayList ();
  354. bool match;
  355. FieldAttributes fattrs;
  356. initialize ();
  357. for (int i = 0; i < generic_type.num_fields; i++) {
  358. FieldInfo c = generic_type.fields [i];
  359. match = false;
  360. fattrs = c.Attributes;
  361. if ((fattrs & FieldAttributes.FieldAccessMask) == FieldAttributes.Public) {
  362. if ((bf & BindingFlags.Public) != 0)
  363. match = true;
  364. } else {
  365. if ((bf & BindingFlags.NonPublic) != 0)
  366. match = true;
  367. }
  368. if (!match)
  369. continue;
  370. match = false;
  371. if ((fattrs & FieldAttributes.Static) != 0) {
  372. if ((bf & BindingFlags.Static) != 0)
  373. match = true;
  374. } else {
  375. if ((bf & BindingFlags.Instance) != 0)
  376. match = true;
  377. }
  378. if (!match)
  379. continue;
  380. l.Add (TypeBuilder.GetField (this, c));
  381. }
  382. FieldInfo[] result = new FieldInfo [l.Count];
  383. l.CopyTo (result);
  384. return result;
  385. }
  386. public override PropertyInfo[] GetProperties (BindingFlags bf)
  387. {
  388. if (!generic_type.IsCompilerContext)
  389. throw new NotSupportedException ();
  390. ArrayList l = new ArrayList ();
  391. Type current_type = this;
  392. do {
  393. MonoGenericClass gi = current_type as MonoGenericClass;
  394. if (gi != null)
  395. l.AddRange (gi.GetPropertiesInternal (bf, this));
  396. else if (current_type is TypeBuilder)
  397. l.AddRange (current_type.GetProperties (bf));
  398. else {
  399. MonoType mt = (MonoType) current_type;
  400. l.AddRange (mt.GetPropertiesByName (null, bf, false, this));
  401. break;
  402. }
  403. if ((bf & BindingFlags.DeclaredOnly) != 0)
  404. break;
  405. current_type = current_type.BaseType;
  406. } while (current_type != null);
  407. PropertyInfo[] result = new PropertyInfo [l.Count];
  408. l.CopyTo (result);
  409. return result;
  410. }
  411. PropertyInfo[] GetPropertiesInternal (BindingFlags bf, MonoGenericClass reftype)
  412. {
  413. if (generic_type.properties == null)
  414. return new PropertyInfo [0];
  415. ArrayList l = new ArrayList ();
  416. bool match;
  417. MethodAttributes mattrs;
  418. MethodInfo accessor;
  419. initialize ();
  420. foreach (PropertyInfo pinfo in generic_type.properties) {
  421. match = false;
  422. accessor = pinfo.GetGetMethod (true);
  423. if (accessor == null)
  424. accessor = pinfo.GetSetMethod (true);
  425. if (accessor == null)
  426. continue;
  427. mattrs = accessor.Attributes;
  428. if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
  429. if ((bf & BindingFlags.Public) != 0)
  430. match = true;
  431. } else {
  432. if ((bf & BindingFlags.NonPublic) != 0)
  433. match = true;
  434. }
  435. if (!match)
  436. continue;
  437. match = false;
  438. if ((mattrs & MethodAttributes.Static) != 0) {
  439. if ((bf & BindingFlags.Static) != 0)
  440. match = true;
  441. } else {
  442. if ((bf & BindingFlags.Instance) != 0)
  443. match = true;
  444. }
  445. if (!match)
  446. continue;
  447. l.Add (new PropertyOnTypeBuilderInst (reftype, pinfo));
  448. }
  449. PropertyInfo[] result = new PropertyInfo [l.Count];
  450. l.CopyTo (result);
  451. return result;
  452. }
  453. public override EventInfo[] GetEvents (BindingFlags bf)
  454. {
  455. if (!generic_type.IsCompilerContext)
  456. throw new NotSupportedException ();
  457. ArrayList l = new ArrayList ();
  458. Type current_type = this;
  459. do {
  460. MonoGenericClass gi = current_type as MonoGenericClass;
  461. if (gi != null)
  462. l.AddRange (gi.GetEventsInternal (bf, this));
  463. else if (current_type is TypeBuilder)
  464. l.AddRange (current_type.GetEvents (bf));
  465. else {
  466. MonoType mt = (MonoType) current_type;
  467. l.AddRange (mt.GetEvents (bf));
  468. break;
  469. }
  470. if ((bf & BindingFlags.DeclaredOnly) != 0)
  471. break;
  472. current_type = current_type.BaseType;
  473. } while (current_type != null);
  474. EventInfo[] result = new EventInfo [l.Count];
  475. l.CopyTo (result);
  476. return result;
  477. }
  478. EventInfo[] GetEventsInternal (BindingFlags bf, MonoGenericClass reftype) {
  479. if (generic_type.events == null)
  480. return new EventInfo [0];
  481. initialize ();
  482. ArrayList l = new ArrayList ();
  483. bool match;
  484. MethodAttributes mattrs;
  485. MethodInfo accessor;
  486. for (int i = 0; i < event_count; ++i) {
  487. EventBuilder ev = generic_type.events [i];
  488. match = false;
  489. accessor = ev.add_method;
  490. if (accessor == null)
  491. accessor = ev.remove_method;
  492. if (accessor == null)
  493. continue;
  494. mattrs = accessor.Attributes;
  495. if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
  496. if ((bf & BindingFlags.Public) != 0)
  497. match = true;
  498. } else {
  499. if ((bf & BindingFlags.NonPublic) != 0)
  500. match = true;
  501. }
  502. if (!match)
  503. continue;
  504. match = false;
  505. if ((mattrs & MethodAttributes.Static) != 0) {
  506. if ((bf & BindingFlags.Static) != 0)
  507. match = true;
  508. } else {
  509. if ((bf & BindingFlags.Instance) != 0)
  510. match = true;
  511. }
  512. if (!match)
  513. continue;
  514. l.Add (new EventOnTypeBuilderInst (this, ev));
  515. }
  516. EventInfo[] result = new EventInfo [l.Count];
  517. l.CopyTo (result);
  518. return result;
  519. }
  520. public override Type[] GetNestedTypes (BindingFlags bf)
  521. {
  522. return generic_type.GetNestedTypes (bf);
  523. }
  524. public override bool IsAssignableFrom (Type c)
  525. {
  526. if (c == this)
  527. return true;
  528. Type[] interfaces = GetInterfacesInternal ();
  529. if (c.IsInterface) {
  530. if (interfaces == null)
  531. return false;
  532. foreach (Type t in interfaces)
  533. if (c.IsAssignableFrom (t))
  534. return true;
  535. return false;
  536. }
  537. Type parent = GetParentType ();
  538. if (parent == null)
  539. return c == typeof (object);
  540. else
  541. return c.IsAssignableFrom (parent);
  542. }
  543. public override Type UnderlyingSystemType {
  544. get { return this; }
  545. }
  546. public override string Name {
  547. get { return generic_type.Name; }
  548. }
  549. public override string Namespace {
  550. get { return generic_type.Namespace; }
  551. }
  552. public override string FullName {
  553. get { return format_name (true, false); }
  554. }
  555. public override string AssemblyQualifiedName {
  556. get { return format_name (true, true); }
  557. }
  558. public override Guid GUID {
  559. get { throw new NotSupportedException (); }
  560. }
  561. string format_name (bool full_name, bool assembly_qualified)
  562. {
  563. StringBuilder sb = new StringBuilder (generic_type.FullName);
  564. bool compiler_ctx = generic_type.IsCompilerContext;
  565. sb.Append ("[");
  566. for (int i = 0; i < type_arguments.Length; ++i) {
  567. if (i > 0)
  568. sb.Append (",");
  569. string name = full_name ? type_arguments [i].AssemblyQualifiedName : type_arguments [i].ToString ();
  570. if (name == null) {
  571. if (compiler_ctx && type_arguments [i].IsGenericParameter)
  572. name = type_arguments [i].Name;
  573. else
  574. return null;
  575. }
  576. if (full_name)
  577. sb.Append ("[");
  578. sb.Append (name);
  579. if (full_name)
  580. sb.Append ("]");
  581. }
  582. sb.Append ("]");
  583. if (assembly_qualified) {
  584. sb.Append (", ");
  585. sb.Append (generic_type.Assembly.FullName);
  586. }
  587. return sb.ToString ();
  588. }
  589. public override string ToString ()
  590. {
  591. return format_name (false, false);
  592. }
  593. public override Type MakeArrayType ()
  594. {
  595. return new ArrayType (this, 0);
  596. }
  597. public override Type MakeArrayType (int rank)
  598. {
  599. if (rank < 1)
  600. throw new IndexOutOfRangeException ();
  601. return new ArrayType (this, rank);
  602. }
  603. public override Type MakeByRefType ()
  604. {
  605. return new ByRefType (this);
  606. }
  607. public override Type MakePointerType ()
  608. {
  609. return new PointerType (this);
  610. }
  611. /*public override Type GetElementType ()
  612. {
  613. throw new NotSupportedException ();
  614. }*/
  615. protected override bool IsCOMObjectImpl ()
  616. {
  617. return false;
  618. }
  619. protected override bool IsPrimitiveImpl ()
  620. {
  621. return false;
  622. }
  623. /*
  624. protected override bool IsArrayImpl ()
  625. {
  626. return false;
  627. }
  628. protected override bool IsByRefImpl ()
  629. {
  630. return false;
  631. }
  632. protected override bool IsPointerImpl ()
  633. {
  634. return false;
  635. }*/
  636. protected override TypeAttributes GetAttributeFlagsImpl ()
  637. {
  638. return generic_type.Attributes;
  639. }
  640. //stuff that throws
  641. public override Type GetInterface (string name, bool ignoreCase)
  642. {
  643. throw new NotSupportedException ();
  644. }
  645. public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
  646. {
  647. if (!generic_type.IsCompilerContext)
  648. throw new NotSupportedException ();
  649. foreach (var evt in GetEvents (bindingAttr)) {
  650. if (evt.Name == name)
  651. return evt;
  652. }
  653. return null;
  654. }
  655. public override FieldInfo GetField( string name, BindingFlags bindingAttr)
  656. {
  657. throw new NotSupportedException ();
  658. }
  659. public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
  660. {
  661. throw new NotSupportedException ();
  662. }
  663. public override Type GetNestedType (string name, BindingFlags bindingAttr)
  664. {
  665. throw new NotSupportedException ();
  666. }
  667. public override object InvokeMember (string name, BindingFlags invokeAttr,
  668. Binder binder, object target, object[] args,
  669. ParameterModifier[] modifiers,
  670. CultureInfo culture, string[] namedParameters)
  671. {
  672. throw new NotSupportedException ();
  673. }
  674. protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
  675. CallingConventions callConvention, Type[] types,
  676. ParameterModifier[] modifiers)
  677. {
  678. throw new NotSupportedException ();
  679. }
  680. protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
  681. Type returnType, Type[] types, ParameterModifier[] modifiers)
  682. {
  683. throw new NotSupportedException ();
  684. }
  685. protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
  686. Binder binder,
  687. CallingConventions callConvention,
  688. Type[] types,
  689. ParameterModifier[] modifiers)
  690. {
  691. throw new NotSupportedException ();
  692. }
  693. //MemberInfo
  694. public override bool IsDefined (Type attributeType, bool inherit)
  695. {
  696. throw new NotSupportedException ();
  697. }
  698. public override object [] GetCustomAttributes (bool inherit)
  699. {
  700. throw new NotSupportedException ();
  701. }
  702. public override object [] GetCustomAttributes (Type attributeType, bool inherit)
  703. {
  704. throw new NotSupportedException ();
  705. }
  706. }
  707. }