Skip to content

Instantly share code, notes, and snippets.

View milutinovici's full-sized avatar

Ivan Milutinović milutinovici

View GitHub Profile
@milutinovici
milutinovici / BestOffersIndex.cs
Last active December 11, 2015 13:29
RavenDB generic static index
public class Offer<TProduct> : where TProduct : Product
{
public string Id { get; set; }
public User Seller { get; set; }
public TProduct Product { get; set; }
public decimal Price { get; set; }
}
public class Product
{
public string Id { get; set; }
@milutinovici
milutinovici / AlmostGenericEntities.cs
Last active December 15, 2015 21:29
Almost generic entities, almost working. Include is being ignored. Tested on EF6 alpha3.
public class Product
{
public int Id { get; set; }
public string Manufacturer { get; set; }
public string Name { get; set; }
}
public class Camera : Product
{
public double Megapixels { get; set; }
}
@milutinovici
milutinovici / GenericActionInvoker.cs
Last active August 29, 2015 14:16
asp.net 5 generic controllers
public class GenericActionInvoker : ControllerActionInvoker
{
protected override async Task<IActionResult> InvokeActionAsync(ActionExecutingContext actionExecutingContext)
{
var actionMethodInfo = _descriptor.MethodInfo;
//find action
if(actionExecutingContext.Controller.GetType().IsGenericType)
{
var parameters = actionMethodInfo.GetParameters().Select(x => x.ParameterType).ToArray();
actionMethodInfo = actionExecutingContext.Controller.GetType().GetMethod(actionMethodInfo.Name, parameters);