Make TypeNameParser consistently use tabs
[mono-project.git] / netcore / System.Private.CoreLib / src / System / Type.cs
blob8f45e4031fe69bc065113e10d336e67d6192931a
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 using System.Text;
6 using System.IO;
7 using System.Reflection;
8 using System.Collections.Generic;
9 using System.Runtime.CompilerServices;
10 using System.Runtime.InteropServices;
11 using System.Threading;
13 namespace System
15 partial class Type
17 #region keep in sync with object-internals.h
18 internal RuntimeTypeHandle _impl;
19 #endregion
21 internal bool IsRuntimeImplemented () => this.UnderlyingSystemType is RuntimeType;
23 public bool IsInterface {
24 get {
25 if (this is RuntimeType rt)
26 return RuntimeTypeHandle.IsInterface (rt);
28 return (GetAttributeFlagsImpl () & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
32 [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
33 public static Type GetType (string typeName, bool throwOnError, bool ignoreCase)
35 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
36 return RuntimeType.GetType (typeName, throwOnError, ignoreCase, false, ref stackMark);
39 [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
40 public static Type GetType (string typeName, bool throwOnError)
42 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
43 return RuntimeType.GetType (typeName, throwOnError, false, false, ref stackMark);
46 [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
47 public static Type GetType (string typeName)
49 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
50 return RuntimeType.GetType (typeName, false, false, false, ref stackMark);
53 [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
54 public static Type GetType (string typeName, Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver)
56 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
57 return RuntimeType.GetType (typeName, assemblyResolver, typeResolver, false, false, ref stackMark);
60 [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
61 public static Type GetType (string typeName, Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver, bool throwOnError)
63 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
64 return RuntimeType.GetType (typeName, assemblyResolver, typeResolver, throwOnError, false, ref stackMark);
67 [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
68 public static Type GetType (string typeName, Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase)
70 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
71 return RuntimeType.GetType (typeName, assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark);
74 static Type GetType (string typeName, Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark) {
75 return TypeNameParser.GetType (typeName, assemblyResolver, typeResolver, throwOnError, ignoreCase, ref stackMark);
78 public static Type? GetTypeFromHandle (RuntimeTypeHandle handle)
80 if (handle.Value == IntPtr.Zero)
81 return null;
83 return internal_from_handle (handle.Value);
86 public static Type GetTypeFromCLSID (Guid clsid, string? server, bool throwOnError) => throw new PlatformNotSupportedException ();
88 public static Type GetTypeFromProgID (string progID, string? server, bool throwOnError) => throw new PlatformNotSupportedException ();
90 internal virtual Type InternalResolve ()
92 return UnderlyingSystemType;
95 // Called from the runtime to return the corresponding finished Type object
96 internal virtual Type RuntimeResolve ()
98 throw new NotImplementedException ();
101 internal virtual bool IsUserType {
102 get {
103 return true;
107 internal virtual MethodInfo GetMethod (MethodInfo fromNoninstanciated)
109 throw new InvalidOperationException ("can only be called in generic type");
112 internal virtual ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
114 throw new InvalidOperationException ("can only be called in generic type");
117 internal virtual FieldInfo GetField (FieldInfo fromNoninstanciated)
119 throw new InvalidOperationException ("can only be called in generic type");
122 [MethodImplAttribute (MethodImplOptions.InternalCall)]
123 static extern Type internal_from_handle (IntPtr handle);
125 public static bool operator == (Type? left, Type? right)
127 return object.ReferenceEquals (left, right);
130 public static bool operator != (Type? left, Type? right)
132 return !object.ReferenceEquals (left, right);