Skip to content

Instantly share code, notes, and snippets.

View martijnburgers's full-sized avatar

Martijn Burgers martijnburgers

View GitHub Profile
@martijnburgers
martijnburgers / SQL_CLR_Functions-NETCLR20.sql
Created April 13, 2015 20:03
SQL CLR Functions for converting bytes to UTF-7, UTF-8, UTF32 and Unicode. Build for SQL Server 2005, 2008, and 2008 R2.
GO
PRINT N'Creating [SQL_CLR_Functions]...for SQL Server 2005, 2008, and 2008 R2';
GO
CREATE ASSEMBLY [SQL_CLR_Functions]
AUTHORIZATION [dbo]
FROM 0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C010300DE1E2C550000000000000000E00002210B010B000008000000060000000000002E270000002000000040000000000010002000000002000004000000000000000400000000000000008000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000D42600005700000000400000C802000000000000000000000000000000000000006000000C0000009C2500001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E7465787400000034070000002000000008000000020000000000000000000000000000200000602E72737263000000C80200000040000000
@martijnburgers
martijnburgers / descriptor.cs
Last active August 29, 2015 14:07
Descriptor implementation
We couldn’t find that file to show.
# Works for me. You may need to tweak it. Stick it in your powershell profile FTW
function Rename-Project
{
# designed to run from the solution directory where the project is a child directory
param(
[string]$projectName=$(throw "projectName required."),
[string]$newProjectName=$(throw "newProjectName required.")
)
@martijnburgers
martijnburgers / AutoMapper.Playground.cs
Created January 24, 2014 11:00
AutoMapper Playground
using AutoMapper;
using Newtonsoft.Json;
namespace AutoMapper.PlayGround
{
class Program
{
static void Main(string[] args)
{
SetupAutoMapper();
@martijnburgers
martijnburgers / DefaultAutoMapperBootstrapper.cs
Last active December 31, 2015 22:29
Our AutoMapper bootstrapper. For web applications you can call the Run method inside you application start or use something like WebActivator.
/// <summary>
/// Bootstraps AutoMapper.
/// </summary>
public static class DefaultAutoMapperBootstrapper
{
private static readonly object Lock = new object();
private static bool _initialized;
/// <summary>
/// Run the bootstrapper for AutoMapper
@martijnburgers
martijnburgers / AutomapperRegistry221.cs
Last active December 31, 2015 22:28
Our AutoMapper registry for AutoMapper 2.2.1
/// <summary>
/// Registry class responsible for registering automapper types in the IoC container.
/// </summary>
public class AutomapperRegistry : Registry
{
public AutomapperRegistry()
{
For<ConfigurationStore>().Singleton().Use<ConfigurationStore>().Ctor<IEnumerable<IObjectMapper>>().Is(MapperRegistry.AllMappers());
For<IConfigurationProvider>().Use(ctx => ctx.GetInstance<ConfigurationStore>());
For<IConfiguration>().Use(ctx => ctx.GetInstance<ConfigurationStore>());
@martijnburgers
martijnburgers / AutomapperRegistry30.cs
Last active December 31, 2015 22:28
Our AutoMapper registry for AutoMapper 3.0.0
/// <summary>
/// Registry class responsible for registering automapper types in the IoC container.
/// </summary>
public class AutomapperRegistry : Registry
{
public AutomapperRegistry()
{
For<ConfigurationStore>().Singleton().Use<ConfigurationStore>().Ctor<IEnumerable<IObjectMapper>>().Is(PlatformAdapter.Resolve<IMapperRegistry>().GetMappers());
For<IConfigurationProvider>().Use(ctx => ctx.GetInstance<ConfigurationStore>());
For<IConfiguration>().Use(ctx => ctx.GetInstance<ConfigurationStore>());
@martijnburgers
martijnburgers / AutoMapperProfileConvention
Last active December 31, 2015 22:28
Our AutoMapperProfileConvention. Finds AutoMapper Profiles and checks if they have accessible contstructors. We have been searching for hours why a certain profile was not registered in the AutoMapper configuration until we saw that for some reason it had a private constructor :-)
/// <summary>
/// Finds all automapper profile type and checks if the profile type has accessible constructors, if not it will throw an exception.
/// Accesible constructors are needed for IoC.
/// </summary>
public class AutoMapperProfileConvention : IRegistrationConvention
{
private Func<Type, string> _getName = type => PluginCache.GetPlugin(type).ConcreteKey;
private readonly Type _pluginType;
public AutoMapperProfileConvention()
@martijnburgers
martijnburgers / AutomapperRegistry31.cs
Last active August 4, 2016 20:17
Our AutoMapper registry for AutoMapper 3.1.0
/// <summary>
/// Registry class responsible for registering automapper types in the IoC container.
/// </summary>
public class AutomapperRegistry : Registry
{
public AutomapperRegistry()
{
var platformSpecificRegistry = PlatformAdapter.Resolve<IPlatformSpecificMapperRegistry>();
platformSpecificRegistry.Initialize(); //this will init all the standard mappers specific for this platform.
@martijnburgers
martijnburgers / condition_bug_in_automapper.cs
Last active December 31, 2015 15:19
There is a condition bug in AutoMapper 3.0.0. I didn't check older versions but it seems it exists in earlier versions as well (https://github.com/AutoMapper/AutoMapper/issues/329). The bug occurs when you include sub classes in your super class mapping and then during mapping, map from a sub class to a super class. The following code demonstrat…
class Program
{
//source classes
public abstract class SourceBase
{
public string ASource { get; set; }
public string BSource { get; set; }
}
public class SourceFoo : SourceBase