I need to maintain the state of member variable between 2 method calls
through reflection. for example i have following class in assembly whose
method I am invoking it dynamically using reflection
Class A
{
int lang;
public void SetLang(int x)
{
lang = x;
}
public bool VerifyLang()
{
if (lang == 1033)
return true;
return false;
}
}
I need to call VerifyLang() method through reflection but I am not able to
use SetLang(int x) method to set the expected value of "lang" as the state
will not preserved between 2 method calls through reflection in a same way we
do it through object. Can I set the member variable like in this case "lang"
dynamically by creating the object of Type "Class A" and then invoking the
method VerifyLang() using the same object used earlier to set the member
variable so that state is maintained between multiple invoke methods through
reflection.
Please let me know if my requirement is still not clear.
"Marc Gravell" wrote:
That sounds a very odd thing to do... can you add some context (what
you want to achieve)? there may be better ways of doing this.
No that you can't unload an assembly from an AppDomain; once you have
loaded it once, you are stuck with it - you can't really re-compile it
in-place. Even if you could, you would also have issues if that
assembly was signed.
As for .NET 3; note that 3.0 and 3.5 /mainly/ just add some bits -
there are no fundamental changes (except the thread-pool limits ;-p) -
so the same would apply to 2.0 and upwards (all current CLR 2.x
variants).
In particular, depending on what you are doing, the component-model
(and runtime [rather than compile-time] version of reflection) may
offer some options for updating attributes, but there are probably
easier ways of doing it...
So: what are you trying to pass in the attribute? And what is
consuming it? Is it your custom code, or library code (such as Linq-to-
Sql attributes).
Marc