|
How to block USB ports in c# application?
|
|
|
|
|
|
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<IProduct> GetPaginatedProduct(bool IsCalled, IProductPageSortOption paginationOption, IEnumerable<ICustomCriteria> additionalCriteria,string reportStartDate, string reportEndDate)
{
HibernateDelegate<IList<ProductStaticDataDBBean>> hibDel = delegate(ISession session)
{
....
....
}
}
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. "
modified 22-May-12 6:00am.
|
|
|
|
|
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)
{
....
....
}
Let me know if this answers your question, I think I may have the wrong end of the stick
|
|
|
|
|
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.
|
|
|
|
|
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).
|
|
|
|
|
We are developing VMS.We found some difficulty in generating Barcode using Crystal report, We request you to send us the Barcode generator for Crystal report
|
|
|
|
|
Member 3601034 wrote: We request you to send us the Barcode generator for Crystal report
Sorry, but this site does not provide code to order.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
So a guy on my team accidentally left out a "return" statement in the following code:
public override OM.ModelObjectMessageSource CreateMessageSource(OM.ModelSolutionBase solution, OM.ModelObject item, OM.ModelObject referencedItem)
{
…..
TtTransitionPointer oTransitionPointer = item as TtTransitionPointer;
if (oTransitionPointer != null) new TransitionPointerMessageSource(oTransitionPointer);
…..
return base.CreateMessageSource(solution, item, referencedItem);
}
Easily enough found and fixed as it turned out, but we both were left puzzled that this wasn't a compiler warning. What's the use case for constructing the ephemeral object TransitionPointerMessageSource? It's not assigned to anything and isn't returned.
|
|
|
|
|
But you may be doing something in the instance that you create with the values you pass in. As this would be a perfectly reasonable thing to do, it would be churlish of the system to try and prevent it, and a warning could well be classed overkill as well.
|
|
|
|
|
Yea, I get that. Clearly there could be side effects of constructing an object, but would that be anything like reasonable programming practice? I mean, warnings are not errors. My expectation is that they point to something you might want to look at -- for example, a standalone statement that constructs an object which is then immediately (or at the leisure of the runtime system) disposed.
|
|
|
|
|
Tom Clement wrote: would that be anything like reasonable programming practice
Of course it would. In effect here, it's really no different to calling a static method in another class. I certainly wouldn't expect to be warned about it in the same way as I'm not warned if I ignore the return value from a method.
|
|
|
|
|
Simple: the constructor may do something that affects non-transient storage.
For example, it may insert the new object into the appropriate databases. That the object is not needed again by the code that creates it is irrelevant to the system.
It doesn't need a warning, any more than ignoring the return value from any other method call does:
private int MyMethod(int i)
{
i = i * 2;
Console.WriteLine (i);
return i;
}
...
MyMethod(6);
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Which "return" did you forget? The return in "return base.CreateMessageSource(...)", or do you think of a return before "new TransitionPointerMessageSource(...)"?
In the first case, I'd expect a compiler error, in the last case no warning or error at all, as others explained already.
|
|
|
|
|
As others have said, a constructor is just a method and can reasonably do things other than simply initialise the object. Whether you consider them good practice or not, there are uses for this: for example, the constructor could register the instance in some local storage to make the object non-transient, it could transmit itself over a network connection or persist itself to file, it could modify static state or the state of the objects passed into it, as well as having other side effects.
|
|
|
|
|
Ok, I'm pretty sure I didn't learn anything from everyone's responses (I do know about side effects), except maybe that people seem to have a difference sense of what is good programming practice than I. To me, calling a constructor to achieve side effects seems obscure at best. I guess I'm just glad I don't have to try to read code written that way. But, as someone said, perhaps it would be presumptuous of the compiler to warn about that.
|
|
|
|
|
personally, i made it one time, to call a static constructor of one type that i was implementing, test reasons, code that never made it to production...
in my case the static constructor check for a file, if it doesn't exists, they create it with default values, but in that test i wasn't able to call any other method because they made changes to the file and i was looking for the default one...
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
|
|
|
|
|
Good Evening! I try to realize the search on a particular sheet Excel workbook.
I do late binding with a book as:
using Excel = Microsoft.Office.Interop.Excel;
private void button1_Click(object sender, EventArgs e)
{
excelapp = new Excel.Application();
excelapp.Workbooks.Open(@"C:\4.xls", Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
Next, I enter into textbox1, for example, the word TXTMessage, this means that the need to look at the sheet of TXT, and textbox2 - the search term in the third column (for example).
How to implement search?
Please, help me if you can.
|
|
|
|
|
I don't know, I've never used Microsoft.Office.Interop.Excel, I use ADO.net with an OleDb connection to ACE for Excel and Access, so I just use an SQL query.
What are you trying to accomplish?
|
|
|
|
|
i try just find essential record in the list
|
|
|
|
|
Then I recommend ADO.net -- do you need some pointers on that?
|
|
|
|
|
Thanks, but i have to use mechanism of the late binding.
|
|
|
|
|
Ummm... oookaaay... you can do that with ADO.net; I generally write utilities that take command-line parameters, like what database to connect to, what table to query, etc.
What are you trying to accomplish?
|
|
|
|
|
I'm trying to make the system of authentication
|
|
|
|
|