Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Delegate Conversion to Method? [Solved]

Delegate Conversion to Method? [Solved]

Scheduled Pinned Locked Moved C#
helpquestiondebuggingtutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ravi Sant
    wrote on last edited by
    #1

    Hi, I have a code to debug, which in delegate block as below. Since even the F11 steps through it, i think of extracting method out of delegate. I googled much about this with no ready-help.

    private List GetPaginatedProduct(bool IsCalled, IProductPageSortOption paginationOption, IEnumerable additionalCriteria,string reportStartDate, string reportEndDate)
    {

    HibernateDelegate> hibDel = delegate(ISession session)
    {
    ....
    //do something with session .. about 300 lines of code...
    ....
    }

    }

    My question is: Can I call it like: say delegate(ISession session){ call some function(..) }. So that I effectively replace inline code with a function call. Please guide. Thanks. Edit: I was not able to break into anonymous code. Refactoring the delegates to call few methods, containing anonymous code above, made task easier.

    // ♫ 99 little bugs in the code, // 99 bugs in the code // We fix a bug, compile it again // 101 little bugs in the code ♫

    Tell your manager, while you code: "good, cheap or fast: pick two. "

    K B 2 Replies Last reply
    0
    • R Ravi Sant

      Hi, I have a code to debug, which in delegate block as below. Since even the F11 steps through it, i think of extracting method out of delegate. I googled much about this with no ready-help.

      private List GetPaginatedProduct(bool IsCalled, IProductPageSortOption paginationOption, IEnumerable additionalCriteria,string reportStartDate, string reportEndDate)
      {

      HibernateDelegate> hibDel = delegate(ISession session)
      {
      ....
      //do something with session .. about 300 lines of code...
      ....
      }

      }

      My question is: Can I call it like: say delegate(ISession session){ call some function(..) }. So that I effectively replace inline code with a function call. Please guide. Thanks. Edit: I was not able to break into anonymous code. Refactoring the delegates to call few methods, containing anonymous code above, made task easier.

      // ♫ 99 little bugs in the code, // 99 bugs in the code // We fix a bug, compile it again // 101 little bugs in the code ♫

      Tell your manager, while you code: "good, cheap or fast: pick two. "

      K Offline
      K Offline
      Keith Barrow
      wrote on last edited by
      #2

      What you have here is an anonymous method, being assigned to a delegate. I'm surprised that debugging isn't working, you should put a breakpoint inside the delegate to make sure. Stepping in should work. You can refactor quite easily:

      HibernateDelegate<IList<ProductStaticDataDBBean>> hibDel = MeaningfulMethodName;
      whateverreturntypeyouhave MeaningfulMethodName (ISession session)
      {
      ....
      //do something with session .. about 300 lines of code...
      ....
      }

      Let me know if this answers your question, I think I may have the wrong end of the stick :~

      Sort of a cross between Lawrence of Arabia and Dilbert.[^]
      -Or-
      A Dead ringer for Kate Winslett[^]

      R 1 Reply Last reply
      0
      • K Keith Barrow

        What you have here is an anonymous method, being assigned to a delegate. I'm surprised that debugging isn't working, you should put a breakpoint inside the delegate to make sure. Stepping in should work. You can refactor quite easily:

        HibernateDelegate<IList<ProductStaticDataDBBean>> hibDel = MeaningfulMethodName;
        whateverreturntypeyouhave MeaningfulMethodName (ISession session)
        {
        ....
        //do something with session .. about 300 lines of code...
        ....
        }

        Let me know if this answers your question, I think I may have the wrong end of the stick :~

        Sort of a cross between Lawrence of Arabia and Dilbert.[^]
        -Or-
        A Dead ringer for Kate Winslett[^]

        R Offline
        R Offline
        Ravi Sant
        wrote on last edited by
        #3

        I was not able to put a breakpoint inside anonymous code. Refactoring the delegate to call few methods(and put anonymous code there) solved the problem and debugging.

        // ♫ 99 little bugs in the code, // 99 bugs in the code // We fix a bug, compile it again // 101 little bugs in the code ♫

        Tell your manager, while you code: "good, cheap or fast: pick two. "

        K 1 Reply Last reply
        0
        • R Ravi Sant

          Hi, I have a code to debug, which in delegate block as below. Since even the F11 steps through it, i think of extracting method out of delegate. I googled much about this with no ready-help.

          private List GetPaginatedProduct(bool IsCalled, IProductPageSortOption paginationOption, IEnumerable additionalCriteria,string reportStartDate, string reportEndDate)
          {

          HibernateDelegate> hibDel = delegate(ISession session)
          {
          ....
          //do something with session .. about 300 lines of code...
          ....
          }

          }

          My question is: Can I call it like: say delegate(ISession session){ call some function(..) }. So that I effectively replace inline code with a function call. Please guide. Thanks. Edit: I was not able to break into anonymous code. Refactoring the delegates to call few methods, containing anonymous code above, made task easier.

          // ♫ 99 little bugs in the code, // 99 bugs in the code // We fix a bug, compile it again // 101 little bugs in the code ♫

          Tell your manager, while you code: "good, cheap or fast: pick two. "

          B Offline
          B Offline
          BobJanova
          wrote on last edited by
          #4

          If you put a stop point inside the delegate, it should get debugged as normal ... but when the delegate is called, not when it's defined (i.e. debugging the outer method will step over it because the content is not being executed at that time).

          1 Reply Last reply
          0
          • R Ravi Sant

            I was not able to put a breakpoint inside anonymous code. Refactoring the delegate to call few methods(and put anonymous code there) solved the problem and debugging.

            // ♫ 99 little bugs in the code, // 99 bugs in the code // We fix a bug, compile it again // 101 little bugs in the code ♫

            Tell your manager, while you code: "good, cheap or fast: pick two. "

            K Offline
            K Offline
            Keith Barrow
            wrote on last edited by
            #5

            Ravi Sant wrote:

            I was not able to put a breakpoint inside anonymous code.

            Curious: I tried it and it worked (VS2010 Ultimate), I don't remember there being a problem in VS 2008 but that doesn't mean there wasn't. Sounds like something is Foo'd with VS.

            Sort of a cross between Lawrence of Arabia and Dilbert.[^]
            -Or-
            A Dead ringer for Kate Winslett[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups