Skip to content

Instantly share code, notes, and snippets.

View Antaris's full-sized avatar
🎯
Focusing

Matthew Abbott Antaris

🎯
Focusing
View GitHub Profile
@Antaris
Antaris / FunctionFactory.cs
Created April 11, 2011 20:28
Extends the System.Linq.Dynamic.ExpressionParser sample to build a generic expression parser.
public static class FunctionFactory
{
private static Delegate CreateInternal(Type[] argumentTypes, Type returnType, string expression, string[] argumentNames = null)
{
if (argumentNames != null)
{
if (argumentTypes.Length != argumentNames.Length)
throw new ArgumentException("The number of argument names does not equal the number of argument types.");
}
@Antaris
Antaris / DependencyList.cs
Created February 6, 2012 14:17
Sorting dependencies using DependencyList
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
/// <summary>
/// Represents a list whose items can be dependant on each other, and enumerating the list will sort the items
/// as per their dependency requirements.
/// </summary>
namespace CompileModuleExample
{
public class Greeter
{
public string GetMessage()
{
}
}
}
public class ConnectionStringProvider
{
private readonly IApplicationEnvironment _appEnv;
private readonly IConfiguration _config;
public ConnectionStringProvider(IApplicationEnvironment appEnv, IConfiguration config)
{
_appEnv = appEnv;
_config = config;
}
public abstract class StartupBase
{
public virtual void ConfigureService(IServiceCollection services)
{
// Standard registrations
ConfigureEntityFramework(services);
}
public abstract void ConfigureEntityFramework(IServiceCollection services);
@Antaris
Antaris / gist:5663603
Created May 28, 2013 15:29
Older Android devices seem to struggle with Cassette's release urls (/cassette.axd/styleseet/*, etc) because of the presence of an underscore. The following re-write rules will rewrite the outbound html to change the urls to something Android 2.* devices will like, and an inbound rewrite to match incoming requests to the CassetteHttpHandler. Thi…
<rewrite>
<outboundRules>
<rule name="CassetteOutboundUrl" preCondition="HtmlContent" stopProcessing="false">
<match filterByTags="Link, Script" pattern="^/cassette.axd/(.*?)/(.*)" />
<action type="Rewrite" value="/cassette.axd/?type={R:1}&amp;data={R:2}" />
</rule>
<preConditions>
<remove name="HtmlContent" />
<preCondition name="HtmlContent">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
@Antaris
Antaris / Program.cs
Created January 5, 2016 14:13
ASP.NET 5 Dependency Injection / Service Resolving in a Console App package
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
namespace ConsoleApp1
{
public class Program
{
@Antaris
Antaris / MyContext.cs
Created October 14, 2016 05:27 — forked from divega/MyContext.cs
Simple builder class for creating TVPs that work in .NET Core 1.0
using Microsoft.EntityFrameworkCore;
namespace TvpSampleApp
{
public class MyContext : DbContext
{
public DbSet<Person> People { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
@Antaris
Antaris / BlogDbContext.cs
Last active October 18, 2016 08:32
Early work on custom type conversions for Entity Framework
public class BlogDbContext : DbContext
{
public DbSet<BlogPost> Posts { get; set; }
}
public class DynamicRouter : IRouter
{
private IRouter _router;
public DynamicRouter(IRouter router)
{
_router = router;
}
public Task RouteAsync(RouteContext context)