Automatic properties with custom logic – part 2

October 29, 2008

5

Let’s say we have a class called ShoppingCartItem. We’re going to concern ourselves with two properties here namely TaxID and Taxable. The business logic dictates that an item is definitely non-taxable if it has a tax-id of zero, otherwise it may or may not be taxable which is decided by some code situated outside the… [Read more…]

Posted in: .NET, Tech/Hacks

Automatic properties with custom logic

October 24, 2008

2

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…]

Posted in: General, Tech/Hacks

“Add Service Reference” option not appearing in Visual Studio 2008

July 22, 2008

22

Had to do a bit of head-scratching on this one. New projects created in Visual Studio 2008 did show the “Add Service Reference” when right-clicking on a project in Solution Explorer while some existing ones didn’t. Using “Add Web Reference” instead of “Add Service Reference” has its own set of issues in that WCF services… [Read more…]

Tagged: ,
Posted in: .NET, Tech/Hacks

A simple RTF report generator

June 10, 2008

3

I was describing how a simple yet extensible report-generator could be implemented quickly to somebody. I’m posting it here as some of you might find it useful (and I can refer to this link in future conversations ). The concept: …is really simple. The idea is to look for a placeholder like @Fruit and replace… [Read more…]

Posted in: .NET, Tech/Hacks

ArrayList item comparison

June 6, 2008

2

What’ll be the output of the following piece of code (asked here)? One might expect… True True But what you’d actually get is… False False …because of boxing. a.Add(1) boxes the integer 1 into an object and stores it in a, while b.Add(1) boxes the integer 1 into a separate object and stores it in… [Read more…]

Posted in: .NET, Tech/Hacks

What you should do…

May 1, 2008

0

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…]

Posted in: General, Tech/Hacks

Two (useless but potentially) interesting tid-bits

April 29, 2008

0

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…]

Tagged: , ,
Posted in: .NET, General, Tech/Hacks

C# compiler optimizations and empty “try” block

April 28, 2008

2

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…]

Posted in: General, Tech/Hacks

Make a file empty

April 26, 2008

0

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.

Posted in: General

Which one is faster – FileStream.Position or FileStream.Seek?

April 26, 2008

0

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.

Posted in: General
Follow

Get every new post delivered to your Inbox.