System.Type.GetMethod C# (CSharp) Method

GetMethod() public method

Searches for the public method with the specified name.
More than one method is found with the specified name. is null.
public GetMethod ( string name ) : MethodInfo
name string The string containing the name of the public method to get.
return MethodInfo
        public MethodInfo GetMethod(string name)
        {
            if (name == null)
                throw new ArgumentNullException("name");
            else
                return this.GetMethodImpl(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public, (Binder)null, CallingConventions.Any, (Type[])null, (ParameterModifier[])null);
        }

Same methods

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

Usage Example

Ejemplo n.º 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