Archive for category C#

Using TeamCity to enable NuGet package restore for solution-level packages

Problem What’s a solution-level package? A solution-level package is one that installs a tool or additional commands for the Package Manager console, but does not add references or content to any projects in your solution. For example, the psake package installs PowerShell scripts you can use to automate your build process. A package is considered […]

,

4 Comments

ExpandoObject: exposing properties to the TypeDescriptor

Consider the following unit test: I’ve highlighted the interesting parts which are: creating an ExpandoObject with two properties (Foo and Bar) using TypeDescriptor.GetProperties to fetch them There should be two properties but sadly this unit test returns: The problem is that the ExpandoObject, internally, uses a dictionary of string and object (IDictionary<string,object>) to store the […]

, , , , ,

1 Comment

Conditionally display TeamCity build progress messages

TeamCity has a number of notifications/messages that you can make use of to interact with the build script. One of them is the Build Progress Message which is shown on the project dashboard to provide sort of a UI hint to the user while the build is running, like this example: According to the TeamCity […]

, ,

Leave a comment

Changing unit-test frameworks with the help of fluent assertions

There are numerous reasons to why I keep using the little micro framework called Fluent Assertions. However recently I ran into a little situation that might not be so well documented so I thought I’d tell you about it here instead.   Problem/Background In a project I was involved in recently we had been using […]

, , ,

2 Comments

NLog: highlighting words with regex

NLog is a simple little logging framework for .NET that I’ve come to prefer as my logging component in many situations. However, I ran into a situation using it that I´d like to share with you since I didn’t find any great resources on the Internet about it (yet). note: the complete code is up […]

, ,

Leave a comment

Better arrange readability with new Moq fluent functional specifications

I love Moq which is a little micro framework for controlling the behavior of dependencies, or at least that is how usually use it…sort of. (some might call it a mocking framework…well, anyway) One of the disadvantages of Moq however is that the syntax can be a bit complicated and the arrange part of the […]

, ,

Leave a comment

Automapper: Issue with mapping Xml to types that share a common parent

Let’s say you have a simple object graph consisting of a common base class called bicycle which has a property called Id. Two specialized bicycle classes exist; tandem bike and mountain bike Now, given the xml below: We want to use automapper to convert from the xml to actual C# classes.   Let’ s start […]

,

Leave a comment

The sometimes overlooked Enumerable.Range

I’ll start with confessing that the first time I saw LINQ and especially Enumerable.Range I didn’t see what I would use it for. Well, luckily times change… An example The other day when I was writing some code for a mockup and I hade to generate some fake data. More than often, that sort of […]

,

Leave a comment

Tip of the day: How can we discover extension methods more easily

Extension methods is a powerful feature that should be used when it´s really an extension on a type (like a string) that you would use over and over again. In contrast, a utility method is something you need once and performs something that is very specific to the problem you´re trying to solve, thus not […]

,

1 Comment

Unity 2.0 and Automatic Type Lookup

I just recently started to use the new unity 2.0 release and I thought I´d share an example of using the new automatic type lookup feature that was introduced with this release. A simple example Let´s say I´ve got the following solution structure in Visual Studio: Unity.Model– has the contract/interface ICustomerServices Unity.Infrastructure – has the […]

, , , ,

Leave a comment