Question

There is some .net Dll library, this Dll contains a class with two methods with the same name, such as:

void b()
{

}

bool b()
{

}

It is not possible in C#, but it appear to be OK internally, how can I call one method from my code when adding such library?

I need the simplest way, I know it is OK using reflection, but are there any other easier way?

*EDIT*

I am getting this in the metadata of the library:

#region Assembly XXXX.dll, v xxxx
// C:\....................
#endregion


namespace XXXX.YYYYY
{
    public class a : IDisposable
    {

        .
        .
        .
        .
        .
        public void b();
        public bool b();
        .
        .
        .
        .
        public void Dispose();
    }
}
Was it helpful?

Solution

Ooh, that's horrible. The only way you can call that from C# is via reflection; you'd probably need to use GetMethods() and find the one you want from the array (the GetMethod() overloads may not love that).

Once you have the MethodInfo, you can either just use Invoke, or you can use Delegate.CreateDelegate to get a typed delegate you can re-use. It depends how often you will be calling it, as to which of those is preferable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top