Esempio n. 1
0
        /// <summary>
        /// Searches for the specified field, using the specified binding constraints.
        /// </summary>
        /// <param name="type">Type on which to perform lookup</param>
        /// <param name="name">The string containing the name of the data field to get. </param>
        /// <param name="bindingAttr">A bitmask comprised of one or more BindingFlags that specify how the search is conducted.
        /// -or-
        /// Zero, to return null.</param>
        /// <returns>An object representing the field that matches the specified requirements, if found; otherwise, null.</returns>
        public static FieldInfo GetField(Type type, string name, BindingFlags bindingAttr)
        {
            GetTypeInfoOrThrow(type);

            IEnumerable <FieldInfo> fields = MemberEnumerator.GetMembers <FieldInfo>(type, name, bindingAttr);

            return(Disambiguate(fields));
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the EventInfo object representing the specified event, using the specified binding constraints.
        /// </summary>
        /// <param name="type">Type on which to perform lookup</param>
        /// <param name="name">The string containing the name of an event which is declared or inherited by the current Type. </param>
        /// <param name="bindingAttr">A bitmask comprised of one or more BindingFlags that specify how the search is conducted.
        /// -or-
        /// Zero, to return null. </param>
        /// <returns>The object representing the specified event that is declared or inherited by the current Type, if found; otherwise, null.</returns>
        public static EventInfo GetEvent(Type type, string name, BindingFlags bindingAttr)
        {
            GetTypeInfoOrThrow(type);

            IEnumerable <EventInfo> events = MemberEnumerator.GetMembers <EventInfo>(type, name, bindingAttr);

            return(Disambiguate(events));
        }
Esempio n. 3
0
        /// <summary>
        /// Searches for events that are declared or inherited by the current Type, using the specified binding constraints.
        /// </summary>
        /// <param name="type">Type on which to perform lookup</param>
        /// <param name="bindingAttr">A bitmask comprised of one or more BindingFlags that specify how the search is conducted.
        /// -or-
        /// Zero, to return null. </param>
        /// <returns>An array of EventInfo objects representing all events that are declared or inherited by the current Type that match the specified binding constraints.
        /// -or-
        /// An empty array of type EventInfo, if the current Type does not have events, or if none of the events match the binding constraints.</returns>
        public static EventInfo[] GetEvents(Type type, BindingFlags bindingAttr)
        {
            GetTypeInfoOrThrow(type);

            IEnumerable <EventInfo> events = MemberEnumerator.GetMembers <EventInfo>(type, MemberEnumerator.AnyName, bindingAttr);

            return(events.ToArray());
        }
Esempio n. 4
0
        /// <summary>
        /// Searches for the specified property, using the specified binding constraints.
        /// </summary>
        /// <param name="type">Type on which to perform lookup</param>
        /// <param name="name">The string containing the name of the property to get. </param>
        /// <param name="bindingAttr">A bitmask comprised of one or more BindingFlags that specify how the search is conducted.
        /// -or-
        /// Zero, to return null. </param>
        /// <returns>A bitmask comprised of one or more BindingFlags that specify how the search is conducted.
        /// -or-
        /// Zero, to return null. </returns>
        public static PropertyInfo GetProperty(Type type, string name, BindingFlags bindingAttr)
        {
            GetTypeInfoOrThrow(type);

            IEnumerable <PropertyInfo> properties = MemberEnumerator.GetMembers <PropertyInfo>(type, name, bindingAttr);

            return(Disambiguate(properties));
        }
Esempio n. 5
0
        /// <summary>
        /// Searches for the specified property, using the specified binding constraints.
        /// </summary>
        /// <param name="type">Type on which to perform lookup</param>
        /// <param name="name">The string containing the name of the property to get. </param>
        /// <param name="bindingAttr">A bitmask comprised of one or more BindingFlags that specify how the search is conducted
        /// -or-
        /// Zero, to return an empty array. </param>
        /// <returns>An array of PropertyInfo objects representing all the public property defined for the current Type
        /// -or-
        /// An empty array of type PropertyInfo, if no properties matching the constraints are found.</returns>
        public static PropertyInfo[] GetProperties(this Type type, string name, BindingFlags bindingAttr)
        {
            GetTypeInfoOrThrow(type);

            IEnumerable <PropertyInfo> properties = MemberEnumerator.GetMembers <PropertyInfo>(type, name, bindingAttr);

            return(properties.ToArray());
        }
Esempio n. 6
0
        /// <summary>
        /// Searches for the types nested in the current Type, using the specified binding constraints.
        /// </summary>
        /// <param name="type">Type on which to perform lookup</param>
        /// <param name="bindingAttr">A bitmask comprised of one or more BindingFlags that specify how the search is conducted -or- Zero, to return null. </param>
        /// <returns>An array of Type objects representing all the types nested in the current Type that match the specified binding constraints (the search is not recursive), or an empty array of type Type, if no nested types are found that match the binding constraints.</returns>
        public static Type[] GetNestedTypes(Type type, BindingFlags bindingAttr)
        {
            GetTypeInfoOrThrow(type);

            IEnumerable <TypeInfo> types = MemberEnumerator.GetMembers <TypeInfo>(type, MemberEnumerator.AnyName, bindingAttr);

            return(types.Select(t => t.AsType()).ToArray());
        }
Esempio n. 7
0
        /// <summary>
        /// Searches for the specified method, using the specified binding constraints.
        /// </summary>
        /// <param name="type">Type on which to perform lookup</param>
        /// <param name="name">The string containing the name of the method to get. </param>
        /// <param name="bindingAttr">A bitmask comprised of one or more BindingFlags that specify how the search is conducted
        /// -or-
        /// Zero, to return an empty array. </param>
        /// <returns>An array of MethodInfo objects representing all the public methods defined for the current Type
        /// -or-
        /// An empty array of type MethodInfo, if no public methods are defined for the current Type.</returns>
        public static MethodInfo[] GetMethods(Type type, string name, BindingFlags bindingAttr)
        {
            GetTypeInfoOrThrow(type);

            IEnumerable <MethodInfo> methods = MemberEnumerator.GetMembers <MethodInfo>(type, name, bindingAttr);

            return(methods.ToArray());
        }
Esempio n. 8
0
        /// <summary>
        /// Searches for the specified method, using the specified binding constraints.
        /// </summary>
        /// <param name="type">Type on which to perform lookup</param>
        /// <param name="name">The string containing the name of the method to get.</param>
        /// <param name="bindingAttr">A bitmask comprised of one or more BindingFlags that specify how the search is conducted
        /// -or-
        /// Zero, to return null. </param>
        /// <returns>An object representing the method that matches the specified requirements, if found; otherwise, null.</returns>
        public static MethodInfo GetMethod(Type type, string name, BindingFlags bindingAttr)
        {
            GetTypeInfoOrThrow(type);

            IEnumerable <MethodInfo> methods = MemberEnumerator.GetMembers <MethodInfo>(type, name, bindingAttr);

            return(Disambiguate(methods));
        }
Esempio n. 9
0
        /// <summary>
        /// Searches for the specified nested type, using the specified binding constraints.
        /// </summary>
        /// <param name="type">Type on which to perform lookup</param>
        /// <param name="name">The string containing the name of the nested type to get. </param>
        /// <param name="bindingAttr">A bitmask comprised of one or more BindingFlags that specify how the search is conducted
        /// -or-
        /// Zero, to return null. </param>
        /// <returns>An object representing the nested type that matches the specified requirements, if found; otherwise, null.</returns>
        public static Type GetNestedType(Type type, string name, BindingFlags bindingAttr)
        {
            GetTypeInfoOrThrow(type);

            IEnumerable <TypeInfo> nestedTypes = MemberEnumerator.GetMembers <TypeInfo>(type, name, bindingAttr);
            TypeInfo nestedType = Disambiguate(nestedTypes);

            return(nestedType == null ? null : nestedType.AsType());
        }
Esempio n. 10
0
        private static LowLevelList <MemberInfo> GetMembers(Type type, object nameFilterOrAnyName, BindingFlags bindingAttr)
        {
            LowLevelList <MemberInfo> members = new LowLevelList <MemberInfo>();

            members.AddRange(MemberEnumerator.GetMembers <MethodInfo>(type, nameFilterOrAnyName, bindingAttr, allowPrefixing: true));
            members.AddRange(MemberEnumerator.GetMembers <ConstructorInfo>(type, nameFilterOrAnyName, bindingAttr, allowPrefixing: true));
            members.AddRange(MemberEnumerator.GetMembers <PropertyInfo>(type, nameFilterOrAnyName, bindingAttr, allowPrefixing: true));
            members.AddRange(MemberEnumerator.GetMembers <EventInfo>(type, nameFilterOrAnyName, bindingAttr, allowPrefixing: true));
            members.AddRange(MemberEnumerator.GetMembers <FieldInfo>(type, nameFilterOrAnyName, bindingAttr, allowPrefixing: true));
            members.AddRange(MemberEnumerator.GetMembers <TypeInfo>(type, nameFilterOrAnyName, bindingAttr, allowPrefixing: true));

            return(members);
        }
Esempio n. 11
0
        /// <summary>
        /// Searches for the fields defined for the current Type, using the specified binding constraints.
        /// </summary>
        /// <param name="type">Type on which to perform lookup</param>
        /// <param name="bindingAttr">A bitmask comprised of one or more BindingFlags that specify how the search is conducted
        /// -or-
        /// Zero, to return an empty array. </param>
        /// <returns>An array of FieldInfo objects representing all fields defined for the current Type that match the specified binding constraints.
        /// -or-
        /// An empty array of type FieldInfo, if no fields are defined for the current Type, or if none of the defined fields match the binding constraints.</returns>
        public static FieldInfo[] GetFields(Type type, BindingFlags bindingAttr)
        {
            GetTypeInfoOrThrow(type);

            return(MemberEnumerator.GetMembers <FieldInfo>(type, MemberEnumerator.AnyName, bindingAttr).ToArray());
        }