I code therefore I am.

August 24, 2009 at 9:38pm
0 notes
Comments (View)

Tags:
quotes  

Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

— Martin Fowler

2:54pm
0 notes
Comments (View)

Tags:
CSharp  

System.IO.Path.Combine Behavior

When using Path.Combine, you should be aware of the behavior that if the second parameter has a leading slash, it will ignore the first parameter.

Given the following:

string root = "c:\";
string path = "test.txt";
string lead = "\test.txt";

We get the following results:

using System.IO;

Path.Combine(root, path); // ‘c:\test.txt’
Path.combine(root, lead); // ‘\test.txt’

June 22, 2009 at 1:41pm
0 notes
Comments (View)

Tags:
Test-Driven Development  

3 A's Pattern For Writing Test Methods

Arrange, Act, Assert. Specifically, use separate code paragraphs (groups of lines of code separated by a blank line) for each of the As. Arrange is variable declaration and initialization. Act is invoking the code under test. Assert is using the Assert.* methods to verify that expectations were met. Following this pattern consistently makes it easy to revisit test code.

[source: Principles for Test-Driven Development]

June 17, 2009 at 4:46pm
0 notes
Comments (View)

Tags:
ASP.NET  

HTTP GET for ASP.NET Webservices

It’s disabled by default and to enable it, add this to the web.config

<configuration>
    <system.web>
    <webServices>
        <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
    </system.web>
</configuration>
Alternatively, you can enable these protocols in the Machine.config
<protocols>
	<add name="HttpSoap"/>
	<add name="HttpPost"/>
	<add name="HttpGet"/> 
	<add name="HttpPostLocalhost"/>
      <!-- Documentation enables the documentation/test pages -->
	<add name="Documentation"/>
</protocols>
[source: INFO: HTTP GET and HTTP POST Are Disabled by Default]

May 5, 2009 at 3:51pm
0 notes
Comments (View)

Tags:
CSharp  

Safe Casting

Use the as keyword.

MyClass castedObject = obj as MyClass;

This won’t throw a class cast exception. Instead, castedObject will return null if obj isn’t a MyClass.

1:52pm
0 notes
Comments (View)

Tags:
CSharp  

Chain ?? Operators

You can use multiple ?? operators to chain multiple null comparisons:

string text = value1 ?? value2 ?? String.Empty;

12:17pm
0 notes
Comments (View)

Tags:
CSharp  

Normalizing & Comparing Strings

When normalizing strings, it is highly recommended that you use ToUpperInvariant instead of ToLowerInvariant because Microsoft has optimized the code for performing uppercase comparisons.

[source: CLR via C# ]