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
"APx.AcousticResponse.AcquiredWaveform.DeltaCursor.Visible"
or
"APx.BandpassLevel.FixedTuningFrequency.GetValue(Unit)"**
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
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;
}
Any hints or help is much appreciated