Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use an anonymous method to wrap the call.</p> <p>For example, assuming you have a datalayer class, add a similar method to the data layer:</p> <pre><code>public delegate void DoSomethingInvoker(); class DataLayer { //myReader needs to be declared externally in other to access it from the doSomething delegate public void MethodThatGetsAsXmlReader(XmlReader myReader, DoSomethingInvoker doSomething) { myReader = GetXmlReaderFromDB(); doSomething(); CloseDbConnection(); //close connections, do cleanup, and any other book keeping can be done after the doSomething() call } } </code></pre> <p>To call/use it, you simply do this in your high level class</p> <pre><code>DataLayer dl = new DataLayer(); XmlReader myReader = null; //variables declared outside the scope of the anonymous method are still accessible inside it through the magic of closures dl.MethodThatGetsAsXmlReader(myReader, delegate() { //do all work that involves myReader here myReader.read(); Console.out.println(myReader.value); }); //at this point myReader is closed and cannot be used </code></pre> <p>Basically, you pass the code you want to execute to the datalayer, the data layer fetches the xmlreader, calls your code against it, and then does cleanup.</p> <p>I use a similar technique for wrapping transaction logic in my code</p> <pre><code>DataLayer dl = new DataLayer(); dl.Transaction(delegate() { dl.DbCall1(); dl.DbCall2(); dl.DbCall3(); }); </code></pre> <p>It makes the code nice and readable, while still keeping it organized and layered;</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload