-1

I made a code like this.

private void MakeRowUsingMethodName(string pMethodName,params object[] var)
    {

        DataTable dt = dataSet1.Tables[0];
        DataRow row = dt.NewRow();
        row = dt.NewRow();

        System.Reflection.MethodInfo pMethod = typeof(ShellSection).GetMethod(pMethodName);
        int paramIndex = 0;
        string paramType = string.Empty;
        string paramName = string.Empty;
        int paramCount = pMethod.GetParameters().Length;
        string MethodName = pMethod.Name;

        foreach (ParameterInfo pParameter in pMethod.GetParameters())
        {

            paramIndex = pParameter.Position;
            paramName = pParameter.Name;
            paramType = pParameter.ParameterType.Name;

            row[paramIndex] = var[paramIndex];

        }
        dt.Rows.Add(row);
    }

It's work fine now, but i want more flexibility use other class.

but this part is hard to me.

System.Reflection.MethodInfo pMethod = typeof(ShellSection).GetMethod(pMethodName);

that "ShellSection" is ClassName,

so i wondered about it can be change ClassName to string-value.

And i don't know this method convert to like global method.

If only this part can be modified, I can make more flexible code.

PS.

I'll fix my question.

string className = "ShellSection"; or other things

typeof("ShellSection").GetMethod(pMethodName); or

typeof(className).GetMethod(pMethodName);

I am asking about the possibility and the method of operation as above.

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
jinsu_kim
  • 7
  • 6
  • 1
    Perhaps someting like: https://stackoverflow.com/questions/11107536/convert-string-to-type-in-c-sharp – zaza Nov 08 '18 at 01:50
  • I read them first, but I did not understand English well and did not understand the questions. I briefly let you know how to use it and I applied it immediately. Thank you for your comment. – jinsu_kim Nov 08 '18 at 02:03

1 Answers1

0

You can try to use Type.GetType method it supports you get Type by class string name.

Type.GetType(ShellSection).GetMethod(pMethodName);

instead of

typeof(ShellSection).GetMethod(pMethodName);
D-Shih
  • 44,943
  • 6
  • 31
  • 51