Using the configuration Builder in ASP.NET 5

The Problem

Managing the configuration data have always been troublsome. Although Microsoft did provided and also updated/upgraded a lot of options from time to time, yet it remains  a challenge most of time. Things get more critical when the configuration data we are concerned is the confidential data like connection string, smtp passwords, API keys etc becase at some point of time, they do get checked in source code or shared across other developers. In one of my prev project faced a similar issue when private key and the Code Signing certificate was accidentally checked in by a developer. The customer had to revoke the certificate which invalidated all the production builds which were deployed to end users as well. Continue reading “Using the configuration Builder in ASP.NET 5”

How to count items in an IEnumerable without iterating?

IEnumerable doesn’t support this. This is by design. IEnumerable uses lazy evaluation to get the elements you ask for just before you need them.

If you want to know the number of items without iterating over them you can use ICollection<T>, it has a Count property.

ICollection<T> c = source as ICollection<TSource>;
if (c != null)
    return c.Count;

int result = 0;
using (IEnumerator<T> enumerator = source.GetEnumerator())
    while (enumerator.MoveNext())
return result;

I am a junior developer. How do I handle disagreement in a code review regarding an unlikely edge case?

I am working at a robotics startup on a path coverage team and after submitting a pull request, my code gets reviewed.

My teammate, who has been on the team for more than a year, has made some comments to my code that suggest I do a lot more work than I believe to be necessary. No, I am not a lazy developer. I love elegant code that has good comments, variable names, indentation and handles cases properly. However, he has a different type of organization in mind that I don’t agree with.

What do I do? 

Continue reading “I am a junior developer. How do I handle disagreement in a code review regarding an unlikely edge case?”

Method to Copy Data Between Objects of Different Types

This article describes a method to automatically copy data from an object to another object with similar structures. This is similar to a deep_copy(source, destination) but with the possibility of returning a type that is different from the source.

I needed a way to apply/convert values from one object to another so I created a method to automatically drill down the source object graph and copy the properties from one object to another. There are many ways to do this, but I designed a method that is generic enough and also leaves place for customization/fine tuning/hacking. Continue reading “Method to Copy Data Between Objects of Different Types”

A template containing a class feature must end with a class feature

If you have had a play with the awesome Code generation tool that you can build yourself:

Walkthrough: Generating Code by using Text Templates

Then you might have had a small issue with the above error:

A template containing a class feature must end with a class feature

The error is caused by an invisible space after the last #>

It is also important to bear in mind, that invisible spaces may cause other hard-to-understand compile-errors.

If you want to see a bigger picture, just look at following links:

Now that you are aware how harmfull invisible spaces can be when dealing with Text Templates, my advice is: Make them visible. If you don’t know how to do it, see Jeef Widmer’s blog


When programming against any LDAP backend, it’s good to sanitize any user input that may go into a search filter. A typical case is authentication (login or single sing-on) applications, where an input username or email must be used to resolve a user’s distinct name (DN) in the LDAP directory. Continue reading “ESCAPING SPECIAL CHARS IN LDAP SEARCH FILTERS”