CallerMemberName attribute

Recently I created a WebApi where the client wanted to know what the original method name was when getting a response back.

I found a cool way to do it which .NET 4.5 offers.

The [CallerMemberName] attribute can be added as an optional parameter to any method and give you access to the calling methods name.

public class SomeClass
{
    public void SomeMethod([CallerMemberName]string memberName = "")
    {
        Console.WriteLine(memberName); //output will me name of calling method
    }
}

You can access some other useful properties too such as line number and even file path

public void TraceMessage(string message,
        [System.Runtime.CompilerServices.CallerMemberName] string memberName = "",
        [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "",
        [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)
{
    System.Diagnostics.Trace.WriteLine("message: " + message);
    System.Diagnostics.Trace.WriteLine("member name: " + memberName);
    System.Diagnostics.Trace.WriteLine("source file path: " + sourceFilePath);
    System.Diagnostics.Trace.WriteLine("source line number: " + sourceLineNumber);
}

Inheritance from derived classes with AutoMapper

Simple scenario.  Base class is super simple and we have a derived class which adds some additional properties to it.

The problem is if you try to do a Mapper.CreateMap from your source to the DERIVED class, the properties of the base class are not include by default.

To achieve this:

Mapper.CreateMap<SourceClass, ExtendedClass>().IncludeBase<EventBase, EventExtended>();

 

Credit: https://github.com/AutoMapper/AutoMapper/wiki/Mapping-inheritance

Strikethru in Trello

Yes, Trello is great. Actually its flippin awesome and has pretty much changed the way I work and the tools I used to use.

Unfortunately Trello doesn’t fully support markdown, but does allow you to strikethru in certain areas which is a nice feature which seems to be very hidden.

Simply:-

~~yourdata~~

This doesn’t work on List names but does work within them, in checklists, cards and so on.