Small sample of using Code Contracts

I had read about Code Contracts long time ago, but I didn’t see a reason to use contract instead of simple tests and argument’s check with Exception’s throws. Only now I’m trying to use them at real project. I didn’t see why I need to write:

Contract.Requires<ArgumentNullException>(argument == null); 

Instead of like I did it before:

if (argument == null) 

    throw new ArgumentNullException(“argument”)

Couple of weeks ago I had reinstall my Windows 7 on my laptop (I bought SSD for my laptop). After I install ReSharper with Visual Studio 2010 after run I accidental choosed “Go to the metadata” instead of like usual “Go to Object Explorer” by Ctrl and Mouse Click. So when I clicked on some class of (basic classes of .NET) I looked at source code of these classes and found that they are using Code Contracts. I thought this is why I need to understand why I need to use contracts in my code, so I started to use them in some small applications and tried to find some interesting case. Read more…

Config Transformation Tool: Parameters support

Couple of weeks ago I wrote about my small utility Config Transformation Tool, which I wrote with base of web.config transformation task. In those moments I was thinking about opportunity to pass parameters to transform file, to tool can replaces parameters in transformation file with special values. Yesterday I resolved this issue. From now I use class Microsoft.Web.Publishing.Tasks.XmlTransformation which works with strings and XmlDocuments instead of files. I had two tasks: (a) I need method which will replace parameters on values, (b) I need method which will be parse command line and create dictionary of parameters. Read more…

Register hotkey in system for WPF application

Couple days ago I got a question about how to register hotkey in Windows for WPF application. I remembered that one year ago I was solving the same problem in WinForms application, I was registering hot keys for my application, it was Vista Keys Extender project. I knew that my project worked, so I suggested author of question to use code of my project to solve his problem. But as we learned later in WPF message handle mechanism different from WinForms. So I started to find solution for WPF application. I copied my old code from my old project and started to rewrite it step-by-step. Read more…

Wrox–Professional WCF 4–Windows Communication Foundation with .NET 4

0470563141Couple of weeks ago I got a paper copy of book Pablo Cibraro, Kurt Claeys, Fabio Cozzolino, Johann Grabner – Professional WCF 4: Windows Communication Foundation with .NET 4. This book has not a lot of pages, just about 400. Really, I don’t remember when I saw so thin book about some technology. But maybe this book has not a lot pages, but a lot of interesting themes.

First chapter is patterns and principles of SOA applications. This is the best chapter in this book. When I was reading this chapter I saw that authors have a lot experience of creating applications with Service-oriented architecture. Authors described all possible architecture principles, with which you can create SOA applications. And they did not limit themselves to the principles that are possible with WCF. I think that this chapter is “must read” for all developers, it is doesn’t matter what technologies you are using: php, java or .net. And this is good luck that Wrox published this chapter online: Design Principles and Patterns. It is about 30 pages, so read it right now.

Read more…