Blogg: Utvikling på .NET-plattform

Iterate through Enumeration C#

Need to iterate through an Enumeration in C#?

First create the array using following code:

Array lstProvider = System.Enum.GetValues( typeof(CommonShared.EnumProvider));
Then you can directly call the following foreach loop:
foreach (CommonShared.EnumProvider enProvider in lstProvider) { // do something... }

  • Av Steinar Aasheim

Time and date in XML

Today, one of my collegues was struggling with a datetime string recieved from a XML-feed. The string was on the format: "2009-08-05T19:00:00+01:00". And is called "Complete date plus hours, minutes and seconds" in the spesification on W3C.

When he tried DateTime.Parse(), the timesone was added to the time, resulting in a string like this: "05.08.2009 20:00:00".

When he tried DateTime.ParseExact(), he could not find a CultureInfo-string that matched the date format.

After some searching he found that the XML namespace also had some date functions. The result was to use the ToDateTimeOffset function in the XML namespace, like this:

System.Xml.XmlConvert.ToDateTimeOffset ("2009-08-05T19:00:00+01:00").ToString("yyyy-MM-dd hh:mm s")

After even more research he came up with the final soultion:

DateTimeOffset.Parse("2003-10-29T17:44:00+01:00")

  • Av Steinar Aasheim

Test: Spectral Core Documenter

The last couple of days I have spent some time on a product called Documenter from Spectral Core. With this application you can get a full documentation of your MS SQL databases - fully automated! The application is really fast, and can generate HTML or a Windows Helpfile. The HTML-code can even be uploaded via FTP to a web server.

Documenter generates documentation of database info, assemblies, user data types, roles, schemas, views, triggers, synonyms, tables, columns, indexes, foreign keys, contraints, rules, procedures and functions! The latest version even supports encrypted procedures.

Documenter Interface

When I tested the application I ran into a small problem and contacted the support team. Just a few hours later the problem was fixed and I could download a new version from their web site. Impressing!

The product is worth every dollar! If you need to document a database, I would recommend this product!

Read more about all the features here.

  • Av Steinar Aasheim

Safe XML

Recently I came accross a very cool namespace when I was searching for a safe way to handle XML-output.

System.Security.SecurityElement.Escape(your string);
The System.Security namespace also have a lot of other nice functions - take a look, and I bet you will find some nice functions you have handcoded yourselv before.