MonoGenericClass.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  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. internal override bool IsCompilerContext {
  70. get {
  71. return generic_type.IsCompilerContext;
  72. }
  73. }
  74. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  75. extern void initialize (MethodInfo[] methods, ConstructorInfo[] ctors, FieldInfo[] fields, PropertyInfo[] properties, EventInfo[] events);
  76. private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic |
  77. BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
  78. void initialize ()
  79. {
  80. if (initialized)
  81. return;
  82. MonoGenericClass parent = GetParentType () as MonoGenericClass;
  83. if (parent != null)
  84. parent.initialize ();
  85. EventInfo[] events = generic_type.GetEvents_internal (flags);
  86. event_count = events.Length;
  87. initialize (generic_type.GetMethods (flags),
  88. generic_type.GetConstructorsInternal (flags),
  89. generic_type.GetFields (flags),
  90. generic_type.GetProperties (flags),
  91. events);
  92. initialized = true;
  93. }
  94. Type GetParentType ()
  95. {
  96. return InflateType (generic_type.BaseType);
  97. }
  98. internal Type InflateType (Type type)
  99. {
  100. return InflateType (type, type_arguments, null);
  101. }
  102. internal Type InflateType (Type type, Type[] method_args)
  103. {
  104. return InflateType (type, type_arguments, method_args);
  105. }
  106. internal static Type InflateType (Type type, Type[] type_args, Type[] method_args)
  107. {
  108. if (type == null)
  109. return null;
  110. if (!type.IsGenericParameter && !type.ContainsGenericParameters)
  111. return type;
  112. if (type.IsGenericParameter) {
  113. if (type.DeclaringMethod == null)
  114. return type_args == null ? type : type_args [type.GenericParameterPosition];
  115. return method_args == null ? type : method_args [type.GenericParameterPosition];
  116. }
  117. if (type.IsPointer)
  118. return InflateType (type.GetElementType (), type_args, method_args).MakePointerType ();
  119. if (type.IsByRef)
  120. return InflateType (type.GetElementType (), type_args, method_args).MakeByRefType ();
  121. if (type.IsArray) {
  122. if (type.GetArrayRank () > 1)
  123. return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType (type.GetArrayRank ());
  124. #if BOOTSTRAP_NET_2_0
  125. if (type.ToString ().EndsWith ("[*]"))
  126. #else
  127. if (type.ToString ().EndsWith ("[*]", StringComparison.Ordinal)) /*FIXME, the reflection API doesn't offer a way around this*/
  128. #endif
  129. return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType (1);
  130. return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType ();
  131. }
  132. Type[] args = type.GetGenericArguments ();
  133. for (int i = 0; i < args.Length; ++i)
  134. args [i] = InflateType (args [i], type_args, method_args);
  135. Type gtd = type.IsGenericTypeDefinition ? type : type.GetGenericTypeDefinition ();
  136. return gtd.MakeGenericType (args);
  137. }
  138. public override Type BaseType {
  139. get {
  140. Type parent = GetParentType ();
  141. return parent != null ? parent : generic_type.BaseType;
  142. }
  143. }
  144. Type[] GetInterfacesInternal ()
  145. {
  146. if (generic_type.interfaces == null)
  147. return new Type [0];
  148. Type[] res = new Type [generic_type.interfaces.Length];
  149. for (int i = 0; i < res.Length; ++i)
  150. res [i] = InflateType (generic_type.interfaces [i]);
  151. return res;
  152. }
  153. public override Type[] GetInterfaces ()
  154. {
  155. if (!IsCompilerContext)
  156. throw new NotSupportedException ();
  157. return GetInterfacesInternal ();
  158. }
  159. protected override bool IsValueTypeImpl ()
  160. {
  161. return generic_type.IsValueType;
  162. }
  163. internal override MethodInfo GetMethod (MethodInfo fromNoninstanciated)
  164. {
  165. initialize ();
  166. if (!(fromNoninstanciated is MethodBuilder))
  167. throw new InvalidOperationException ("Inflating non MethodBuilder objects is not supported: " + fromNoninstanciated.GetType ());
  168. MethodBuilder mb = (MethodBuilder)fromNoninstanciated;
  169. if (methods == null)
  170. methods = new Hashtable ();
  171. if (!methods.ContainsKey (mb))
  172. methods [mb] = new MethodOnTypeBuilderInst (this, mb);
  173. return (MethodInfo)methods [mb];
  174. }
  175. internal override ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
  176. {
  177. initialize ();
  178. if (!(fromNoninstanciated is ConstructorBuilder))
  179. throw new InvalidOperationException ("Inflating non ConstructorBuilder objects is not supported: " + fromNoninstanciated.GetType ());
  180. ConstructorBuilder cb = (ConstructorBuilder)fromNoninstanciated;
  181. if (ctors == null)
  182. ctors = new Hashtable ();
  183. if (!ctors.ContainsKey (cb))
  184. ctors [cb] = new ConstructorOnTypeBuilderInst (this, cb);
  185. return (ConstructorInfo)ctors [cb];
  186. }
  187. internal override FieldInfo GetField (FieldInfo fromNoninstanciated)
  188. {
  189. initialize ();
  190. if (!(fromNoninstanciated is FieldBuilder))
  191. throw new InvalidOperationException ("Inflating non FieldBuilder objects is not supported: " + fromNoninstanciated.GetType ());
  192. FieldBuilder fb = (FieldBuilder)fromNoninstanciated;
  193. if (fields == null)
  194. fields = new Hashtable ();
  195. if (!fields.ContainsKey (fb))
  196. fields [fb] = new FieldOnTypeBuilderInst (this, fb);
  197. return (FieldInfo)fields [fb];
  198. }
  199. public override MethodInfo[] GetMethods (BindingFlags bf)
  200. {
  201. if (!IsCompilerContext)
  202. throw new NotSupportedException ();
  203. ArrayList l = new ArrayList ();
  204. //
  205. // Walk up our class hierarchy and retrieve methods from our
  206. // parent classes.
  207. //
  208. Type current_type = this;
  209. do {
  210. MonoGenericClass gi = current_type as MonoGenericClass;
  211. if (gi != null)
  212. l.AddRange (gi.GetMethodsInternal (bf, this));
  213. else if (current_type is TypeBuilder)
  214. l.AddRange (current_type.GetMethods (bf));
  215. else {
  216. // If we encounter a `MonoType', its
  217. // GetMethodsByName() will return all the methods
  218. // from its parent type(s), so we can stop here.
  219. MonoType mt = (MonoType) current_type;
  220. l.AddRange (mt.GetMethodsByName (null, bf, false, this));
  221. break;
  222. }
  223. if ((bf & BindingFlags.DeclaredOnly) != 0)
  224. break;
  225. current_type = current_type.BaseType;
  226. } while (current_type != null);
  227. MethodInfo[] result = new MethodInfo [l.Count];
  228. l.CopyTo (result);
  229. return result;
  230. }
  231. MethodInfo[] GetMethodsInternal (BindingFlags bf, MonoGenericClass reftype)
  232. {
  233. if (generic_type.num_methods == 0)
  234. return new MethodInfo [0];
  235. ArrayList l = new ArrayList ();
  236. bool match;
  237. MethodAttributes mattrs;
  238. initialize ();
  239. for (int i = 0; i < generic_type.num_methods; ++i) {
  240. MethodInfo c = generic_type.methods [i];
  241. match = false;
  242. mattrs = c.Attributes;
  243. if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
  244. if ((bf & BindingFlags.Public) != 0)
  245. match = true;
  246. } else {
  247. if ((bf & BindingFlags.NonPublic) != 0)
  248. match = true;
  249. }
  250. if (!match)
  251. continue;
  252. match = false;
  253. if ((mattrs & MethodAttributes.Static) != 0) {
  254. if ((bf & BindingFlags.Static) != 0)
  255. match = true;
  256. } else {
  257. if ((bf & BindingFlags.Instance) != 0)
  258. match = true;
  259. }
  260. if (!match)
  261. continue;
  262. c = TypeBuilder.GetMethod (this, c);
  263. l.Add (c);
  264. }
  265. MethodInfo[] result = new MethodInfo [l.Count];
  266. l.CopyTo (result);
  267. return result;
  268. }
  269. public override ConstructorInfo[] GetConstructors (BindingFlags bf)
  270. {
  271. if (!IsCompilerContext)
  272. throw new NotSupportedException ();
  273. ArrayList l = new ArrayList ();
  274. Type current_type = this;
  275. do {
  276. MonoGenericClass gi = current_type as MonoGenericClass;
  277. if (gi != null)
  278. l.AddRange (gi.GetConstructorsInternal (bf, this));
  279. else if (current_type is TypeBuilder)
  280. l.AddRange (current_type.GetConstructors (bf));
  281. else {
  282. MonoType mt = (MonoType) current_type;
  283. l.AddRange (mt.GetConstructors_internal (bf, this));
  284. break;
  285. }
  286. if ((bf & BindingFlags.DeclaredOnly) != 0)
  287. break;
  288. current_type = current_type.BaseType;
  289. } while (current_type != null);
  290. ConstructorInfo[] result = new ConstructorInfo [l.Count];
  291. l.CopyTo (result);
  292. return result;
  293. }
  294. ConstructorInfo[] GetConstructorsInternal (BindingFlags bf, MonoGenericClass reftype)
  295. {
  296. if (generic_type.ctors == null)
  297. return new ConstructorInfo [0];
  298. ArrayList l = new ArrayList ();
  299. bool match;
  300. MethodAttributes mattrs;
  301. initialize ();
  302. for (int i = 0; i < generic_type.ctors.Length; i++) {
  303. ConstructorInfo c = generic_type.ctors [i];
  304. match = false;
  305. mattrs = c.Attributes;
  306. if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
  307. if ((bf & BindingFlags.Public) != 0)
  308. match = true;
  309. } else {
  310. if ((bf & BindingFlags.NonPublic) != 0)
  311. match = true;
  312. }
  313. if (!match)
  314. continue;
  315. match = false;
  316. if ((mattrs & MethodAttributes.Static) != 0) {
  317. if ((bf & BindingFlags.Static) != 0)
  318. match = true;
  319. } else {
  320. if ((bf & BindingFlags.Instance) != 0)
  321. match = true;
  322. }
  323. if (!match)
  324. continue;
  325. l.Add (TypeBuilder.GetConstructor (this, c));
  326. }
  327. ConstructorInfo[] result = new ConstructorInfo [l.Count];
  328. l.CopyTo (result);
  329. return result;
  330. }
  331. public override FieldInfo[] GetFields (BindingFlags bf)
  332. {
  333. if (!IsCompilerContext)
  334. throw new NotSupportedException ();
  335. ArrayList l = new ArrayList ();
  336. Type current_type = this;
  337. do {
  338. MonoGenericClass gi = current_type as MonoGenericClass;
  339. if (gi != null)
  340. l.AddRange (gi.GetFieldsInternal (bf, this));
  341. else if (current_type is TypeBuilder)
  342. l.AddRange (current_type.GetFields (bf));
  343. else {
  344. MonoType mt = (MonoType) current_type;
  345. l.AddRange (mt.GetFields_internal (bf, this));
  346. break;
  347. }
  348. if ((bf & BindingFlags.DeclaredOnly) != 0)
  349. break;
  350. current_type = current_type.BaseType;
  351. } while (current_type != null);
  352. FieldInfo[] result = new FieldInfo [l.Count];
  353. l.CopyTo (result);
  354. return result;
  355. }
  356. FieldInfo[] GetFieldsInternal (BindingFlags bf, MonoGenericClass reftype)
  357. {
  358. if (generic_type.num_fields == 0)
  359. return new FieldInfo [0];
  360. ArrayList l = new ArrayList ();
  361. bool match;
  362. FieldAttributes fattrs;
  363. initialize ();
  364. for (int i = 0; i < generic_type.num_fields; i++) {
  365. FieldInfo c = generic_type.fields [i];
  366. match = false;
  367. fattrs = c.Attributes;
  368. if ((fattrs & FieldAttributes.FieldAccessMask) == FieldAttributes.Public) {
  369. if ((bf & BindingFlags.Public) != 0)
  370. match = true;
  371. } else {
  372. if ((bf & BindingFlags.NonPublic) != 0)
  373. match = true;
  374. }
  375. if (!match)
  376. continue;
  377. match = false;
  378. if ((fattrs & FieldAttributes.Static) != 0) {
  379. if ((bf & BindingFlags.Static) != 0)
  380. match = true;
  381. } else {
  382. if ((bf & BindingFlags.Instance) != 0)
  383. match = true;
  384. }
  385. if (!match)
  386. continue;
  387. l.Add (TypeBuilder.GetField (this, c));
  388. }
  389. FieldInfo[] result = new FieldInfo [l.Count];
  390. l.CopyTo (result);
  391. return result;
  392. }
  393. public override PropertyInfo[] GetProperties (BindingFlags bf)
  394. {
  395. if (!IsCompilerContext)
  396. throw new NotSupportedException ();
  397. ArrayList l = new ArrayList ();
  398. Type current_type = this;
  399. do {
  400. MonoGenericClass gi = current_type as MonoGenericClass;
  401. if (gi != null)
  402. l.AddRange (gi.GetPropertiesInternal (bf, this));
  403. else if (current_type is TypeBuilder)
  404. l.AddRange (current_type.GetProperties (bf));
  405. else {
  406. MonoType mt = (MonoType) current_type;
  407. l.AddRange (mt.GetPropertiesByName (null, bf, false, this));
  408. break;
  409. }
  410. if ((bf & BindingFlags.DeclaredOnly) != 0)
  411. break;
  412. current_type = current_type.BaseType;
  413. } while (current_type != null);
  414. PropertyInfo[] result = new PropertyInfo [l.Count];
  415. l.CopyTo (result);
  416. return result;
  417. }
  418. PropertyInfo[] GetPropertiesInternal (BindingFlags bf, MonoGenericClass reftype)
  419. {
  420. if (generic_type.properties == null)
  421. return new PropertyInfo [0];
  422. ArrayList l = new ArrayList ();
  423. bool match;
  424. MethodAttributes mattrs;
  425. MethodInfo accessor;
  426. initialize ();
  427. foreach (PropertyInfo pinfo in generic_type.properties) {
  428. match = false;
  429. accessor = pinfo.GetGetMethod (true);
  430. if (accessor == null)
  431. accessor = pinfo.GetSetMethod (true);
  432. if (accessor == null)
  433. continue;
  434. mattrs = accessor.Attributes;
  435. if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
  436. if ((bf & BindingFlags.Public) != 0)
  437. match = true;
  438. } else {
  439. if ((bf & BindingFlags.NonPublic) != 0)
  440. match = true;
  441. }
  442. if (!match)
  443. continue;
  444. match = false;
  445. if ((mattrs & MethodAttributes.Static) != 0) {
  446. if ((bf & BindingFlags.Static) != 0)
  447. match = true;
  448. } else {
  449. if ((bf & BindingFlags.Instance) != 0)
  450. match = true;
  451. }
  452. if (!match)
  453. continue;
  454. l.Add (new PropertyOnTypeBuilderInst (reftype, pinfo));
  455. }
  456. PropertyInfo[] result = new PropertyInfo [l.Count];
  457. l.CopyTo (result);
  458. return result;
  459. }
  460. public override EventInfo[] GetEvents (BindingFlags bf)
  461. {
  462. if (!IsCompilerContext)
  463. throw new NotSupportedException ();
  464. ArrayList l = new ArrayList ();
  465. Type current_type = this;
  466. do {
  467. MonoGenericClass gi = current_type as MonoGenericClass;
  468. if (gi != null)
  469. l.AddRange (gi.GetEventsInternal (bf, this));
  470. else if (current_type is TypeBuilder)
  471. l.AddRange (current_type.GetEvents (bf));
  472. else {
  473. MonoType mt = (MonoType) current_type;
  474. l.AddRange (mt.GetEvents (bf));
  475. break;
  476. }
  477. if ((bf & BindingFlags.DeclaredOnly) != 0)
  478. break;
  479. current_type = current_type.BaseType;
  480. } while (current_type != null);
  481. EventInfo[] result = new EventInfo [l.Count];
  482. l.CopyTo (result);
  483. return result;
  484. }
  485. EventInfo[] GetEventsInternal (BindingFlags bf, MonoGenericClass reftype) {
  486. if (generic_type.events == null)
  487. return new EventInfo [0];
  488. initialize ();
  489. ArrayList l = new ArrayList ();
  490. bool match;
  491. MethodAttributes mattrs;
  492. MethodInfo accessor;
  493. for (int i = 0; i < event_count; ++i) {
  494. EventBuilder ev = generic_type.events [i];
  495. match = false;
  496. accessor = ev.add_method;
  497. if (accessor == null)
  498. accessor = ev.remove_method;
  499. if (accessor == null)
  500. continue;
  501. mattrs = accessor.Attributes;
  502. if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
  503. if ((bf & BindingFlags.Public) != 0)
  504. match = true;
  505. } else {
  506. if ((bf & BindingFlags.NonPublic) != 0)
  507. match = true;
  508. }
  509. if (!match)
  510. continue;
  511. match = false;
  512. if ((mattrs & MethodAttributes.Static) != 0) {
  513. if ((bf & BindingFlags.Static) != 0)
  514. match = true;
  515. } else {
  516. if ((bf & BindingFlags.Instance) != 0)
  517. match = true;
  518. }
  519. if (!match)
  520. continue;
  521. l.Add (new EventOnTypeBuilderInst (this, ev));
  522. }
  523. EventInfo[] result = new EventInfo [l.Count];
  524. l.CopyTo (result);
  525. return result;
  526. }
  527. public override Type[] GetNestedTypes (BindingFlags bf)
  528. {
  529. return generic_type.GetNestedTypes (bf);
  530. }
  531. public override bool IsAssignableFrom (Type c)
  532. {
  533. if (c == this)
  534. return true;
  535. Type[] interfaces = GetInterfacesInternal ();
  536. if (c.IsInterface) {
  537. if (interfaces == null)
  538. return false;
  539. foreach (Type t in interfaces)
  540. if (c.IsAssignableFrom (t))
  541. return true;
  542. return false;
  543. }
  544. Type parent = GetParentType ();
  545. if (parent == null)
  546. return c == typeof (object);
  547. else
  548. return c.IsAssignableFrom (parent);
  549. }
  550. public override Type UnderlyingSystemType {
  551. get { return this; }
  552. }
  553. public override string Name {
  554. get { return generic_type.Name; }
  555. }
  556. public override string Namespace {
  557. get { return generic_type.Namespace; }
  558. }
  559. public override string FullName {
  560. get { return format_name (true, false); }
  561. }
  562. public override string AssemblyQualifiedName {
  563. get { return format_name (true, true); }
  564. }
  565. public override Guid GUID {
  566. get { throw new NotSupportedException (); }
  567. }
  568. string format_name (bool full_name, bool assembly_qualified)
  569. {
  570. StringBuilder sb = new StringBuilder (generic_type.FullName);
  571. bool compiler_ctx = IsCompilerContext;
  572. sb.Append ("[");
  573. for (int i = 0; i < type_arguments.Length; ++i) {
  574. if (i > 0)
  575. sb.Append (",");
  576. string name = full_name ? type_arguments [i].AssemblyQualifiedName : type_arguments [i].ToString ();
  577. if (name == null) {
  578. if (compiler_ctx && type_arguments [i].IsGenericParameter)
  579. name = type_arguments [i].Name;
  580. else
  581. return null;
  582. }
  583. if (full_name)
  584. sb.Append ("[");
  585. sb.Append (name);
  586. if (full_name)
  587. sb.Append ("]");
  588. }
  589. sb.Append ("]");
  590. if (assembly_qualified) {
  591. sb.Append (", ");
  592. sb.Append (generic_type.Assembly.FullName);
  593. }
  594. return sb.ToString ();
  595. }
  596. public override string ToString ()
  597. {
  598. return format_name (false, false);
  599. }
  600. public override Type MakeArrayType ()
  601. {
  602. return new ArrayType (this, 0);
  603. }
  604. public override Type MakeArrayType (int rank)
  605. {
  606. if (rank < 1)
  607. throw new IndexOutOfRangeException ();
  608. return new ArrayType (this, rank);
  609. }
  610. public override Type MakeByRefType ()
  611. {
  612. return new ByRefType (this);
  613. }
  614. public override Type MakePointerType ()
  615. {
  616. return new PointerType (this);
  617. }
  618. /*public override Type GetElementType ()
  619. {
  620. throw new NotSupportedException ();
  621. }*/
  622. protected override bool IsCOMObjectImpl ()
  623. {
  624. return false;
  625. }
  626. protected override bool IsPrimitiveImpl ()
  627. {
  628. return false;
  629. }
  630. /*
  631. protected override bool IsArrayImpl ()
  632. {
  633. return false;
  634. }
  635. protected override bool IsByRefImpl ()
  636. {
  637. return false;
  638. }
  639. protected override bool IsPointerImpl ()
  640. {
  641. return false;
  642. }*/
  643. protected override TypeAttributes GetAttributeFlagsImpl ()
  644. {
  645. return generic_type.Attributes;
  646. }
  647. //stuff that throws
  648. public override Type GetInterface (string name, bool ignoreCase)
  649. {
  650. throw new NotSupportedException ();
  651. }
  652. public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
  653. {
  654. if (!IsCompilerContext)
  655. throw new NotSupportedException ();
  656. foreach (var evt in GetEvents (bindingAttr)) {
  657. if (evt.Name == name)
  658. return evt;
  659. }
  660. return null;
  661. }
  662. public override FieldInfo GetField( string name, BindingFlags bindingAttr)
  663. {
  664. throw new NotSupportedException ();
  665. }
  666. public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
  667. {
  668. throw new NotSupportedException ();
  669. }
  670. public override Type GetNestedType (string name, BindingFlags bindingAttr)
  671. {
  672. throw new NotSupportedException ();
  673. }
  674. public override object InvokeMember (string name, BindingFlags invokeAttr,
  675. Binder binder, object target, object[] args,
  676. ParameterModifier[] modifiers,
  677. CultureInfo culture, string[] namedParameters)
  678. {
  679. throw new NotSupportedException ();
  680. }
  681. protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
  682. CallingConventions callConvention, Type[] types,
  683. ParameterModifier[] modifiers)
  684. {
  685. throw new NotSupportedException ();
  686. }
  687. protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
  688. Type returnType, Type[] types, ParameterModifier[] modifiers)
  689. {
  690. throw new NotSupportedException ();
  691. }
  692. protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
  693. Binder binder,
  694. CallingConventions callConvention,
  695. Type[] types,
  696. ParameterModifier[] modifiers)
  697. {
  698. throw new NotSupportedException ();
  699. }
  700. //MemberInfo
  701. public override bool IsDefined (Type attributeType, bool inherit)
  702. {
  703. throw new NotSupportedException ();
  704. }
  705. public override object [] GetCustomAttributes (bool inherit)
  706. {
  707. throw new NotSupportedException ();
  708. }
  709. public override object [] GetCustomAttributes (Type attributeType, bool inherit)
  710. {
  711. throw new NotSupportedException ();
  712. }
  713. }
  714. }