System.Type.GetMethod C# (CSharp) Method

GetMethod() public method

Searches for the specified method, using the specified binding constraints.
More than one method is found with the specified name and matching the specified binding constraints. is null.
public GetMethod ( string name, BindingFlags bindingAttr ) : MethodInfo
name string The string containing the name of the method to get.
bindingAttr BindingFlags A bitmask comprised of one or more that specify how the search is conducted.-or- Zero, to return null.
return MethodInfo
        public MethodInfo GetMethod(string name, BindingFlags bindingAttr)
        {
            if (name == null)
                throw new ArgumentNullException("name");
            else
                return this.GetMethodImpl(name, bindingAttr, (Binder)null, CallingConventions.Any, (Type[])null, (ParameterModifier[])null);
        }

Same methods

Type::GetMethod ( string name ) : MethodInfo
Type::GetMethod ( string name, Type types ) : MethodInfo

Usage Example

Example #1
0
        public static bool GetPrimitives(Type containerType, Type type, out MethodInfo writer, out MethodInfo reader)
        {
            if (type.IsEnum)
                type = Enum.GetUnderlyingType(type);

            if (type.IsGenericType == false)
            {
                writer = containerType.GetMethod("WritePrimitive", BindingFlags.Static | BindingFlags.Public | BindingFlags.ExactBinding, null,
                    new Type[] { typeof(Stream), type }, null);

                reader = containerType.GetMethod("ReadPrimitive", BindingFlags.Static | BindingFlags.Public | BindingFlags.ExactBinding, null,
                    new Type[] { typeof(Stream), type.MakeByRefType() }, null);
            }
            else
            {
                var genType = type.GetGenericTypeDefinition();

                writer = GetGenWriter(containerType, genType);
                reader = GetGenReader(containerType, genType);
            }

            if (writer == null && reader == null)
                return false;
            else if (writer != null && reader != null)
                return true;
            else
                throw new InvalidOperationException(String.Format("Missing a {0}Primitive() for {1}",
                    reader == null ? "Read" : "Write", type.FullName));
        }
All Usage Examples Of System.Type::GetMethod