Playing Chicken With Common Sense

Using Type Alias

I am surprised how many people still don't know they can alias namespaces using the C# keyword using.  Resharper automatically adds this syntax for me and it seems like 1 person a month says that didn't know. 1: using Short = Company.Project.Task.Function; The reason for this p... [More]
  • 1 Comments
  • E-mail
  • Kick it!
  • Shout it
  • Bookmark and Share

Let's say you have a generic class with a new() constraint on the type parameter. This means that you are allowed to create new objects of the generic type, like this: 1: class GenericClass<T> where T : new() 2: { 3: public void SomeMethod() 4: { 5: ... [More]
  • 0 Comments
  • E-mail
  • Kick it!
  • Shout it
  • Bookmark and Share

Generic C# Singleton goodness

  Here is a Generic Singleton factory. Enjoy! // this is the class for which I want to maintain a single instancepublic class MyClass{ private MyClass() { // private constructor ensures that callers cannot instantiate an object using new() }} // Singleton fac... [More]
  • 0 Comments
  • E-mail
  • Kick it!
  • Shout it
  • Bookmark and Share

Escape XML string in C#

This is a simple way of escaping special characters inside of strings that you might want to insert into XML.  I have used other techniques which require more coding so keep this handy! You will use the following method: SecurityElement.Escape(string text). see MSDN documentation
  • 0 Comments
  • E-mail
  • Kick it!
  • Shout it
  • Bookmark and Share

  Sometimes you need to resolve relative url's without ResolveUrl. If the code is executing outside a Control, for example in an IHttpHandler or business layer code somewhere that has no reference to a Control, you can't call Control.ResolveUrl. The System.Web.VirtualPathUtility class has som... [More]
  • 0 Comments
  • E-mail
  • Kick it!
  • Shout it
  • Bookmark and Share

Control panel

RecentComments

Comment RSS