Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

496
Vistas
C# - GetMethod returns null

I have A class:

public abstract class A
{

}

And then I have B class that derives from it:

public sealed class B : A
{
    public void SomeMethod()
    {
        var method = this.GetType().GetMethod("AddText");
    }

    private void AddText(string text)
    {
        ...
    }
}

Why is GetMethod returning null?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

var methodInfo = this.GetType().GetMethod("AddText", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(string) }, null);

Your method has a parameter, you need to use the overload that accepts a type array for the parameter types and the binding flags.

In .net Method signatures are based on their name, their return type, and their parameters.

So if your method has parameters you have to tell Reflection what parameter types it has via a Type[].

over 4 years ago · Santiago Trujillo Denunciar

0

By default, Reflection will only search for public methods.

You need to pass BindingFlags.Instance | BindingFlags.NonPublic.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda