lamp

May 2009 - Posts

Automatic Properties, when you *think* you don’t need them
31 May 09 12:30 AM | Frederick.Chapleau | with no comments

I always create property assessors for objects. But why? Maybe just in case I need them later.

Now, with VS 2008 there is a new feature, automatic properties.

Check them out, it will save you time.

-f.

ref: http://weblogs.asp.net/scottgu/archive/2007/03/08/new-c-orcas-language-features-automatic-properties-object-initializers-and-collection-initializers.aspx

Filed under:
Dojo Javascript Framework
30 May 09 11:05 PM | Frederick.Chapleau | with no comments

After writing the same code over and over, I looked around to see I there was some libraries.

Wikipedia (as usual) as a pretty complete list. And I found that Dojo was one of the most complete.

-f.

ref:

http://dojotoolkit.org/

http://en.wikipedia.org/wiki/Dojo_Toolkit

Javascript Serializer
29 May 09 05:51 PM | Frederick.Chapleau | with no comments

Do you need to generate JSON object from C# ?

Check out the JavaScriptSerializer.

-f.

ref:

http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx

http://www.chapleau.info/cs/blogs/fchapleau/archive/2009/05/30/json-extension-methods.aspx

Filed under:
Give random seed to random
28 May 09 10:40 AM | Frederick.Chapleau | with no comments

hum... no, it’s not possible, but there is another way to do it.

Random r = new Random(Convert.ToInt32(DateTime.Now.Ticks-DateTime.Now.Ticks));

Catch it? Yes it will fail only if your computer is too slow to have more than an int32 of tick between two operation. (2,147,483,647 for an int32 /10000 ticks in a milliseconds, so it will fail if the time between a substraction is 214 seconds)

-f.

Filed under:
Styling with style!
27 May 09 05:58 PM | Frederick.Chapleau | with no comments

CSS is a good way to handle style and positioning of a webpage. Do you know that you can repeat the style ids and split the styling (like, colors) and the positioning (like left and top)?

The best way that I've found, two CSS, one with the positioning, and another with the styles, so if you want to dynamically change the color, you only have to change a CSS file.

-f.

Filed under:
Remove the code behind when not using it
26 May 09 06:08 AM | Frederick.Chapleau | with no comments

When creating a ASP.Net web application, a code-behind page with the same name as the asp.net page is created, but you can avoid it.

The only directive required to be recognized as a ASP.NET page, is <%@ Page %>

-f.

Call the dispose method if it exists
25 May 09 05:39 PM | Frederick.Chapleau | with no comments

If a dispose method exist, it is a good practice to call it when the immediate performance is not an issue, and when you want to optimize long term performance.

The call of the dispose method will be done by the Garbage Collector even if you are not calling it, but the resources will only be this disposed at this time.

-f.

Filed under:
Use the parse method or a direct cast?
24 May 09 08:43 PM | Frederick.Chapleau | with no comments

Using the parse method of an object is always better than using a direct cast, when you do not know what is the type of the given object... and take a look at the “as” keyword, it can be helpful too.

-f.

Filed under:
Expose Protected properties
23 May 09 07:45 AM | Frederick.Chapleau | with no comments

When designing ASP.Net webpage, all protectected properties can be accessed with <%=propertyname%>

So, you can split UI from Business logic by wrapping code inside them.

-f.

What is an event?
22 May 09 07:17 AM | Frederick.Chapleau | with no comments

Do you really know?

It is a MulticastDelegate that only allow to add and remove handlers, so, it’s like calling many methods, at one time...

-f.

ref:

http://blogs.msdn.com/ddietric/archive/2007/10/01/fun-with-events-and-delegates.aspx

http://www.codeproject.com/KB/cs/howeventswork.aspx

Filed under:
Locking mechanism: Monitor
21 May 09 10:36 PM | Frederick.Chapleau | with no comments

Comparing to way of locking.. lock(object){ } and Monitor.Enter() and Monitor.Exit().

It is the same! But the better way to do it, is to use the lock statement, because you can always forget to Monitor.Exit() or an error can throw an exception before it is called.

-f.

ref:

The lock keyword calls Enter(Object) at the start of the block and Exit(Object) at the end of the block.

http://msdn.microsoft.com/en-us/library/c5kehkcz.aspx

Filed under:
Commenting with ///
20 May 09 10:32 AM | Frederick.Chapleau | with no comments

(Almost) everybody knows that typing /// in front of a method generates XML comments. But it does not apply only to method, but to classes, namespaces, and property accessors.

... and there are 11 more tags! <c>, <code>, <list>, <listheader>, <item>, <term>, <description>, <para>, <paramref>, <see>, and <value>

-f.

ref:

http://msdn.microsoft.com/en-us/magazine/cc302121.aspx

Filed under:
Isolate Code by Namespace inclusion
19 May 09 08:57 PM | Frederick.Chapleau | with no comments

When it’s time to isolate code into component, a good way to do it easily is to remove namespaces from classes and references from assembly…

Removing Windows.Form remove the entire Windows Form layer from the class, and separate the component. Removing the System.Web assemblies split your presentation layer from the Application Layer...

-f.

Filed under:
URIParser when you want to validate them
18 May 09 08:48 PM | Frederick.Chapleau | with no comments

There a lot to URIParser than the HTTP and File scheme, LDAP, TCP, Gopher and many other, check them out

-f.

ref.:

http://msdn.microsoft.com/en-us/library/system.uriparser.aspx

Filed under:
System Uptime
17 May 09 10:30 PM | Frederick.Chapleau | with no comments

Get the system up by getting the System.Environment.TickCount .

-f.

Filed under:
More Posts Next page »