Single methods with different reset values



  • Are there ways to use uniform methods with the same input parameters, but different reset values? Let's say there are methods.

    public string use_reflection (string param)
    {
    }
    public list<string> use_reflection (string param)
    {
    }
    

    In method, I use a reflexi machine to challenge other methods by their name.

    Type thisType = this.GetType();
    MethodInfo theMethod = thisType.GetMethod("тут имя метода");
    answer = theMethod.Invoke(this, params_obj)
    

    Accordingly, different methods return different types of results, since in the C#, the reset value is not a signature method, the algorithm described will have to produce similar methods. use_reflection For each type of return, or is there any way to circumvent it?



  • For example:

    class Base
    {
        public string use_reflection(string param)
        {
            return "";
        }
    }
    

    class Derived : Base
    {
    new public List<string> use_reflection(string param)
    {
    return null;
    }
    }

    Access or clear caste

    var d = new Derived();
    List<string> r1 = d.use_reflection(null);
    string r2 = ((Base)d).use_reflection(null);

    or through reflexion:

    var methods = typeof(Derived).GetMethods(BindingFlags.Instance | BindingFlags.Public)
    .Where(mi => mi.Name == "use_reflection");
    foreach (var mi in methods)
    Console.WriteLine(mi.ReturnType);


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2