In .NET 2.0 you will notice that every data has among others an extra method called TryParse. TryParse and Parse are semantically the same but differ in the way they handle errors. Parse method will throw an exception if it cannot convert the string, whereas the TryParse method returns a boolean to denote whether the conversion has been successfull or not, and returns the converted value through an out parameter.
The reason why the TryMethod is introduced, is because exceptions are expensive. On http://www.codinghorror.com/blog/archives/000358.html you find a benchmark tool and you notice that the (default) Parse method is a lot slower.
One tip: For extensive use of string concatenation you use the StringBuilder class, for converting data types you apply the TryParse method.
In .NET 1.1 you cannot assign the NULL value to a value type (e.g. int, float, etc.). There are some situations where this is needed, typically in database scenarios. In .NET 2.0 there is a new type called nullable. The nullable type implements the INullableValue interface and looks like:
The idea is that a nullable type combines a value (Value) of the underlying type with a boolean (HasValue) null indicator. The underlying type of a nullable type must be a value type.
In .NET 2.0 there is a new operator, called the null coalescing operator, ??. For example the statement x ?? y is x if x is not null, otherwise the result is y. Note that this operator also works with reference types.
RemotingHelper is a little helper class by Ingo Rammer that enables you to use interfaces to access remote objects instead of the implementation. In .NET 2.0 there are a lot of new features, and one of them are generics. Especially with the RemotingHelper we deal with types and with the GetObject method we can use generics to parameterize the method by type.
No need to cast and no typeof operator! Below you find a version of the RemotingHelper using generics
usingSystem;usingSystem.Collections.Generic;usingSystem.Runtime.Remoting;publicclassRemotingHelper{privatestaticboolisInit;privatestaticIDictionary<Type,WellKnownClientTypeEntry>wellKnownTypes;publicstaticTGetObject<T>(){if(!isInit)InitTypeCache();WellKnownClientTypeEntryentry=wellKnownTypes\[typeof(T)\];if(entry==null){thrownewRemotingException("Type not found!");}return(T)Activator.GetObject(entry.ObjectType,entry.ObjectUrl);}publicstaticvoidInitTypeCache(){isInit=true;wellKnownTypes=newDictionary<Type,WellKnownClientTypeEntry>();foreach(WellKnownClientTypeEntryentryinRemotingConfiguration.GetRegisteredWellKnownClientTypes()){if(entry.ObjectType==null){thrownewRemotingException("A configured type could not be found. Please check spelling");}wellKnownTypes.Add(entry.ObjectType,entry);}}}
I updated my blog site to version 1.8 of DasBlog and created a new theme called Business. I will release soon a version of the theme so that you can use it for your own blog site.
If you are targeting Windows XP SP2 or Windows 2003 and your .NET application relies on COM components, then it is not needed anymore to register your COM components. This can be done by using manifest files. Registration-Free Activation of .NET-Based Components: A Walkthrough is an excellent article about this topic.
The session 'Turn Left or Right? How to Best Design Your Web Services Interface' at TechEd was very interesting and pointed issues like versioning, contracts, interfaces, etc.
One way of setting up CC.NET and VSS is that CC.NET is responsible for getting the latest version (setting the attribute autoGetSource to true of the sourcecontrol node in the ccnet.config file) or NAnt by using the vssget task of NAntContrib for compiling the sources by NAnt. I always use the csc task instead of the solution task, therefore it is necessary to have a clean version of VSS, because VSS does not automatically delete files locally that have been deleted in the VSS database.
An alternative and better way is to set a shadow folder in VSS. A shadow folder contains a copy of the most recently checked-in version of each file in the project. This is exactly what we need for compiling the sources.
That way is CC.NET only using VSS for monitoring changes in the VSS database and/or labeling.