/// <summary> /// Returns all the public properties of for the specified type. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to get the properties for.</param> /// <returns>An array of <see cref="PropertyInfo" /> objects representing all the public properties defined for the specified type.-or- An empty array of type <see cref="PropertyInfo" />, if no public properties are defined for the specified type.</returns> public static IReadOnlyList <PropertyInfo> GetProperties(this ITypeIntrospectionProvider provider, Type type) => NotNull(NotNull(provider)).GetProperties(type, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
/// <summary> /// Gets a value indicating whether the string format attribute AutoClass is selected for the specified <paramref name="type"/>. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to check.</param> /// <returns>true if the string format attribute AutoClass is selected for the <paramref name="type"/>; otherwise, false.</returns> public static bool IsAutoClass(this ITypeIntrospectionProvider provider, Type type) => (NotNull(provider).GetAttributes(type) & TypeAttributes.StringFormatMask) == TypeAttributes.AutoClass;
/// <summary> /// Returns all the public types nested in the specified type. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to get the nested types for.</param> /// <returns>An array of <see cref="Type"/> objects representing all the public nested types defined for the specified type.-or- An empty array of type <see cref="Type"/>, if no public nested types are defined for the specified type.</returns> public static IReadOnlyList <Type> GetNestedTypes(this ITypeIntrospectionProvider provider, Type type) => NotNull(NotNull(provider)).GetNestedTypes(type, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
/// <summary> /// Gets the initializer for the specified <paramref name="type"/>. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to get the initializer for.</param> /// <returns>A <see cref="ConstructorInfo" /> representing the class constructor for the specified <paramref name="type"/>.</returns> public static ConstructorInfo TypeInitializer(this ITypeIntrospectionProvider provider, Type type) => NotNull(NotNull(provider)).GetConstructor(type, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, CallingConventions.Any, Type.EmptyTypes, modifiers: null);
/// <summary> /// Returns all the public the constructors defined for the specified type. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to get the constructors for.</param> /// <returns>An array of <see cref="ConstructorInfo" /> objects representing all the public constructors defined for the specified type.-or- An empty array of type <see cref="ConstructorInfo" />, if no public constructors are defined for the specified type, or if none of the defined constructors match the binding constraints.</returns> public static IReadOnlyList <ConstructorInfo> GetConstructors(this ITypeIntrospectionProvider provider, Type type) => NotNull(NotNull(provider)).GetConstructors(type, BindingFlags.Instance | BindingFlags.Public);
/// <summary> /// Gets a value indicating whether the specified <paramref name="type"/> has a <see cref="System.Runtime.InteropServices.ComImportAttribute" /> attribute applied, indicating that it was imported from a COM type library. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to check.</param> /// <returns>true if the specified <paramref name="type"/> has a <see cref="System.Runtime.InteropServices.ComImportAttribute" />; otherwise, false.</returns> public static bool IsImport(this ITypeIntrospectionProvider provider, Type type) => (NotNull(provider).GetAttributes(type) & TypeAttributes.Import) > TypeAttributes.NotPublic;
/// <summary> /// Gets a value indicating whether the specified <paramref name="type"/> object represents a type whose definition is nested inside the definition of another type. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to check.</param> /// <returns>true if the specified <paramref name="type"/> is nested inside another type; otherwise, false.</returns> public static bool IsNested(this ITypeIntrospectionProvider provider, Type type) => NotNull(NotNull(provider)).GetDeclaringType(type) != null;
/// <summary> /// Searches for the specified public method whose parameters match the specified generic parameter count and argument types. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to get the method for.</param> /// <param name="name">The string containing the name of the method to get.</param> /// <param name="genericParameterCount">The number of generic type parameters of the method.</param> /// <param name="types">An array of <see cref="Type"/> objects representing the number, order, and type of the parameters for the method to get.-or- An empty array of the type <see cref="Type"/> to get a method that takes no parameters.</param> /// <returns>An object representing the method that matches the specified requirements, if found; otherwise, null.</returns> public static MethodInfo GetMethod(this ITypeIntrospectionProvider provider, Type type, string name, int genericParameterCount, Type[] types) => NotNull(NotNull(provider)).GetMethod(type, name, genericParameterCount, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public, binder: null, CallingConventions.Any, types, modifiers: null);
/// <summary> /// Searches for the specified method whose parameters match the specified generic parameter count, argument types and modifiers, using the specified binding constraints. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to get the method for.</param> /// <param name="name">The string containing the name of the method to get.</param> /// <param name="genericParameterCount">The number of generic type parameters of the method.</param> /// <param name="bindingAttr">A bitmask comprised of one or more <see cref="BindingFlags" /> that specify how the search is conducted.</param> /// <param name="binder">An object that defines a set of properties and enables binding, which can involve selection of an overloaded method, coercion of argument types, and invocation of a member through reflection.-or- A null reference, to use the <see cref="Type.DefaultBinder" />.</param> /// <param name="types">An array of <see cref="Type"/> objects representing the number, order, and type of the parameters for the method to get.-or- An empty array of the type <see cref="Type"/> to get a method that takes no parameters.</param> /// <param name="modifiers">An array of <see cref="ParameterModifier" /> objects representing the attributes associated with the corresponding element in the <paramref name="types" /> array. The default binder does not process this parameter.</param> /// <returns>An object representing the method that matches the specified requirements, if found; otherwise, null.</returns> public static MethodInfo GetMethod(this ITypeIntrospectionProvider provider, Type type, string name, int genericParameterCount, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers) => NotNull(NotNull(provider)).GetMethod(type, name, genericParameterCount, bindingAttr, binder, CallingConventions.Any, types, modifiers);
/// <summary> /// Searches for the public members with the specified name. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to get the members for.</param> /// <param name="name">The string containing the name of the members to get.</param> /// <returns>An array of <see cref="MemberInfo" /> objects representing the members with the specified name, if found; otherwise, an empty array.</returns> public static IReadOnlyList <MemberInfo> GetMember(this ITypeIntrospectionProvider provider, Type type, string name) => NotNull(NotNull(provider)).GetMember(type, name, MemberTypes.All, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
/// <summary> /// Searches for the specified members, using the specified binding constraints. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to get the members for.</param> /// <param name="name">The string containing the name of the members to get.</param> /// <param name="bindingAttr">A bitmask comprised of one or more <see cref="BindingFlags" /> that specify how the search is conducted.</param> /// <returns>An array of <see cref="MemberInfo" /> objects representing the members with the specified name, if found; otherwise, an empty array.</returns> public static IReadOnlyList <MemberInfo> GetMember(this ITypeIntrospectionProvider provider, Type type, string name, BindingFlags bindingAttr) => NotNull(NotNull(provider)).GetMember(type, name, MemberTypes.All, bindingAttr);
/// <summary> /// Searches for a public instance constructor whose parameters match the specified argument types. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to get the constructor for.</param> /// <param name="types">An array of <see cref="Type"/> objects representing the number, order, and type of the parameters for the constructor to get.-or- An empty array of the type <see cref="Type"/> to get a constructor that takes no parameters.</param> /// <returns>An object representing the constructor that matches the specified requirements, if found; otherwise, null.</returns> public static ConstructorInfo GetConstructor(this ITypeIntrospectionProvider provider, Type type, Type[] types) => NotNull(NotNull(provider)).GetConstructor(type, BindingFlags.Instance | BindingFlags.Public, binder: null, types, modifiers: null);
/// <summary> /// Searches for a constructor whose parameters match the specified argument types and modifiers, using the specified binding constraints. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to get the constructor for.</param> /// <param name="bindingAttr">A bitmask comprised of one or more <see cref="BindingFlags" /> that specify how the search is conducted.</param> /// <param name="binder">An object that defines a set of properties and enables binding, which can involve selection of an overloaded method, coercion of argument types, and invocation of a member through reflection.-or- A null reference, to use the <see cref="Type.DefaultBinder" />.</param> /// <param name="types">An array of <see cref="Type"/> objects representing the number, order, and type of the parameters for the constructor to get.-or- An empty array of the type <see cref="Type"/> to get a constructor that takes no parameters.</param> /// <param name="modifiers">An array of <see cref="ParameterModifier" /> objects representing the attributes associated with the corresponding element in the <paramref name="types" /> array. The default binder does not process this parameter.</param> /// <returns>An object representing the constructor that matches the specified requirements, if found; otherwise, null.</returns> public static ConstructorInfo GetConstructor(this ITypeIntrospectionProvider provider, Type type, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers) => NotNull(NotNull(provider)).GetConstructor(type, bindingAttr, binder, CallingConventions.Any, types, modifiers);
/// <summary> /// Searches for the interface with the specified name. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to get the interface for.</param> /// <param name="name">The string containing the name of the interface to get. For generic interfaces, this is the mangled name.</param> /// <returns>An object representing the interface with the specified name, implemented or inherited by the specified type, if found; otherwise, null.</returns> public static Type GetInterface(this ITypeIntrospectionProvider provider, Type type, string name) => NotNull(NotNull(provider)).GetInterface(type, name, ignoreCase: false);
/// <summary> /// Gets a value indicating whether the specified <paramref name="type"/> is a class; that is, not a value type or interface. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to check.</param> /// <returns>true if the specified <paramref name="type"/> is a class; otherwise, false.</returns> public static bool IsClass(this ITypeIntrospectionProvider provider, Type type) => (NotNull(provider).GetAttributes(type) & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Class && !NotNull(provider).IsValueType(type);
/// <summary> /// Searches for a public nested type with the specified name. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to get the nested type for.</param> /// <param name="name">The name of the nested type to search for.</param> /// <returns>An object representing the nested type that matches the specified requirements, if found; otherwise, null.</returns> public static Type GetNestedType(this ITypeIntrospectionProvider provider, Type type, string name) => NotNull(NotNull(provider)).GetNestedType(type, name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
/// <summary> /// Gets a value indicating whether the class layout attribute ExplicitLayout is selected for the specified <paramref name="type"/>. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to check.</param> /// <returns>true if the class layout attribute ExplicitLayout is selected for the <paramref name="type"/>; otherwise, false.</returns> public static bool IsExplicitLayout(this ITypeIntrospectionProvider provider, Type type) => (NotNull(provider).GetAttributes(type) & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout;
/// <summary> /// Searches for the specified public property whose parameters match the specified argument types. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to get the property for.</param> /// <param name="name">The string containing the name of the property to get.</param> /// <param name="types">An array of <see cref="Type"/> objects representing the number, order, and type of the parameters for the indexed property to get.-or- An empty array of the type <see cref="Type"/> to get a property that is not indexed.</param> /// <returns>An object representing the property that matches the specified requirements, if found; otherwise, null.</returns> public static PropertyInfo GetProperty(this ITypeIntrospectionProvider provider, Type type, string name, Type[] types) => NotNull(NotNull(provider)).GetProperty(type, name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public, binder: null, returnType: null, types, modifiers: null);
/// <summary> /// Gets a value indicating whether the class layout attribute SequentialLayout is selected for the specified <paramref name="type"/>. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to check.</param> /// <returns>true if the class layout attribute SequentialLayout is selected for the <paramref name="type"/>; otherwise, false.</returns> public static bool IsLayoutSequential(this ITypeIntrospectionProvider provider, Type type) => (NotNull(provider).GetAttributes(type) & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout;
/// <summary> /// Searches for the specified public property with the specified name. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to get the property for.</param> /// <param name="name">The string containing the name of the property to get.</param> /// <returns>An object representing the property that matches the specified requirements, if found; otherwise, null.</returns> public static PropertyInfo GetProperty(this ITypeIntrospectionProvider provider, Type type, string name) => NotNull(NotNull(provider)).GetProperty(type, name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
/// <summary> /// Gets a value indicating whether the specified <paramref name="type"/> is nested and visible only within its own assembly. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to check.</param> /// <returns>true if the specified <paramref name="type"/> is nested and visible only within its own assembly; otherwise, false.</returns> public static bool IsNestedAssembly(this ITypeIntrospectionProvider provider, Type type) => (NotNull(provider).GetAttributes(type) & TypeAttributes.VisibilityMask) == TypeAttributes.NestedAssembly;
/// <summary> /// Gets a value indicating whether the specified <paramref name="type"/> has a name that requires special handling. /// </summary> /// <param name="provider">The reflection introspection provider.</param> /// <param name="type">The type to check.</param> /// <returns>true if the specified <paramref name="type"/> has a name that requires special handling; otherwise, false.</returns> public static bool IsSpecialName(this ITypeIntrospectionProvider provider, Type type) => (NotNull(provider).GetAttributes(type) & TypeAttributes.SpecialName) > TypeAttributes.NotPublic;