Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing a property or method by passing string to a function
    primarykey
    data
    text
    <p>I have a .net assembly providing a huge number of API's and I need to write a COM wrapper for it . I can not write interfaces to each and every method and property provided my the .net assembly due to time constraints. Instead What i plan to do is to write a generic commandParser function which takes the string argument giving the full path (?) of the property or method being referred and in turn the method has to call the correct property or method . e.g suppose i need to set the property Visible , i would pass the string as below (refer image also for the class structure) or if need to call a method</p> <p><strong>"APx.AcousticResponse.AcquiredWaveform.DeltaCursor.Visible"</strong></p> <p><strong>or</strong></p> <p><strong>"APx.BandpassLevel.FixedTuningFrequency.GetValue(Unit)"**</strong></p> <p>Obviously i am clueless , I know using reflections it is possible but i am not at there yet.Here is the dummy code i have been working so far with out any success :P</p> <pre><code>public bool methodFromString(string methodName,object [] parameteres) { string [] split = methodName.Split(new char []{'.'}); apx = new APx500(); Type wrapType = apx .GetType(); FieldInfo[] fields = wrapType.GetFields(); MemberInfo[] members = wrapType.GetMembers(); Console.WriteLine(members.Length); MethodInfo [] methods = wrapType.GetMethods(); foreach (MemberInfo mem in members) { //Console.WriteLine(mem.Name); if(mem.Name == split[0]) { Console.WriteLine(mem.Name); Type memType = mem.GetType(); MethodInfo[] temp = memType.GetMethods(); foreach (MethodInfo t in temp) { Console.WriteLine(memType.Name); } } //if (met.Name == methodName) //{ // try // { // met.Invoke(APx, parameteres); // break; // } // catch (TargetInvocationException ex) // { // Console.WriteLine(ex.Message); // Console.WriteLine(ex.InnerException); // break; // } //} } // MethodInfo theMethod = wrapType.GetMethod(methodName); //theMethod.Invoke(APx, parameteres); //wrapType.InvokeMember(methodName, // BindingFlags.InvokeMethod | BindingFlags.Public | // BindingFlags.Static, // null, // null, // parameteres); return true; } </code></pre> <p>Any hints or help is much appreciated</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload