diff options
Diffstat (limited to 'src/mscorlib/src/System/Type.cs')
-rw-r--r-- | src/mscorlib/src/System/Type.cs | 735 |
1 files changed, 419 insertions, 316 deletions
diff --git a/src/mscorlib/src/System/Type.cs b/src/mscorlib/src/System/Type.cs index 192760830b..795a42fef0 100644 --- a/src/mscorlib/src/System/Type.cs +++ b/src/mscorlib/src/System/Type.cs @@ -40,7 +40,7 @@ namespace System public static readonly Object Missing = System.Reflection.Missing.Value; - public static readonly char Delimiter = '.'; + public static readonly char Delimiter = '.'; // EmptyTypes is used to indicate that we are looking for someting without any parameters. public readonly static Type[] EmptyTypes = EmptyArray<Type>.Value; @@ -49,18 +49,20 @@ namespace System private static Binder defaultBinder; - protected Type() {} + protected Type() { } // MemberInfo Methods.... // The Member type Field. - public override MemberTypes MemberType { - get {return System.Reflection.MemberTypes.TypeInfo;} + public override MemberTypes MemberType + { + get { return System.Reflection.MemberTypes.TypeInfo; } } // Return the class that declared this type. - public override Type DeclaringType { - get {return null;} + public override Type DeclaringType + { + get { return null; } } public virtual MethodBase DeclaringMethod { get { return null; } } @@ -68,7 +70,7 @@ namespace System // Return the class that was used to obtain this type. public override Type ReflectedType { - get {return null;} + get { return null; } } //////////////////////////////////////////////////////////////////////////////// @@ -78,19 +80,22 @@ namespace System //// [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod - public static Type GetType(String typeName, bool throwOnError, bool ignoreCase) { + public static Type GetType(String typeName, bool throwOnError, bool ignoreCase) + { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return RuntimeType.GetType(typeName, throwOnError, ignoreCase, false, ref stackMark); } [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod - public static Type GetType(String typeName, bool throwOnError) { + public static Type GetType(String typeName, bool throwOnError) + { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return RuntimeType.GetType(typeName, throwOnError, false, false, ref stackMark); } [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod - public static Type GetType(String typeName) { + public static Type GetType(String typeName) + { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return RuntimeType.GetType(typeName, false, false, false, ref stackMark); } @@ -129,7 +134,7 @@ namespace System } [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod - public static Type ReflectionOnlyGetType(String typeName, bool throwIfNotFound, bool ignoreCase) + public static Type ReflectionOnlyGetType(String typeName, bool throwIfNotFound, bool ignoreCase) { if (typeName == null) throw new ArgumentNullException(nameof(typeName)); @@ -155,7 +160,7 @@ namespace System //// public static Type GetTypeFromProgID(String progID) { - return RuntimeType.GetTypeFromProgIDImpl(progID, null, false); + return RuntimeType.GetTypeFromProgIDImpl(progID, null, false); } //////////////////////////////////////////////////////////////////////////////// @@ -169,17 +174,17 @@ namespace System //// public static Type GetTypeFromProgID(String progID, bool throwOnError) { - return RuntimeType.GetTypeFromProgIDImpl(progID, null, throwOnError); + return RuntimeType.GetTypeFromProgIDImpl(progID, null, throwOnError); } public static Type GetTypeFromProgID(String progID, String server) { - return RuntimeType.GetTypeFromProgIDImpl(progID, server, false); + return RuntimeType.GetTypeFromProgIDImpl(progID, server, false); } public static Type GetTypeFromProgID(String progID, String server, bool throwOnError) { - return RuntimeType.GetTypeFromProgIDImpl(progID, server, throwOnError); + return RuntimeType.GetTypeFromProgIDImpl(progID, server, throwOnError); } //////////////////////////////////////////////////////////////////////////////// @@ -191,22 +196,22 @@ namespace System //// public static Type GetTypeFromCLSID(Guid clsid) { - return RuntimeType.GetTypeFromCLSIDImpl(clsid, null, false); + return RuntimeType.GetTypeFromCLSIDImpl(clsid, null, false); } public static Type GetTypeFromCLSID(Guid clsid, bool throwOnError) { - return RuntimeType.GetTypeFromCLSIDImpl(clsid, null, throwOnError); + return RuntimeType.GetTypeFromCLSIDImpl(clsid, null, throwOnError); } public static Type GetTypeFromCLSID(Guid clsid, String server) { - return RuntimeType.GetTypeFromCLSIDImpl(clsid, server, false); + return RuntimeType.GetTypeFromCLSIDImpl(clsid, server, false); } public static Type GetTypeFromCLSID(Guid clsid, String server, bool throwOnError) { - return RuntimeType.GetTypeFromCLSIDImpl(clsid, server, throwOnError); + return RuntimeType.GetTypeFromCLSIDImpl(clsid, server, throwOnError); } // GetTypeCode @@ -227,18 +232,21 @@ namespace System // this is true for EnumBuilder but not the other System.Type subclasses in BCL if (this != UnderlyingSystemType && UnderlyingSystemType != null) return Type.GetTypeCode(UnderlyingSystemType); - + return TypeCode.Object; } // Property representing the GUID associated with a class. - public abstract Guid GUID { + public abstract Guid GUID + { get; } // Return the Default binder used by the system. - static public Binder DefaultBinder { - get { + static public Binder DefaultBinder + { + get + { // Allocate the default binder if it hasn't been allocated yet. if (defaultBinder == null) CreateBinder(); @@ -246,7 +254,7 @@ namespace System } } - static private void CreateBinder() + static private void CreateBinder() { if (defaultBinder == null) { @@ -255,43 +263,43 @@ namespace System } } - // Description of the Binding Process. - // We must invoke a method that is accessable and for which the provided - // parameters have the most specific match. A method may be called if - // 1. The number of parameters in the method declaration equals the number of - // arguments provided to the invocation - // 2. The type of each argument can be converted by the binder to the - // type of the type of the parameter. - // - // The binder will find all of the matching methods. These method are found based - // upon the type of binding requested (MethodInvoke, Get/Set Properties). The set - // of methods is filtered by the name, number of arguments and a set of search modifiers - // defined in the Binder. - // - // After the method is selected, it will be invoked. Accessability is checked - // at that point. The search may be control which set of methods are searched based - // upon the accessibility attribute associated with the method. - // - // The BindToMethod method is responsible for selecting the method to be invoked. - // For the default binder, the most specific method will be selected. - // - // This will invoke a specific member... - - abstract public Object InvokeMember(String name,BindingFlags invokeAttr,Binder binder,Object target, - Object[] args, ParameterModifier[] modifiers,CultureInfo culture,String[] namedParameters); + // Description of the Binding Process. + // We must invoke a method that is accessable and for which the provided + // parameters have the most specific match. A method may be called if + // 1. The number of parameters in the method declaration equals the number of + // arguments provided to the invocation + // 2. The type of each argument can be converted by the binder to the + // type of the type of the parameter. + // + // The binder will find all of the matching methods. These method are found based + // upon the type of binding requested (MethodInvoke, Get/Set Properties). The set + // of methods is filtered by the name, number of arguments and a set of search modifiers + // defined in the Binder. + // + // After the method is selected, it will be invoked. Accessability is checked + // at that point. The search may be control which set of methods are searched based + // upon the accessibility attribute associated with the method. + // + // The BindToMethod method is responsible for selecting the method to be invoked. + // For the default binder, the most specific method will be selected. + // + // This will invoke a specific member... + + abstract public Object InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, + Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters); [DebuggerStepThroughAttribute] [Diagnostics.DebuggerHidden] - public Object InvokeMember(String name,BindingFlags invokeAttr,Binder binder, Object target, Object[] args, CultureInfo culture) + public Object InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture) { - return InvokeMember(name,invokeAttr,binder,target,args,null,culture,null); + return InvokeMember(name, invokeAttr, binder, target, args, null, culture, null); } [DebuggerStepThroughAttribute] [Diagnostics.DebuggerHidden] - public Object InvokeMember(String name,BindingFlags invokeAttr,Binder binder, Object target, Object[] args) + public Object InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args) { - return InvokeMember(name,invokeAttr,binder,target,args,null,null,null); + return InvokeMember(name, invokeAttr, binder, target, args, null, null, null); } @@ -299,7 +307,8 @@ namespace System public new abstract Module Module { get; } // Assembly Property associated with a class. - public abstract Assembly Assembly { + public abstract Assembly Assembly + { [Pure] get; } @@ -316,7 +325,8 @@ namespace System } } - internal virtual RuntimeTypeHandle GetTypeHandleInternal() { + internal virtual RuntimeTypeHandle GetTypeHandleInternal() + { return TypeHandle; } @@ -337,26 +347,30 @@ namespace System // Return the fully qualified name. The name does contain the namespace. - public abstract String FullName { + public abstract String FullName + { [Pure] get; } // Return the name space of the class. - public abstract String Namespace { + public abstract String Namespace + { [Pure] get; } - public abstract String AssemblyQualifiedName { + public abstract String AssemblyQualifiedName + { [Pure] get; } [Pure] - public virtual int GetArrayRank() { + public virtual int GetArrayRank() + { Contract.Ensures(Contract.Result<int>() >= 0); throw new NotSupportedException(Environment.GetResourceString("NotSupported_SubclassOverride")); } @@ -364,7 +378,8 @@ namespace System // Returns the base class for a class. If this is an interface or has // no base class null is returned. Object is the only Type that does not // have a base class. - public abstract Type BaseType { + public abstract Type BaseType + { [Pure] get; } @@ -376,15 +391,15 @@ namespace System // reason is that we don't typically expose the class initializer. public ConstructorInfo GetConstructor(BindingFlags bindingAttr, Binder binder, - CallingConventions callConvention, + CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) - { - // Must provide some types (Type[0] for nothing) + { + // Must provide some types (Type[0] for nothing) if (types == null) throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); - for (int i=0;i<types.Length;i++) + for (int i = 0; i < types.Length; i++) if (types[i] == null) throw new ArgumentNullException(nameof(types)); return GetConstructorImpl(bindingAttr, binder, callConvention, types, modifiers); @@ -395,7 +410,7 @@ namespace System if (types == null) throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); - for (int i=0;i<types.Length;i++) + for (int i = 0; i < types.Length; i++) if (types[i] == null) throw new ArgumentNullException(nameof(types)); return GetConstructorImpl(bindingAttr, binder, CallingConventions.Any, types, modifiers); @@ -409,7 +424,7 @@ namespace System abstract protected ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder binder, - CallingConventions callConvention, + CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers); @@ -417,14 +432,17 @@ namespace System // This routine will return an array of all constructors supported by the class. // Unlike everything else, the default is to not look for static methods. The // reason is that we don't typically expose the class initializer. - public ConstructorInfo[] GetConstructors() { + public ConstructorInfo[] GetConstructors() + { return GetConstructors(BindingFlags.Public | BindingFlags.Instance); } - + abstract public ConstructorInfo[] GetConstructors(BindingFlags bindingAttr); - public ConstructorInfo TypeInitializer { - get { + public ConstructorInfo TypeInitializer + { + get + { return GetConstructorImpl(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, CallingConventions.Any, @@ -480,20 +498,20 @@ namespace System if (types == null) throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); - for (int i=0;i<types.Length;i++) + for (int i = 0; i < types.Length; i++) if (types[i] == null) throw new ArgumentNullException(nameof(types)); return GetMethodImpl(name, Type.DefaultLookup, null, CallingConventions.Any, types, modifiers); } - public MethodInfo GetMethod(String name,Type[] types) + public MethodInfo GetMethod(String name, Type[] types) { if (name == null) throw new ArgumentNullException(nameof(name)); if (types == null) throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); - for (int i=0;i<types.Length;i++) + for (int i = 0; i < types.Length; i++) if (types[i] == null) throw new ArgumentNullException(nameof(types)); return GetMethodImpl(name, Type.DefaultLookup, null, CallingConventions.Any, types, null); @@ -518,14 +536,15 @@ namespace System abstract protected MethodInfo GetMethodImpl(String name, BindingFlags bindingAttr, Binder binder, - CallingConventions callConvention, + CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers); // GetMethods // This routine will return all the methods implemented by the class - public MethodInfo[] GetMethods() { + public MethodInfo[] GetMethods() + { return GetMethods(Type.DefaultLookup); } @@ -536,14 +555,16 @@ namespace System abstract public FieldInfo GetField(String name, BindingFlags bindingAttr); - public FieldInfo GetField(String name) { + public FieldInfo GetField(String name) + { return GetField(name, Type.DefaultLookup); } // GetFields // Get fields will return a full array of fields implemented by a class - public FieldInfo[] GetFields() { + public FieldInfo[] GetFields() + { return GetFields(Type.DefaultLookup); } abstract public FieldInfo[] GetFields(BindingFlags bindingAttr); @@ -551,8 +572,9 @@ namespace System // GetInterface // This method will return an interface (as a class) based upon // the passed in name. - public Type GetInterface(String name) { - return GetInterface(name,false); + public Type GetInterface(String name) + { + return GetInterface(name, false); } abstract public Type GetInterface(String name, bool ignoreCase); @@ -563,25 +585,27 @@ namespace System // FindInterfaces // This method will filter the interfaces supported the class - public virtual Type[] FindInterfaces(TypeFilter filter,Object filterCriteria) + public virtual Type[] FindInterfaces(TypeFilter filter, Object filterCriteria) { if (filter == null) throw new ArgumentNullException(nameof(filter)); Contract.EndContractBlock(); Type[] c = GetInterfaces(); int cnt = 0; - for (int i = 0;i<c.Length;i++) { - if (!filter(c[i],filterCriteria)) + for (int i = 0; i < c.Length; i++) + { + if (!filter(c[i], filterCriteria)) c[i] = null; else cnt++; } if (cnt == c.Length) return c; - + Type[] ret = new Type[cnt]; - cnt=0; - for (int i=0;i<c.Length;i++) { + cnt = 0; + for (int i = 0; i < c.Length; i++) + { if (c[i] != null) ret[cnt++] = c[i]; } @@ -593,15 +617,17 @@ namespace System // null is returned if the event is not found - public EventInfo GetEvent(String name) { - return GetEvent(name,Type.DefaultLookup); + public EventInfo GetEvent(String name) + { + return GetEvent(name, Type.DefaultLookup); } - abstract public EventInfo GetEvent(String name,BindingFlags bindingAttr); + abstract public EventInfo GetEvent(String name, BindingFlags bindingAttr); // GetEvents // This method will return an array of EventInfo. If there are not Events // an empty array will be returned. - virtual public EventInfo[] GetEvents() { + virtual public EventInfo[] GetEvents() + { return GetEvents(Type.DefaultLookup); } abstract public EventInfo[] GetEvents(BindingFlags bindingAttr); @@ -609,7 +635,7 @@ namespace System // Return a property based upon the passed criteria. The nameof the // parameter must be provided. - public PropertyInfo GetProperty(String name,BindingFlags bindingAttr,Binder binder, + public PropertyInfo GetProperty(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) { if (name == null) @@ -617,17 +643,17 @@ namespace System if (types == null) throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); - return GetPropertyImpl(name,bindingAttr,binder,returnType,types,modifiers); + return GetPropertyImpl(name, bindingAttr, binder, returnType, types, modifiers); } - public PropertyInfo GetProperty(String name, Type returnType, Type[] types,ParameterModifier[] modifiers) + public PropertyInfo GetProperty(String name, Type returnType, Type[] types, ParameterModifier[] modifiers) { if (name == null) throw new ArgumentNullException(nameof(name)); if (types == null) throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); - return GetPropertyImpl(name,Type.DefaultLookup,null,returnType,types,modifiers); + return GetPropertyImpl(name, Type.DefaultLookup, null, returnType, types, modifiers); } public PropertyInfo GetProperty(String name, BindingFlags bindingAttr) @@ -635,7 +661,7 @@ namespace System if (name == null) throw new ArgumentNullException(nameof(name)); Contract.EndContractBlock(); - return GetPropertyImpl(name,bindingAttr,null,null,null,null); + return GetPropertyImpl(name, bindingAttr, null, null, null, null); } public PropertyInfo GetProperty(String name, Type returnType, Type[] types) @@ -645,7 +671,7 @@ namespace System if (types == null) throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); - return GetPropertyImpl(name,Type.DefaultLookup,null,returnType,types,null); + return GetPropertyImpl(name, Type.DefaultLookup, null, returnType, types, null); } public PropertyInfo GetProperty(String name, Type[] types) @@ -655,7 +681,7 @@ namespace System if (types == null) throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); - return GetPropertyImpl(name,Type.DefaultLookup,null,null,types,null); + return GetPropertyImpl(name, Type.DefaultLookup, null, null, types, null); } public PropertyInfo GetProperty(String name, Type returnType) @@ -665,7 +691,7 @@ namespace System if (returnType == null) throw new ArgumentNullException(nameof(returnType)); Contract.EndContractBlock(); - return GetPropertyImpl(name,Type.DefaultLookup,null,returnType,null,null); + return GetPropertyImpl(name, Type.DefaultLookup, null, returnType, null, null); } public PropertyInfo GetProperty(String name) @@ -673,10 +699,10 @@ namespace System if (name == null) throw new ArgumentNullException(nameof(name)); Contract.EndContractBlock(); - return GetPropertyImpl(name,Type.DefaultLookup,null,null,null,null); + return GetPropertyImpl(name, Type.DefaultLookup, null, null, null, null); } - protected abstract PropertyInfo GetPropertyImpl(String name, BindingFlags bindingAttr,Binder binder, + protected abstract PropertyInfo GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers); @@ -701,7 +727,7 @@ namespace System public Type GetNestedType(String name) { - return GetNestedType(name,Type.DefaultLookup); + return GetNestedType(name, Type.DefaultLookup); } abstract public Type GetNestedType(String name, BindingFlags bindingAttr); @@ -709,15 +735,16 @@ namespace System // GetMember // This method will return all of the members which match the specified string // passed into the method - public MemberInfo[] GetMember(String name) { - return GetMember(name,Type.DefaultLookup); + public MemberInfo[] GetMember(String name) + { + return GetMember(name, Type.DefaultLookup); } virtual public MemberInfo[] GetMember(String name, BindingFlags bindingAttr) { - return GetMember(name,MemberTypes.All,bindingAttr); + return GetMember(name, MemberTypes.All, bindingAttr); } - + virtual public MemberInfo[] GetMember(String name, MemberTypes type, BindingFlags bindingAttr) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_SubclassOverride")); @@ -726,7 +753,8 @@ namespace System // GetMembers // This will return a Member array of all of the members of a class - public MemberInfo[] GetMembers() { + public MemberInfo[] GetMembers() + { return GetMembers(Type.DefaultLookup); } abstract public MemberInfo[] GetMembers(BindingFlags bindingAttr); @@ -741,7 +769,7 @@ namespace System // FindMembers // This will return a filtered version of the member information - public virtual MemberInfo[] FindMembers(MemberTypes memberType,BindingFlags bindingAttr,MemberFilter filter,Object filterCriteria) + public virtual MemberInfo[] FindMembers(MemberTypes memberType, BindingFlags bindingAttr, MemberFilter filter, Object filterCriteria) { // Define the work arrays MethodInfo[] m = null; @@ -750,168 +778,199 @@ namespace System PropertyInfo[] p = null; EventInfo[] e = null; Type[] t = null; - + int i = 0; int cnt = 0; // Total Matchs - + // Check the methods - if ((memberType & System.Reflection.MemberTypes.Method) != 0) { + if ((memberType & System.Reflection.MemberTypes.Method) != 0) + { m = GetMethods(bindingAttr); - if (filter != null) { - for (i=0;i<m.Length;i++) - if (!filter(m[i],filterCriteria)) + if (filter != null) + { + for (i = 0; i < m.Length; i++) + if (!filter(m[i], filterCriteria)) m[i] = null; else cnt++; - } else { - cnt+=m.Length; + } + else + { + cnt += m.Length; } } - + // Check the constructors - if ((memberType & System.Reflection.MemberTypes.Constructor) != 0) { + if ((memberType & System.Reflection.MemberTypes.Constructor) != 0) + { c = GetConstructors(bindingAttr); - if (filter != null) { - for (i=0;i<c.Length;i++) - if (!filter(c[i],filterCriteria)) + if (filter != null) + { + for (i = 0; i < c.Length; i++) + if (!filter(c[i], filterCriteria)) c[i] = null; else cnt++; - } else { - cnt+=c.Length; + } + else + { + cnt += c.Length; } } - + // Check the fields - if ((memberType & System.Reflection.MemberTypes.Field) != 0) { + if ((memberType & System.Reflection.MemberTypes.Field) != 0) + { f = GetFields(bindingAttr); - if (filter != null) { - for (i=0;i<f.Length;i++) - if (!filter(f[i],filterCriteria)) + if (filter != null) + { + for (i = 0; i < f.Length; i++) + if (!filter(f[i], filterCriteria)) f[i] = null; else cnt++; - } else { - cnt+=f.Length; + } + else + { + cnt += f.Length; } } - + // Check the Properties - if ((memberType & System.Reflection.MemberTypes.Property) != 0) { + if ((memberType & System.Reflection.MemberTypes.Property) != 0) + { p = GetProperties(bindingAttr); - if (filter != null) { - for (i=0;i<p.Length;i++) - if (!filter(p[i],filterCriteria)) + if (filter != null) + { + for (i = 0; i < p.Length; i++) + if (!filter(p[i], filterCriteria)) p[i] = null; else cnt++; - } else { - cnt+=p.Length; + } + else + { + cnt += p.Length; } } - + // Check the Events - if ((memberType & System.Reflection.MemberTypes.Event) != 0) { + if ((memberType & System.Reflection.MemberTypes.Event) != 0) + { e = GetEvents(bindingAttr); - if (filter != null) { - for (i=0;i<e.Length;i++) - if (!filter(e[i],filterCriteria)) + if (filter != null) + { + for (i = 0; i < e.Length; i++) + if (!filter(e[i], filterCriteria)) e[i] = null; else cnt++; - } else { - cnt+=e.Length; + } + else + { + cnt += e.Length; } } - + // Check the Types - if ((memberType & System.Reflection.MemberTypes.NestedType) != 0) { + if ((memberType & System.Reflection.MemberTypes.NestedType) != 0) + { t = GetNestedTypes(bindingAttr); - if (filter != null) { - for (i=0;i<t.Length;i++) - if (!filter(t[i],filterCriteria)) + if (filter != null) + { + for (i = 0; i < t.Length; i++) + if (!filter(t[i], filterCriteria)) t[i] = null; else cnt++; - } else { - cnt+=t.Length; + } + else + { + cnt += t.Length; } } - + // Allocate the Member Info MemberInfo[] ret = new MemberInfo[cnt]; - + // Copy the Methods cnt = 0; - if (m != null) { - for (i=0;i<m.Length;i++) + if (m != null) + { + for (i = 0; i < m.Length; i++) if (m[i] != null) ret[cnt++] = m[i]; } - + // Copy the Constructors - if (c != null) { - for (i=0;i<c.Length;i++) + if (c != null) + { + for (i = 0; i < c.Length; i++) if (c[i] != null) ret[cnt++] = c[i]; } - + // Copy the Fields - if (f != null) { - for (i=0;i<f.Length;i++) + if (f != null) + { + for (i = 0; i < f.Length; i++) if (f[i] != null) ret[cnt++] = f[i]; } - + // Copy the Properties - if (p != null) { - for (i=0;i<p.Length;i++) + if (p != null) + { + for (i = 0; i < p.Length; i++) if (p[i] != null) ret[cnt++] = p[i]; } - + // Copy the Events - if (e != null) { - for (i=0;i<e.Length;i++) + if (e != null) + { + for (i = 0; i < e.Length; i++) if (e[i] != null) ret[cnt++] = e[i]; } - + // Copy the Types - if (t != null) { - for (i=0;i<t.Length;i++) + if (t != null) + { + for (i = 0; i < t.Length; i++) if (t[i] != null) ret[cnt++] = t[i]; } - + return ret; } - //////////////////////////////////////////////////////////////////////////////// - // - // Attributes - // - // The attributes are all treated as read-only properties on a class. Most of - // these boolean properties have flag values defined in this class and act like - // a bit mask of attributes. There are also a set of boolean properties that - // relate to the classes relationship to other classes and to the state of the - // class inside the runtime. - // - //////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + // + // Attributes + // + // The attributes are all treated as read-only properties on a class. Most of + // these boolean properties have flag values defined in this class and act like + // a bit mask of attributes. There are also a set of boolean properties that + // relate to the classes relationship to other classes and to the state of the + // class inside the runtime. + // + //////////////////////////////////////////////////////////////////////////////// - public bool IsNested + public bool IsNested { [Pure] - get + get { - return DeclaringType != null; + return DeclaringType != null; } } // The attribute property on the Type. - public TypeAttributes Attributes { + public TypeAttributes Attributes + { [Pure] - get {return GetAttributeFlagsImpl();} + get { return GetAttributeFlagsImpl(); } } public virtual GenericParameterAttributes GenericParameterAttributes @@ -922,7 +981,7 @@ namespace System public bool IsVisible { [Pure] - get + get { RuntimeType rt = this as RuntimeType; if (rt != null) @@ -964,59 +1023,71 @@ namespace System public bool IsNotPublic { [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic);} + get { return ((GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic); } } - public bool IsPublic { + public bool IsPublic + { [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.Public);} + get { return ((GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.Public); } } - public bool IsNestedPublic { + public bool IsNestedPublic + { [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic);} + get { return ((GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic); } } - public bool IsNestedPrivate { + public bool IsNestedPrivate + { [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate);} + get { return ((GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate); } } - public bool IsNestedFamily { + public bool IsNestedFamily + { [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamily);} + get { return ((GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamily); } } - public bool IsNestedAssembly { + public bool IsNestedAssembly + { [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedAssembly);} + get { return ((GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedAssembly); } } - public bool IsNestedFamANDAssem { + public bool IsNestedFamANDAssem + { [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamANDAssem);} + get { return ((GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamANDAssem); } } - public bool IsNestedFamORAssem{ + public bool IsNestedFamORAssem + { [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamORAssem);} + get { return ((GetAttributeFlagsImpl() & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamORAssem); } } - public bool IsAutoLayout { + public bool IsAutoLayout + { [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.LayoutMask) == TypeAttributes.AutoLayout);} + get { return ((GetAttributeFlagsImpl() & TypeAttributes.LayoutMask) == TypeAttributes.AutoLayout); } } - public bool IsLayoutSequential { + public bool IsLayoutSequential + { [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout);} + get { return ((GetAttributeFlagsImpl() & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout); } } - public bool IsExplicitLayout { + public bool IsExplicitLayout + { [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout);} + get { return ((GetAttributeFlagsImpl() & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout); } } - public bool IsClass { + public bool IsClass + { [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Class && !IsValueType);} + get { return ((GetAttributeFlagsImpl() & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Class && !IsValueType); } } - public bool IsInterface { + public bool IsInterface + { [Pure] get { @@ -1028,38 +1099,44 @@ namespace System } } - public bool IsValueType { + public bool IsValueType + { + [Pure] + get { return IsValueTypeImpl(); } + } + + public bool IsAbstract + { [Pure] - get {return IsValueTypeImpl();} + get { return ((GetAttributeFlagsImpl() & TypeAttributes.Abstract) != 0); } } - public bool IsAbstract { + public bool IsSealed + { [Pure] - get { return ((GetAttributeFlagsImpl() & TypeAttributes.Abstract) != 0); } - } - - public bool IsSealed { + get { return ((GetAttributeFlagsImpl() & TypeAttributes.Sealed) != 0); } + } + + public virtual bool IsEnum + { [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.Sealed) != 0);} - } - - public virtual bool IsEnum { - [Pure] - get - { + get + { // This will return false for a non-runtime Type object unless it overrides IsSubclassOf. return IsSubclassOf(RuntimeType.EnumType); - } - } - - public bool IsSpecialName { - [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.SpecialName) != 0);} - } + } + } - public bool IsImport { - [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.Import) != 0);} + public bool IsSpecialName + { + [Pure] + get { return ((GetAttributeFlagsImpl() & TypeAttributes.SpecialName) != 0); } + } + + public bool IsImport + { + [Pure] + get { return ((GetAttributeFlagsImpl() & TypeAttributes.Import) != 0); } } public virtual bool IsSerializable @@ -1079,40 +1156,47 @@ namespace System } } - public bool IsAnsiClass { - [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.StringFormatMask) == TypeAttributes.AnsiClass);} + public bool IsAnsiClass + { + [Pure] + get { return ((GetAttributeFlagsImpl() & TypeAttributes.StringFormatMask) == TypeAttributes.AnsiClass); } } - public bool IsUnicodeClass { - [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.StringFormatMask) == TypeAttributes.UnicodeClass);} + public bool IsUnicodeClass + { + [Pure] + get { return ((GetAttributeFlagsImpl() & TypeAttributes.StringFormatMask) == TypeAttributes.UnicodeClass); } } - public bool IsAutoClass { - [Pure] - get {return ((GetAttributeFlagsImpl() & TypeAttributes.StringFormatMask) == TypeAttributes.AutoClass);} + public bool IsAutoClass + { + [Pure] + get { return ((GetAttributeFlagsImpl() & TypeAttributes.StringFormatMask) == TypeAttributes.AutoClass); } } - - // These are not backed up by attributes. Instead they are implemented - // based internally. - public bool IsArray { - [Pure] - get {return IsArrayImpl();} - } - internal virtual bool IsSzArray { - [Pure] - get {return false;} + // These are not backed up by attributes. Instead they are implemented + // based internally. + public bool IsArray + { + [Pure] + get { return IsArrayImpl(); } } - public virtual bool IsGenericType { - [Pure] + internal virtual bool IsSzArray + { + [Pure] get { return false; } } - public virtual bool IsGenericTypeDefinition { - [Pure] + public virtual bool IsGenericType + { + [Pure] + get { return false; } + } + + public virtual bool IsGenericTypeDefinition + { + [Pure] get { return false; } } @@ -1128,22 +1212,23 @@ namespace System get { return false; } } - public virtual int GenericParameterPosition { - [Pure] - get {throw new InvalidOperationException(Environment.GetResourceString("Arg_NotGenericParameter")); } + public virtual int GenericParameterPosition + { + [Pure] + get { throw new InvalidOperationException(Environment.GetResourceString("Arg_NotGenericParameter")); } } - public virtual bool ContainsGenericParameters + public virtual bool ContainsGenericParameters { [Pure] - get + get { if (HasElementType) return GetRootElementType().ContainsGenericParameters; if (IsGenericParameter) return true; - + if (!IsGenericType) return false; @@ -1168,50 +1253,59 @@ namespace System throw new InvalidOperationException(); } - public bool IsByRef { - [Pure] - get {return IsByRefImpl();} + public bool IsByRef + { + [Pure] + get { return IsByRefImpl(); } } - public bool IsPointer { - [Pure] - get {return IsPointerImpl();} + public bool IsPointer + { + [Pure] + get { return IsPointerImpl(); } } - public bool IsPrimitive { - [Pure] - get {return IsPrimitiveImpl();} + public bool IsPrimitive + { + [Pure] + get { return IsPrimitiveImpl(); } } - public bool IsCOMObject { - [Pure] - get {return IsCOMObjectImpl();} + public bool IsCOMObject + { + [Pure] + get { return IsCOMObjectImpl(); } } #if FEATURE_COMINTEROP - internal bool IsWindowsRuntimeObject { + internal bool IsWindowsRuntimeObject + { [Pure] get { return IsWindowsRuntimeObjectImpl(); } } - internal bool IsExportedToWindowsRuntime { + internal bool IsExportedToWindowsRuntime + { [Pure] get { return IsExportedToWindowsRuntimeImpl(); } } #endif // FEATURE_COMINTEROP - public bool HasElementType { - [Pure] - get {return HasElementTypeImpl();} - } + public bool HasElementType + { + [Pure] + get { return HasElementTypeImpl(); } + } + + public bool IsContextful + { + [Pure] + get { return IsContextfulImpl(); } + } - public bool IsContextful { - [Pure] - get {return IsContextfulImpl();} + public bool IsMarshalByRef + { + [Pure] + get { return IsMarshalByRefImpl(); } } - public bool IsMarshalByRef { - [Pure] - get {return IsMarshalByRefImpl();} - } - // Protected routine to determine if this class represents a value class // The default implementation of IsValueTypeImpl never returns true for non-runtime types. protected virtual bool IsValueTypeImpl() @@ -1228,7 +1322,7 @@ namespace System // Protected routine to get the attributes. abstract protected TypeAttributes GetAttributeFlagsImpl(); - + // Protected routine to determine if this class represents an Array abstract protected bool IsArrayImpl(); @@ -1237,31 +1331,34 @@ namespace System // Protected routine to determine if this class is a Pointer abstract protected bool IsPointerImpl(); - + // Protected routine to determine if this class represents a primitive type abstract protected bool IsPrimitiveImpl(); - + // Protected routine to determine if this class represents a COM object abstract protected bool IsCOMObjectImpl(); #if FEATURE_COMINTEROP // Protected routine to determine if this class represents a Windows Runtime object - virtual internal bool IsWindowsRuntimeObjectImpl() { + virtual internal bool IsWindowsRuntimeObjectImpl() + { throw new NotImplementedException(); } // Determines if this type is exported to WinRT (i.e. is an activatable class in a managed .winmd) - virtual internal bool IsExportedToWindowsRuntimeImpl() { + virtual internal bool IsExportedToWindowsRuntimeImpl() + { throw new NotImplementedException(); } #endif // FEATURE_COMINTEROP - public virtual Type MakeGenericType(params Type[] typeArguments) { + public virtual Type MakeGenericType(params Type[] typeArguments) + { Contract.Ensures(Contract.Result<Type>() != null); throw new NotSupportedException(Environment.GetResourceString("NotSupported_SubclassOverride")); } - + // Protected routine to determine if this class is contextful protected virtual bool IsContextfulImpl() { @@ -1278,25 +1375,28 @@ namespace System abstract public Type GetElementType(); [Pure] - public virtual Type[] GetGenericArguments() - { + public virtual Type[] GetGenericArguments() + { throw new NotSupportedException(Environment.GetResourceString("NotSupported_SubclassOverride")); } - public virtual Type[] GenericTypeArguments{ - get{ - if(IsGenericType && !IsGenericTypeDefinition){ + public virtual Type[] GenericTypeArguments + { + get + { + if (IsGenericType && !IsGenericTypeDefinition) + { return GetGenericArguments(); } - else{ + else + { return Type.EmptyTypes; } - } } [Pure] - public virtual Type GetGenericTypeDefinition() + public virtual Type GetGenericTypeDefinition() { Contract.Ensures(Contract.Result<Type>() != null); throw new NotSupportedException(Environment.GetResourceString("NotSupported_SubclassOverride")); @@ -1315,7 +1415,7 @@ namespace System return rootElementType; } -#region Enum methods + #region Enum methods // Default implementations of GetEnumNames, GetEnumValues, and GetEnumUnderlyingType // Subclass of types can override these methods. @@ -1514,7 +1614,7 @@ namespace System t == typeof(char) || t == typeof(bool)); } -#endregion + #endregion public virtual bool IsSecurityCritical { [Pure] get { throw new NotImplementedException(); } } @@ -1562,9 +1662,10 @@ namespace System // For expando object: this is the (Object) IReflectInstance.GetType(). For Type object it is this. // It could also return the baked type or the underlying enum type in RefEmit. See the comment in // code:TypeBuilder.SetConstantValue. - public abstract Type UnderlyingSystemType { + public abstract Type UnderlyingSystemType + { get; - } + } // Returns true of this class is a true subclass of c. Everything // else returns false. If this class and c are the same class false is @@ -1576,29 +1677,30 @@ namespace System Type p = this; if (p == c) return false; - while (p != null) { + while (p != null) + { if (p == c) return true; p = p.BaseType; } return false; } - + // Returns true if the object passed is assignable to an instance of this class. // Everything else returns false. // [Pure] - public virtual bool IsInstanceOfType(Object o) + public virtual bool IsInstanceOfType(Object o) { if (o == null) return false; // No need for transparent proxy casting check here // because it never returns true for a non-rutnime type. - + return IsAssignableFrom(o.GetType()); } - + // Returns true if an instance of Type c may be assigned // to an instance of this class. Return false otherwise. // @@ -1660,7 +1762,7 @@ namespace System { // Interfaces don't derive from other interfaces, they implement them. // So instead of IsSubclassOf, we should use ImplementInterface instead. - if (interfaces[i] == ifaceType || + if (interfaces[i] == ifaceType || (interfaces[i] != null && interfaces[i].ImplementInterface(ifaceType))) return true; } @@ -1693,12 +1795,13 @@ namespace System // This method will return an array of classes based upon the array of // types. - public static Type[] GetTypeArray(Object[] args) { + public static Type[] GetTypeArray(Object[] args) + { if (args == null) throw new ArgumentNullException(nameof(args)); Contract.EndContractBlock(); Type[] cls = new Type[args.Length]; - for (int i = 0;i < cls.Length;i++) + for (int i = 0; i < cls.Length; i++) { if (args[i] == null) throw new ArgumentNullException(); @@ -1760,5 +1863,5 @@ namespace System // private convenience data private const BindingFlags DefaultLookup = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public; internal const BindingFlags DeclaredOnlyLookup = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly; -} + } } |