c# - Find the name of the class that eventually does work in a string of method calls -


i have problem need solve , revolves around idea of code following.

public class x {     private y yinstance;     public bool dosomething(){         return y.dosomething();     } }  public class y {     private z zinstance;     public bool dosomething(){         return z.dosomething();     } }  public class z {     public bool dosomething(){         return true;     } } 

i to, having instance of x, beable find out class work, in case "z". however, in case there can number of layers , more 1 path lead final class. please let me know if need clarify anything.

note: need without calling method

is possible?

edit: poor pseudo-code demonstrate use-case little better suggested. note in repository using nhibernate criteria.

public ienumberable<t> getbycriteria(detachedcriteria criterion){     if(criterion.type.getfilterbase() == a)         criterion.appendfilter_a();     if(criterion.type.getfilterbase() == b)         criterion.appendfilter_b();     if(criterion.type.getfilterbase() == c)         criterion.appendfilter_c();     return criterion.execute(); } 

this idea. note in case there 4 possible bases.

this called decorator pattern.

you implement kind of recursive function:

public class x {     private y yinstance;     public bool dosomething(){         return y.dosomething();     }     public type getworkerclasstype(){         return yinstance.getworkerclasstype();     } }  public class y {     private z zinstance;     public bool dosomething(){         return z.dosomething();     }     public type getworkerclasstype(){         return zinstance.gettype();     } }  public class z {     public bool dosomething(){         return true;     } } 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -