samedi 6 juillet 2019

internal static class in assembly reflection

I am working on a library which contains static member, cause of static members application does not work as we expect, so because of this I decided to load and unload dll and execute needed methods by reflection but when I Invoke methods they don't works properly.

Reflection:

Assembly assembly = Assembly.LoadFrom(path);
Type myType = assembly.GetType("myType");  
MethodInfo loginMethod = myType.GetMethod("Login");
MethodInfo getPatient = myType.GetMethod("GetPatient"); 
object obj = Activator.CreateInstance(myType);  
var login = loginMethod.Invoke(obj, new object[] { m_ServerAddress, _userName, _pass });  
var objPatient = getPatient.Invoke(obj, new object[] { id });

but objPatient is empty, when I decompile the dll I see there is static class, which I guess this is because of static member:

public void Login(string serverName, string username, string password)
{
    if (!this.ccc747141fb6392d84865c5d1014f11f3(username, password))
    {
    Thread.Sleep(10000);
    throw new Exception(ca766e7a1b8b0f6278bb67c73892b2c2d.errLogin);
    }
    cde97ebf3573a6f34016e9de8af2b15f1.ServerName = serverName;
    cde97ebf3573a6f34016e9de8af2b15f1.DatabaseName = c9b0e944124439997ede08a185578afb8.c747006f77fa5666acff05fdaf980a03e(321);
    cde97ebf3573a6f34016e9de8af2b15f1.Username = c9fe502faad3cce0654f4449ba8ea22f9.cfb96f7f308c7ca5e8bbd3c8511c03c6c(c9b0e944124439997ede08a185578afb8.c747006f77fa5666acff05fdaf980a03e(332), true);
    cde97ebf3573a6f34016e9de8af2b15f1.Password = c9fe502faad3cce0654f4449ba8ea22f9.cfb96f7f308c7ca5e8bbd3c8511c03c6c(c9b0e944124439997ede08a185578afb8.c747006f77fa5666acff05fdaf980a03e(381), true);
    this.c0bf0a564aff397c8fc7b99a5467c3ce0();
} 
private void c0bf0a564aff397c8fc7b99a5467c3ce0()
{
    this.MyHospConfigBS.c0bf0a564aff397c8fc7b99a5467c3ce0();
} 
public Patient GetPatient(string admCode)
{
    if (cde97ebf3573a6f34016e9de8af2b15f1.IsAuthorized)
    {
            //Logic
    } 
}

and static class:

internal static class cde97ebf3573a6f34016e9de8af2b15f1
{
    private static List<HospConfig> c416889c951ebe9d47ec584d2cf4ea459; 
    internal static string ServerName { get; set; } 
    internal static string DatabaseName { get; set; } 
    internal static bool IsAuthorized { get; set; } 
    public static string Username { get; set; } 
    public static string Password { get; set; }
    public static List<HospConfig> c338a440332d407de69db3ac44689eebf
    {
        get
        {
            if (cde97ebf3573a6f34016e9de8af2b15f1.c416889c951ebe9d47ec584d2cf4ea459 == null)
            {
                //Logic
            }
            return cde97ebf3573a6f34016e9de8af2b15f1.c416889c951ebe9d47ec584d2cf4ea459;
        }
        set
        {
            cde97ebf3573a6f34016e9de8af2b15f1.c416889c951ebe9d47ec584d2cf4ea459 = value;
        }
    }
}

Is this because of that internal static class, how reflection should be implemented in these cases?

Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire