Tuesday, May 26, 2009

VS2010: Regular Expression Editor

A couple days ago the beta version of VS2010 is released.

I have not yet installed it on my PC, but I have read about the Regular Expression Editor and I found a Code plex: Editor Samples so maybe you can use this in the near future.

How to start with Unit Testing?

I do not know how to start with Unit Testing. And I still don't...

So there are several blog items about Unit Testing, see
Unit Testing ASP.NET ASP.NET unit testing has never been this easy - Stefan Sedich's Blog. But what is the best way to start.

Can someone give me a good suggestion?

Update 16 july 2009: I have found a nice list with suggestions on Bugfree.

Browser backbutton in ASP.NET

The backbutton from the browser does not work often in the way you want in ASP.NET applications. Below some links with information and tweaks relating the back button:

A back button for asp.net pages - Peter's Gekko - CodeBetter.Com - Stuff you need to Code Better!

ASP.NET Browser Back Button - Overclockers Australia Forums

Avoid Back button after logout. - ASP.net - Dotnet Fusion

back button of browser compitible with asp.net application - bytes

dotnetslackers Back Button in ASP.NET

Monday, May 25, 2009

Resource editors

On the blog entry there are two tools for editing the default resx files for the resources.

The Zeta Resource Editor is a Windows Tool and a Web Tool

Also a useful add-in is the automatically add to resource

Thursday, May 7, 2009

LINQ: Any() or Count()

Update 1 july: Also information about the ToDictionary method

When you have a collection and you want to check if there are items in the collection you can do this

Codefragment 1:

if (lCollection.Count() > 0) {
// do something
}


Codefragment 2:

if (lCollection.Any()) {
// do something
}


When the collection is also an ICollection the Count property is returned otherwise the collection is enumerated an counted for each element. The last one is an expensive operation.

The Any() method begins to iterate over the collection and stops when the condition is true. If you use the variant without the condition, the method iterates over the first element and stops. So code fragment 2 is a better solution qua performance.

LINQ and Deferred Execution

I was programming with LINQ and again I was forgotten the Deferred Execution of LINQ. I know the LINQ statement will executed when the program is running, but sometimes it is confusing, so I have read Charlie Calvert's Community Blog : LINQ and Deferred Execution
article and hopefully I will reminder it this time.

Wednesday, May 6, 2009

Difference between Convert.ToBase64String and HttpServerUtility.UrlTokenEncode?

There are two methods for converting a string to a Base64 value:

But what is the exact differnce between them? And when do you decide the use the Convert or the Encode?

When you are going to transmit a value via a URL the method to use is the: HttpServerUtility.UrlTokenEncode() method,

This method creates a url safe value.

The original base64 string encoding follows a standard definition which uses the following characters:

From:

http://www.ietf.org/rfc/rfc1421.txt

 Value Encoding  Value Encoding  Value Encoding  Value Encoding
0 A 17 R 34 i 51 z
1 B 18 S 35 j 52 0
2 C 19 T 36 k 53 1
3 D 20 U 37 l 54 2
4 E 21 V 38 m 55 3
5 F 22 W 39 n 56 4
6 G 23 X 40 o 57 5
7 H 24 Y 41 p 58 6
8 I 25 Z 42 q 59 7
9 J 26 a 43 r 60 8
10 K 27 b 44 s 61 9
11 L 28 c 45 t 62 +
12 M 29 d 46 u 63 /
13 N 30 e 47 v
14 O 31 f 48 w (pad) =
15 P 32 g 49 x
16 Q 33 h 50 y

Printable Encoding Characters
Table 1

As you can see there are a few characters in this set that are already used in normal urls. To create url save string the +, / and = characters are substituted for other tokens to create a value which is usable in a URL.


The System.Convert.ToBase64 does not display this behavior which might result in a value which isn't usable in a URL, So when you Encode a value to base64 data which you are going to use in a url use HttpSeverUtility.UrlTokenEncode to create safe values

Friday, May 1, 2009

Clipboard Ring

In Visual Studio you can use the Clipboard Ring. When you have copied multiple times something with CTRL+C, this is stored on the Clipboard Ring.

With CTRL+SHIFT+V can you browse through the Clipboard Ring.

Events in (Web)UserControls

On Mats Lycken - Posts about .NET related stuff I have read the following post about Events in (Web)UserControls.
I am a big fan of using (Web)UserControls, but often I forgot to use events... so may be I go use them more now;)

Webpage in the center of the screen

On Mikesdotnetting - Articles on ASP.NET and Web Development I have read some usefull HTML which I often forgot.

Html Snippet for creating a webpage in the center of the screen without tables.

Maybe there a better suggestions?

DateFormatting overview

(again)On Mikesdotnetting - Articles on ASP.NET and Web Development I have read a usefull post about DateFormatting.

Design Pattern: Lazy Loading

The design pattern Lazy Loading do I use without knowing this was called so.

The term Lazy Initialisation was known and that is a part of Lazy Loading. So in a property check if the field is not null and only when the field is null do your job.