5 // Sean MacIsaac (macisaac@ximian.com)
6 // Paolo Molaro (lupus@ximian.com)
7 // Patrik Torstensson (patrik.torstensson@labs2.com)
8 // Gonzalo Paniagua (gonzalo@ximian.com)
9 // Marek Safar (marek.safar@gmail.com)
11 // (c) 2001-2003 Ximian, Inc.
12 // Copyright (C) 2003-2005 Novell, Inc (http://www.novell.com)
13 // Copyright (C) 2013 Xamarin Inc (http://www.xamarin.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.Collections.Generic;
36 using System.Globalization;
37 using System.Reflection;
38 using System.Runtime.InteropServices;
39 using System.Runtime.CompilerServices;
40 using System.Runtime.Serialization;
41 using System.Security;
42 using System.Diagnostics.Contracts;
43 using System.Threading;
44 using System.Diagnostics;
45 using System.Security.Permissions;
46 using System.Runtime.Remoting.Activation;
51 // Contains information about the type which is expensive to compute
52 [StructLayout (LayoutKind.Sequential)]
53 internal class MonoTypeInfo {
54 // this is the displayed form: special characters
55 // ,+*&*[]\ in the identifier portions of the names
56 // have been escaped with a leading backslash (\)
57 public string full_name;
58 public MonoCMethod default_ctor;
62 [StructLayout (LayoutKind.Sequential)]
63 class MonoType : RuntimeType, ISerializable
66 MonoTypeInfo type_info;
68 [MethodImplAttribute(MethodImplOptions.InternalCall)]
69 private static extern void type_from_obj (MonoType type, Object obj);
71 internal MonoType (Object obj)
73 // this should not be used - lupus
74 type_from_obj (this, obj);
76 throw new NotImplementedException ();
79 internal override MonoCMethod GetDefaultConstructor ()
81 MonoCMethod ctor = null;
83 if (type_info == null)
84 type_info = new MonoTypeInfo ();
86 ctor = type_info.default_ctor;
89 var ctors = GetConstructors (BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
91 for (int i = 0; i < ctors.Length; ++i) {
92 if (ctors [i].GetParametersCount () == 0) {
93 type_info.default_ctor = ctor = (MonoCMethod) ctors [i];
102 [MethodImplAttribute(MethodImplOptions.InternalCall)]
103 extern MethodInfo GetCorrespondingInflatedMethod (MethodInfo generic);
105 [MethodImplAttribute(MethodImplOptions.InternalCall)]
106 extern ConstructorInfo GetCorrespondingInflatedConstructor (ConstructorInfo generic);
108 internal override MethodInfo GetMethod (MethodInfo fromNoninstanciated)
110 if (fromNoninstanciated == null)
111 throw new ArgumentNullException ("fromNoninstanciated");
112 return GetCorrespondingInflatedMethod (fromNoninstanciated);
115 internal override ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
117 if (fromNoninstanciated == null)
118 throw new ArgumentNullException ("fromNoninstanciated");
119 return GetCorrespondingInflatedConstructor (fromNoninstanciated);
122 internal override FieldInfo GetField (FieldInfo fromNoninstanciated)
124 /* create sensible flags from given FieldInfo */
125 BindingFlags flags = fromNoninstanciated.IsStatic ? BindingFlags.Static : BindingFlags.Instance;
126 flags |= fromNoninstanciated.IsPublic ? BindingFlags.Public : BindingFlags.NonPublic;
127 return GetField (fromNoninstanciated.Name, flags);
130 public override int GetHashCode()
132 Type t = UnderlyingSystemType;
133 if (t != null && t != this)
134 return t.GetHashCode ();
135 return (int)_impl.Value;
138 public override string FullName {
141 // This doesn't need locking
142 if (type_info == null)
143 type_info = new MonoTypeInfo ();
144 if ((fullName = type_info.full_name) == null)
145 fullName = type_info.full_name = getFullName (true, false);
151 internal override bool IsUserType {