c# - Calling parent method from child window through delegate -


i have parent form (mainform), call wpf window (childwpf). in parent window have data access methods. need way call them childwpf , have them return stuff me. wanted through delegates (i dont want pass mainform referance).

in childwpf:

public delegate list<string> mainformmethod(); 

now cant seem find way connect hanlder declaring in mainform childwpf. maybe using events better aproach?

extract data access methods isomedataaccess interface , transfer data access logic mainform class realize interface. after may share class in childwpf too. send instance of isomedataaccess interface contructor parameter when create childwpf form.
edit: create interface part of data access layer needed childwpf in childwpf project. may implement inreface in dataaccess class direct or create intermediate adapter class.

direct implementation:

public class dataaccess : ichilddataaccess {     public void somedatalogic1()     {}      public void somedatalogic2()     {}      public void somedatalogic3()     {} }  public interface ichilddataaccess {     void somedatalogic1();     void somedatalogic3(); } 

or intermediate class:

public class dataaccess {     public void somedatalogic1()     {}      public void somedatalogic2()     {}      public void somedatalogic3()     {} }  public class childdataaccess : ichilddataaccess {     private readonly dataaccess _dataaccess;      public childdataaccess( dataaccess dataaccess )     {         if ( dataaccess == null )             throw new argumentexception( nameof( dataaccess ) );         _dataaccess = dataaccess;     }      public void somedatalogic1()     {         _dataaccess.somedatalogic1();     }      public void somedatalogic3()     {         _dataaccess.somedatalogic3();     } }  public interface ichilddataaccess {     void somedatalogic1();     void somedatalogic3(); } 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -