Skip to content

Instantly share code, notes, and snippets.

View hagbarddenstore's full-sized avatar

Kim Johansson hagbarddenstore

View GitHub Profile
void Main()
{
var testApplication = new TestApplication();
testApplication.SomeEvent += EventHandler;
testApplication.FireEvent();
}
void EventHandler(object sender, EventArgs e)
void Main()
{
var testApplication = new TestApplication();
var eventInfo = testApplication.GetType().GetEvents().First();
EventHandlerPusher.AddEventHandler(testApplication, eventInfo, MyEventHandler);
testApplication.FireEvent();
}
void Main()
{
var testApplication = new TestApplication();
var eventInfo = testApplication.GetType().GetEvents().First();
EventHandlerPusher.AddEventHandler(testApplication, eventInfo, MyEventHandler);
EventHandlerPusher.AddEventHandler(testApplication, eventInfo, MyEventHandler);
testApplication.FireEvent();
private IEnumerable<Task> CreateHandlerTasks(IDomainEvent domainEvent)
{
if (domainEvent == null)
{
return new Task[0];
}
Func<IDomainEvent, IEnumerable<Task>> handlerCreator;
var type = domainEvent.GetType();
@hagbarddenstore
hagbarddenstore / LabelExtensions.cs
Created February 24, 2014 13:51
Provides ASP.NET MVC label extension methods for HtmlHelper.
public static class LabelExtensions
{
public static MvcHtmlString LabelFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, object htmlAttributes)
{
return LabelHelper(html, ModelMetadata.FromLambdaExpression(expression, html.ViewData), ExpressionHelper.GetExpressionText(expression), null, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
}
internal static MvcHtmlString LabelHelper(HtmlHelper html, ModelMetadata metadata, string htmlFieldName, string labelText = null, IDictionary<string, object> htmlAttributes = null)
{
var resolvedLabelText = labelText ?? metadata.DisplayName ?? metadata.PropertyName ?? htmlFieldName.Split('.').Last();
@hagbarddenstore
hagbarddenstore / Main.cs
Created March 19, 2014 08:47
Sort dates in .NET.
void Main()
{
var dates = new[]
{
new DateTime(2000, 1, 1),
new DateTime(2005, 1, 1),
new DateTime(2010, 1, 1),
new DateTime(2015, 1, 1)
};
using System.IO;
namespace A
{
public class B
{
private string _configurationFilePath = "config.txt";
private string _recPath = string.Empty;
public string ReadConfig()
@hagbarddenstore
hagbarddenstore / GuidConstraint.cs
Last active August 29, 2015 13:57
An IRouteConstraint for ASP.NET MVC that validates a route data value to be a valid GUID.
namespace Hagbarddenstore.Mvc
{
using System;
using System.Web;
using System.Web.Routing;
/// <summary>
/// Defines the GuidConstraint type.
/// </summary>
public class GuidConstraint : IRouteConstraint
@hagbarddenstore
hagbarddenstore / StructureMapDependencyResolver.cs
Created April 2, 2014 07:48
An implementation of the System.Web.Mvc.IDependencyResolver interface with StructureMap.
namespace Hagbarddenstore.Mvc
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using StructureMap;
/// <summary>
<Project>
<ItemGroup>
<Compile Include="$(OutputPath)\MyFile.cs">
<Link>MyFile.cs</Link>
</Compile>
</ItemGroup>
</Project>