Delegate Conversion to Method? [Solved]
-
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. "
-
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. "
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[^] -
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[^]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. "
-
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. "
-
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. "
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[^]