Better C# Design Contracts in Lokad Shared Libraries

I’ve just finished updating Enforce statements from the Lokad Shared Libraries with the new syntax that is based on retrieval of parameter name from .NET lambda with IL parsing. A couple of usability and stability issues were discovered and fixed wile pushing changes to the existing code-bases leveraging Lokad Shared. And so there is the updated …

Development Compromises Around Lambda Expressions

I’ve spent some time investigating the ability to leverage C# Linq lambda expressions for retrieving name and value of .NET parameter or variable. It would have allowed to achieve two objectives: Make code shorter and reduce the duplication Prevent the code from turning inconsistent after refactorings. These two lines illustrate that clearly: Enforce.Argument(eventEditorController, “eventEditorController”); Enforce.Argument(() => …

How to Find Out Variable or Parameter Name in C#?

Sometimes it might be useful to capture the name of the variable or parameter within the code to simplify error reporting or debugging. I keep on encountering posts and comments saying that this is not possible in C#. Well, it is not so. And there are multiple ways to do that. Anonymous class approach Given …

How to Use SystemUtil to Write .NET Code With Testable Sleep and Time Calls

One of the things, that you might have seen in the code snippets around this blog, is usage of SystemUtil.Sleep and SystemUtil.Now instead of the Thread.Sleep and DateTime.Now here and then. The reason for these replacements is simple – they make unit tests much easier to write and read. And, in the case of Sleep, they also allow tests run instantly (as opposed to …