vendredi 15 juillet 2016

How to invoke a method on a private static type (or class) in another assembly in .net?

Let's say we have an application called "app.exe" which is using an external assembly called "lib.dll", the assembly contains a static type like following

internal class Foo {
    public static Foo GetInstance(string param1, string param2) {...}
    public string Prop { get; set; }
    public string PublicMethod(string param1) { ... }
    protected string ProtectedMethod(string param1) { ... }
}

What is the best way to call Foo.GetInstance and after use this instance? The class is not implementing any interface (nor does it inherit from any public class). An example is really appreciated.

Update: I know about the principle of OOP, but I'm looking for a technically possible solution here. Being it Reflection, Deturing, Hooking etc. but the most preferable is Reflection. This is merely to unblock the dev team before the 3rd party can adopt their code to fix this mistake (unfortunately we are dealing with lots of bureaucracy here).





Aucun commentaire:

Enregistrer un commentaire