c# - Is this instance of B a property of an instance of A? -
take @ scenario:
//base class abstract class aaa { } //class 1 class bbb : aaa { //field of zzz type public zzz zfield = new zzz(); } //class 2 class zzz { public string foo() { return imapropertyofanaaaderivedclass ? "yes" : "no"; } bool imapropertyofanaaaderivedclass { { /* here */ } } } //running test new bbb().zfield.foo(); // => expected "yes" new zfield.foo(); // => expected "no"
my question is:
is there way implement imapropertyofanaaaderivedclass
?
no. won;t possible in straight forward way. since zzz has not direct relation aaa. 1 possible way have public object exposed zzz , pass bbb ref , check that:
public class zzz { public string foo() { return imapropertyofanaaaderivedclass ? "yes" : "no"; } bool imapropertyofanaaaderivedclass { { return testforaaa aaa; } } public object testforaaa { get; set; } }
and while using pass bbb's ref object.
of course adds dependency works!
Comments
Post a Comment