Author Archives : Darin

Sample ASP.Net MVC project (updated)

I’ve updated the sample MVC project I wrote for using ASP.NET MVC 3 and the Razor view engine. A minor change is that I no longer use the FluentValidationModelValidatorProvider but the standard one. So I decorate the view model with the necessary data annotations :

And the validator becomes :

And here are […]

How to convert XHTML to PDF in C#

In this blog post I will illustrate how you could convert an XHTML page into PDF using the flying-saucer library. This is a Java library so we need to first step would be to convert it to a .NET assembly. I will use the IKVM.NET Bytecode Compiler (ikvmc.exe) for this purpose. So go ahead and […]

LINQ to XML and reading large XML files

LINQ to XML makes it relatively easy to read and query XML files. For example consider the following XML file:

Suppose you would like to find all records with groupid > 2. You could be tempted to issue the following query:

There’s a flaw in this method. XElement.Load method will load the whole […]

Dynamic methods in .NET

Using reflection to invoke methods which are not known at compile time might be problematic in performance critical applications. It is roughly 2.5-3.0 times slower than direct method calls. Here’s a sample test I’ve conducted:

Here are the results: Method CPU units Direct method invocation 796 Reflection method invocation 1986 So using reflection to […]

Transactional NTFS (part 1/2)

Transactional NTFS and DotNet Starting from Windows Vista and Windows Server 2008, Microsoft introduced a great new feature called Transactional NTFS (TxF). It allows developers to write file I/O functions that are guaranteed to either succeed completely or fail completely. Unfortunately there are no classes in the .NET framework that would allows us to perform, […]

How we do ASP.NET MVC

Sample MVC Solution In this post I will show a sample ASP.NET MVC 2.0 project structure illustrating different concepts such as data access, user input validation and mapping between the domain and the view model. The project is still under construction but the source code is available at github. I will illustrate the usage of […]

Playing with FindFirstFile and FindNextFile

Enumerating files in .NET is easy. Everybody knows the GetFiles method and you may be tempted to write code like this :

But if you look closer you will notice that this method returns an array of strings. This could be problematic if the directory you search contains lots of files. The method will […]

Fun with matrix multiplication and unsafe code

In this post I will compare two methods that perform matrix multiplication. We start by defining the Matrix class:

Next we add the first algorithm to the Matrix class which performs a naive multiplication:

The second method uses unsafe code:

Now it’s time to measure the performance:

In this test we […]