Scope Nightmare

September 9th, 2009 2 comments

Today at the workplace I came across a very weird chunk of code. An enormous block of code was wrapped in 25-30 levels of brackets. On a a standard resolution screen (1280×1024) the code was completely out of screen. After spending some time on refactoring it and eliminating annoying scopes I decided to take a screenshot and post it here.

Below I will describe reasons that can lead to such kind of issues and possible solutions.
Read more…


May 11th, 2009 No comments

Today I was issued a license to NDepend software by Patrick Smacchia. NDepend is a tool that simplifies managing a complex .NET code base. Architects and developers can analyze code structure, specify design rules, plan massive refactoring, do effective code reviews and master evolution by comparing different versions of the code. 

Currentty, trying to get the most of it and it seems to be a perfect solution for managing your solution design and code base. The first thing I liked there is the graphical representation of project dependencies. Another good things include code quality metrics and code design rules. Still doing some research on it.

C# Object To Interface Caster Utility

April 23rd, 2009 9 comments


Here I describe a unique way of casting any object to an interface that it actually exposes, even though it does not formally implement the particular interface. In order to get the idea what I’m trying to propose here, consider examples below.

Lets say you’re utilizing 3rd party libraries(LibA and LibB) that are dealing with persons. These libraries have PersonLibA and PersonLibB classes defined and are exposing instances of these persons. Most likely they would expose similar public interface and would have properties like Name, EMail, Address, DateOfBirth, etc.  I’m almost sure that you would like to access these persons uniformly. If you had the source code of these components, you could define a common interface and implement PersonLibA and PersonLibB classes from your newly defined interface. However, if the source code is not available that would not work out. The only thing left to do is to define wrapper classes for each of person classes and implement the common interface.
Read more…

WPF Animatable Button

April 10th, 2009 2 comments


This article is about simplifying the process of defining animation for button mouse over, pressed, enabled and disabled animations. The process of defining triggers is quite complicated when you include all IsMouseOver, IsPressed and IsEnabled states. You will also need to work hard and define BeginStoryboard/StopStoryboard precisely to make your desired animation start. Some of these states are overlapping. For instance when the button is in IsPressed state, most likely it will be also in IsMouseOver state and what leads to improper animation to act. It is also quite annoying to define all these complex triggers every time for such a common problem.
Read more…

C# Object Cloning Machinery

March 16th, 2009 3 comments


In most cases, no matter what area of software development you are involved in, you will need a functionality of cloning your objects. The .NET Framework provides you 3 ways of achieving your object copying goal:

  1. Implement the ICloneable interface, and develop cloning functionality manually for each class involved in your desired cloning.
  2. Serialize you object to binary stream and deserialize it utilizing BinaryFormatter and MemoryStream classes. In this case your classes will need to be Serializable.
  3. Clone using Reflections.

Read more…

WPF Maskable TextBox for Numeric Values

March 10th, 2009 39 comments


This article describes how to enhance WPF TextBox and make it accept numeric(integer and floating point) values. The second goal is make the TextBox smart enough to have it easier to input numerics. The easy means to provide the TextBox with some kind of intelligence not just rejecting non-numeric symbols. Provided extension also allows setting minimum and/or maximum values.
Read more…

C# Coding Standard, Naming Conventions and Practices

March 1st, 2009 5 comments

Here I describe coding style and conventions you would encounter when going over my source codes. Most of them are easy to follow and understand. Read more…