X

Abusing “as” operator

Casting to types using keyword as is one powerful features of C#. It allows exceptionless casting of reference types. If cast is not possible then null is returned. Although this is powerful language feature it opens also door to some questionable uses.

Death March

This winter I read book Death March by Edward Yourdon. Death March is about death march projects and how to survive them. There are also chapters describing decisions that you should never make when managing death march project. And there are great tips that help you avoid bad mistakes in death march projects. The book describes also developers life in such projects and gives them some good advises how to stay alive.

Refactoring: parameterize constructor

In legacy code you may find classes with constructor where some objects are created and initialized. These classes are not easily testable because they depend on other classes and therefore when you unit test these classes they may also throw exceptions of classes they depend on. In these cases we can use parameterize constructor refactoring.

Reading process output

Here is my little example about how to catch run console program and catch the output. I used similar code to read the output of OpenSLL.

Ship it! A Practical Guide to Successful Software Projects

I finished yesterday another great book: Ship it! A Practical Guide to Successful Software Projectsfrom pragmatic series. This book is not theory book that leaves you with many questions and no idea how to move along. Instead, you get an good idea about how to develop software and manage software projects successfully.

Creating DTOs using AutoMapper

There is one small and nice object to object mapper called AutoMapper. I gave it a little try and I found it very useful. Specially if you have web service and you are using DTOs to move data between client and server. Good news is that AutoMapper is able to perform these mappings and you don't have to write more code than couple of lines. Let’s see example.

Refactoring: extract interface

Extract interface is one of the most common refactoring techniques. Motivation behindextract interface refactoring method is to avoid direct dependencies between classes. Instead of using classes in method calls we use interfaces so we can also use subclasses of those classes we used before. Also we can create brand new classes that use follow these interfaces and we can use these classes instead of current ones.

ASP.NET MVC: Ignore requests to favicon.ico

One problem I faced when writing my example pet portal on ASP.NET MVC was Google Chrome’s request to favicon.ico that doesn’t exist. IE8 that I use (8.0.7000.0) doesn’t make these blind requests to discover that favicon.ico is not there. Solution to my problem was very simple.

Writing messages to ULS (Unified Logging System)

If you want to make your SharePoint solution more SharePoint way you can write your tracing, debug and error messages to SharePoint log. Easiest way to do it is to write logger by yourself. Btw, SharePoint has class called ULS to write messages to logs but this class is internal and we cannot use it. But it is there.

SharePoint: Access denied error when adding new page to page library

On one of my servers I detected very weird error. There are authenticated users who can add content to some page libraries and modify pages they have made. One day suddenly they were not able to add pages to page library anymore because of Access Denied error.