I'm pretty sure this isn't possible, but thought I'd ask anyways.
Say I have:
public class A
{
public B BInstance { get; set; }
}
public class B
{
public Type GetParentType()
{
//...
}
}
Is there any possible way, via reflection, for B
's GetParentType
to return typeof(A)
at runtime?
I know I could simply pass typeof(this)
into B
when I initialize it on A
, I'm just curious.
The answer is no, as far i know, because when you write that
var t = new B () ;
the new B instance has no information on where will be stored, so as that istance has no cognition on the fact that is stored in a var, the ones in your example do not know is put in a property of an A instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With