Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions ImpromptuInterface/src/EmitProxy/ActLikeMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using Dynamitey;
using ImpromptuInterface.Optimization;
using Microsoft.CSharp.RuntimeBinder;

Expand Down Expand Up @@ -57,7 +56,7 @@ public dynamic ActLike(object originalDynamic, params Type[] otherInterfaces)

public TInterface Create<TTarget, TInterface>(params object[] args) where TInterface : class
{
return this.ActLike(Dynamic.InvokeConstructor(typeof(TTarget), args));
return this.ActLike(DynamicConstructor.Invoke(typeof(TTarget), args));
}

public IEnumerable<TInterface> AllActLike<TInterface>(IEnumerable<object> originalDynamic, params Type[] otherInterfaces) where TInterface : class
Expand Down Expand Up @@ -544,6 +543,43 @@ private object CustomAttributeTypeArgument(CustomAttributeTypedArgument argument
}


private static readonly Type[] FuncKinds =
{
typeof(Func<>), typeof(Func<,>), typeof(Func<,,>), typeof(Func<,,,>), typeof(Func<,,,,>),
typeof(Func<,,,,,>), typeof(Func<,,,,,,>), typeof(Func<,,,,,,,>), typeof(Func<,,,,,,,,>),
typeof(Func<,,,,,,,,,>), typeof(Func<,,,,,,,,,,>), typeof(Func<,,,,,,,,,,,>),
typeof(Func<,,,,,,,,,,,,>), typeof(Func<,,,,,,,,,,,,,>), typeof(Func<,,,,,,,,,,,,,,>),
typeof(Func<,,,,,,,,,,,,,,,>), typeof(Func<,,,,,,,,,,,,,,,,>)
};

private static readonly Type[] ActionKinds =
{
typeof(Action), typeof(Action<>), typeof(Action<,>), typeof(Action<,,>), typeof(Action<,,,>),
typeof(Action<,,,,>), typeof(Action<,,,,,>), typeof(Action<,,,,,,>), typeof(Action<,,,,,,,>),
typeof(Action<,,,,,,,,>), typeof(Action<,,,,,,,,,>), typeof(Action<,,,,,,,,,,>),
typeof(Action<,,,,,,,,,,,>), typeof(Action<,,,,,,,,,,,,>), typeof(Action<,,,,,,,,,,,,,>),
typeof(Action<,,,,,,,,,,,,,,>), typeof(Action<,,,,,,,,,,,,,,,>)
};

/// <summary>
/// The open `Func`/`Action` of that shape. `paramCount` counts the return type for a
/// `Func`, as the caller's list does.
/// </summary>
private static Type GenericDelegateType(int paramCount, bool returnVoid = false)
{
var count = returnVoid ? paramCount : paramCount - 1;
if (count > 16)
throw new ArgumentException(
$"{(returnVoid ? "Action" : "Func")} only handles at most {(returnVoid ? 16 : 17)} parameters",
nameof(paramCount));
if (count < 0)
throw new ArgumentException(
$"{(returnVoid ? "Action" : "Func")} must have at least {(returnVoid ? 0 : 1)} parameter(s)",
nameof(paramCount));

return returnVoid ? ActionKinds[count] : FuncKinds[count];
}

private CustomAttributeBuilder GetAttributeBuilder(CustomAttributeData data)
{
var tPropertyInfos = new List<PropertyInfo>();
Expand Down Expand Up @@ -1705,7 +1741,7 @@ internal Type GenerateCallSiteFuncType(IEnumerable<Type> argTypes, Type returnTy
if (tIsFunc)
tList.Add(returnType);

var tFuncGeneric = Dynamitey.Dynamic.GenericDelegateType(tList.Count, !tIsFunc);
var tFuncGeneric = GenericDelegateType(tList.Count, !tIsFunc);


var tFuncType = tFuncGeneric.MakeGenericType(tList.ToArray());
Expand Down
133 changes: 0 additions & 133 deletions ImpromptuInterface/src/Optimization/BareBonesList.cs

This file was deleted.

152 changes: 0 additions & 152 deletions ImpromptuInterface/src/Optimization/BinderHash.cs

This file was deleted.

Loading
Loading