There appears to be inadequate documentation on setting up expectations in NMock for methods that accept arguments by reference using “out” and “ref” keywords. Here is a quick note to give an example demonstrating how it can be done. Consider the following interface: “Bar” method takes one “out” parameter and another “ref” parameter. To start… [Read more…]
If you have been blessed with a windows-forms application that has business-logic invading the user-interface, I have something that’ll help you. The most practical approach in this situation is to rearchitect the business layer and switch the UI over in a piecemeal fashion. While you’re doing this, automated testing of the user-interface will make your… [Read more…]
There should be a compiler supported way in C# to declare a property with custom getter/setter logic without having to explicitly declare a backing field. In the absence of such a feature, if you want to have custom getter/setter logic you have to ditch automatic properties, declare a backing field explicitly and then there’s nothing stopping a… [Read more…]
I am fortunate enough to work with a couple of great individuals. Recently I was able to hypnotize persuade them into discussing things which should and shouldn’t be done in a software project I am absolutely sure that the discussion will help me in the future (and them). However I thought the merged list is… [Read more…]
Try-Catch-Finally A try-catch-finally is converted into IL by the C# compiler as a try-catch inside the try block of another try-finally. This allows for finally block to execute even when exceptions are raised in the catch block. Use ildasm and check it out yourself! throw football; Though you cannot throw an arbitrary managed object as… [Read more…]
There is some misinformation you’re likely to stumble upon via Google when searching for “C# compiler /optimize+”. Interestingly, the following snippet can be seen on various forums. The following is a response from a developer on the C# compiler team: We get rid of unused locals (i.e., locals that are never read, even if assigned).… [Read more…]
Found someone using Google to figure out how to clear out the contents of a file and hitting my blog. Well, it’s pretty easy – use FileMode.Truncate when opening the file.
FileStream.Position property is implemented in terms of File.Seek (essentially File.Seek(value, SeekOrigin.Begin)). Consequently setting the location of the virtual file-pointer by calling Seek directly instead of calling Position results in slightly faster execution speed. Seek is also better because it has more options.
This is an academic question. Which one is better? or Even though both Foo and Bar do the same thing, Foo is better performance wise. The compiler converts Foo into IL which roughly achieves the same thing as the following pseudo-code. Foo when converted to IL splits the search space with 110 in the middle… [Read more…]
In an internal meeting of a bunch of developers at my current company, someone made the assertion that the Switch statement in C# (or Select Case in VB.NET) is just a compiler short-cut for writing a chain of If-Then-Else statements. What do you think? Is that statement – true or false? Take the following C#… [Read more…]
November 17, 2008
3