Permalink
Browse files

Non parameter generic methods fixed.

  • Loading branch information...
jbtule committed Aug 28, 2012
1 parent 5b743c6 commit 4aa1117b0430406952bc13673d8679c00836a2c5
@@ -16,7 +16,7 @@ open System.Runtime.InteropServices;
[<assembly: AssemblyConfiguration("")>]
[<assembly: AssemblyCompany("Ekon Benefits")>]
[<assembly: AssemblyProduct("ImpromptuInterface.FSharp")>]
-[<assembly: AssemblyCopyright("Copyright © Ekon Benefits 2011")>]
+[<assembly: AssemblyCopyright("Copyright © Ekon Benefits 2011-2012")>]
[<assembly: AssemblyTrademark("")>]
[<assembly: AssemblyCulture("")>]
@@ -40,5 +40,5 @@ open System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the ‘*’ as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[<assembly: AssemblyVersion("1.2.8.0")>]
+[<assembly: AssemblyVersion("1.2.9.0")>]
()
@@ -17,7 +17,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Ekon Benefits")]
[assembly: AssemblyProduct("ImpromptuInterface.MVVM")]
-[assembly: AssemblyCopyright("Copyright © Ekon Benefits 2011")]
+[assembly: AssemblyCopyright("Copyright © Ekon Benefits 2011-2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -42,7 +42,7 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
#if SILVERLIGHT
-[assembly: AssemblyVersion("4.0.8.0")]
+[assembly: AssemblyVersion("4.0.9.0")]
#else
-[assembly: AssemblyVersion("4.0.8.*")]
+[assembly: AssemblyVersion("4.0.9.*")]
#endif
@@ -32,7 +32,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Ekon Benefits")]
[assembly: AssemblyProduct("ImpromptuInterface")]
-[assembly: AssemblyCopyright("Copyright © Ekon Benefits 2010-2011")]
+[assembly: AssemblyCopyright("Copyright © Ekon Benefits 2010-2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -59,10 +59,10 @@
#if SILVERLIGHT
-[assembly: AssemblyVersion("6.1.1.0")]
+[assembly: AssemblyVersion("6.1.2.0")]
#else
-[assembly: AssemblyVersion("6.1.1.*")]
+[assembly: AssemblyVersion("6.1.2.*")]
#endif
@@ -81,23 +81,25 @@ public override bool TryGetMember(GetMemberBinder binder, out object result)
var tInterface = CallTarget.GetType().GetInterface(_extendedType.Name, false);
result = new Invoker(binder.Name,
- tInterface.IsGenericType ? tInterface.GetGenericArguments() : new Type[] {}, this);
+ tInterface.IsGenericType ? tInterface.GetGenericArguments() : new Type[] {},null, this);
}
return true;
}
public class Invoker:ImpromptuObject
{
- private string _name;
- private ExtensionToInstanceProxy _parent;
- private IDictionary<int,Type[]> _overloadTypes;
- private Type[] _genericParams;
+ protected string _name;
+ protected ExtensionToInstanceProxy _parent;
+ protected IDictionary<int, Type[]> _overloadTypes;
+ protected Type[] _genericParams;
+ protected Type[] _genericMethodParameters;
- internal Invoker(string name, Type[] genericParameters, ExtensionToInstanceProxy parent, Type[] overloadTypes = null)
+ internal Invoker(string name, Type[] genericParameters, Type[] genericMethodParameters, ExtensionToInstanceProxy parent, Type[] overloadTypes = null)
{
_name = name;
_parent = parent;
_genericParams = genericParameters;
+ _genericMethodParameters = genericMethodParameters;
_overloadTypes = new Dictionary<int,Type[]>();
if (overloadTypes == null)
@@ -168,17 +170,13 @@ public override bool TryGetMember(GetMemberBinder binder, out object result)
{
if (binder.Name == "Overloads")
{
- result = this;
+ result = new OverloadInvoker(_name, _genericParams,_genericMethodParameters, _parent);
return true;
}
return base.TryGetMember(binder, out result);
}
- public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
- {
- result = new Invoker(_name, _genericParams, _parent, indexes.Select(it=>Impromptu.InvokeConvert(it,typeof(Type),@explicit:true)).Cast<Type>().ToArray());
- return true;
- }
+
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
{
@@ -189,44 +187,107 @@ public override bool TryInvoke(InvokeBinder binder, object[] args, out object re
.Select(it => it.Item2 != null ? Impromptu.InvokeConvert(it.Item2, it.Item1, @explicit: true) : null).ToArray();
}
- result = _parent.InvokeStaticMethod(_name, tArgs);
+
+ var name = InvokeMemberName.Create(_name, _genericMethodParameters);
+
+ result = _parent.InvokeStaticMethod(name, tArgs);
+ return true;
+ }
+
+ public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
+ {
+ result = new Invoker(_name, _genericParams, indexes.Select(it => Impromptu.InvokeConvert(it, typeof(Type), @explicit: true)).Cast<Type>().ToArray(), _parent);
return true;
}
}
+ public class OverloadInvoker:Invoker
+ {
+ internal OverloadInvoker(string name, Type[] genericParameters, Type[] genericMethodParameters, ExtensionToInstanceProxy parent)
+ : base(name, genericParameters,genericMethodParameters, parent)
+ {
+ }
+
+
+ public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
+ {
+ result = new Invoker(_name, _genericParams,_genericMethodParameters, _parent, indexes.Select(it => Impromptu.InvokeConvert(it, typeof(Type), @explicit: true)).Cast<Type>().ToArray());
+ return true;
+ }
+ }
public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
{
if (!base.TryInvokeMember(binder, args, out result))
{
- result = InvokeStaticMethod(binder.Name, args);
+
+ Type[] types = null;
+ try
+ {
+ IList<Type> typeList =Impromptu.InvokeGet(binder,
+ "Microsoft.CSharp.RuntimeBinder.ICSharpInvokeOrInvokeMemberBinder.TypeArguments");
+ if(typeList != null)
+ {
+
+ types = typeList.ToArray();
+
+ }
+
+ }catch(RuntimeBinderException)
+ {
+ types = null;
+ }
+
+ var name=InvokeMemberName.Create;
+ result = InvokeStaticMethod(name(binder.Name, types), args);
}
return true;
}
- protected object InvokeStaticMethod(string name, object[] args)
+ protected object InvokeStaticMethod(String_OR_InvokeMemberName name, object[] args)
{
var staticType = InvokeContext.CreateStatic;
-
+ var nameArgs = InvokeMemberName.Create;
var tList = new List<object> { CallTarget };
tList.AddRange(args);
object result =null;
var sucess = false;
var exceptionList = new List<Exception>();
+
+ var tGenericPossibles = new List<Type[]>();
+ if (name.GenericArgs != null && name.GenericArgs.Length > 0)
+ {
+ var tInterface = CallTarget.GetType().GetInterface(_extendedType.Name, false);
+ var tTypeGenerics = (tInterface.IsGenericType ? tInterface.GetGenericArguments()
+ : new Type[] { }).Concat(name.GenericArgs).ToArray();
+
+ tGenericPossibles.Add(tTypeGenerics);
+ tGenericPossibles.Add(name.GenericArgs);
+ }
+ else
+ {
+ tGenericPossibles.Add(null);
+ }
+
+
+
foreach (var sType in _staticTypes)
{
- try
+ foreach (var tGenericPossible in tGenericPossibles)
{
- result = Impromptu.InvokeMember(staticType(sType), name, tList.ToArray());
- sucess = true;
- break;
- }
- catch (RuntimeBinderException ex)
- {
- exceptionList.Add(ex);
+ try
+ {
+ result = Impromptu.InvokeMember(staticType(sType), nameArgs(name.Name,tGenericPossible), tList.ToArray());
+ sucess = true;
+ break;
+ }
+ catch (RuntimeBinderException ex)
+ {
+ exceptionList.Add(ex);
+ }
}
}
@@ -242,7 +303,7 @@ protected object InvokeStaticMethod(string name, object[] args)
Type tOutType;
- if (TryTypeForName(name, out tOutType))
+ if (TryTypeForName(name.Name, out tOutType))
{
if (tOutType.IsInterface)
{
@@ -255,20 +316,25 @@ protected object InvokeStaticMethod(string name, object[] args)
if (InstanceHints.Select(it => tIsGeneric && it.IsGenericType ? it.GetGenericTypeDefinition() : it)
.Contains(tOutType))
{
- result = new ExtensionToInstanceProxy(result,_extendedType, _staticTypes, _instanceHints);
+ result = CreateSelf(result, _extendedType, _staticTypes, _instanceHints);
}
}
}
else
{
if (IsExtendedType(result))
{
- result = new ExtensionToInstanceProxy(result, _extendedType, _staticTypes, _instanceHints);
+ result = CreateSelf(result, _extendedType, _staticTypes, _instanceHints);
}
}
return result;
- }
+ }
+
+ protected virtual ExtensionToInstanceProxy CreateSelf(object target, Type extendedType, Type[] staticTypes, Type[] instanceHints)
+ {
+ return new ExtensionToInstanceProxy(target,extendedType,staticTypes, instanceHints);
+ }
private bool IsExtendedType(object target)
{
@@ -31,6 +31,11 @@ public LinqInstanceProxy(dynamic target)
}
+ protected override ExtensionToInstanceProxy CreateSelf(object target, Type extendedType, Type[] staticTypes, Type[] instanceHints)
+ {
+ return new LinqInstanceProxy(target);
+ }
+
#endif
public IEnumerator<object> GetEnumerator()
{
@@ -62,6 +67,7 @@ public interface ILinq<TSource> : IEnumerable<TSource>
Nullable<Double> Average(Func<TSource, Nullable<Double>> selector);
Decimal Average(Func<TSource, Decimal> selector);
Nullable<Decimal> Average(Func<TSource, Nullable<Decimal>> selector);
+ ILinq<TResult> Cast<TResult>();
ILinq<TSource> Concat(IEnumerable<TSource> second);
Boolean Contains(TSource value);
Boolean Contains(TSource value, IEqualityComparer<TSource> comparer);
@@ -123,6 +129,7 @@ public interface ILinq<TSource> : IEnumerable<TSource>
Decimal Min(Func<TSource, Decimal> selector);
Nullable<Decimal> Min(Func<TSource, Nullable<Decimal>> selector);
TResult Min<TResult>(Func<TSource, TResult> selector);
+ ILinq<TResult> OfType<TResult>();
IOrderedLinq<TSource> OrderBy<TKey>(Func<TSource, TKey> keySelector);
IOrderedLinq<TSource> OrderBy<TKey>(Func<TSource, TKey> keySelector, IComparer<TKey> comparer);
IOrderedLinq<TSource> OrderByDescending<TKey>(Func<TSource, TKey> keySelector);
@@ -181,4 +188,5 @@ public interface IOrderedLinq<TSource> : ILinq<TSource>, IOrderedEnumerable<TSou
IOrderedLinq<TSource> ThenByDescending<TKey>(Func<TSource, TKey> keySelector, IComparer<TKey> comparer);
}
+
}
@@ -581,8 +581,8 @@ private static void MakeMethod(ModuleBuilder builder,MethodInfo info, TypeBuilde
tParamTypes = tReplacedTypes.Item2;
tReducedParams = tParamTypes.Select(ReduceToElementType).ToArray();
-
- tCallSite = tCallSite.GetGenericTypeDefinition().MakeGenericType(tReducedParams.SelectMany(FlattenGenericParameters).Distinct().ToArray());
+ var tGenericParams = tMethodBuilder.GetGenericArguments();
+ tCallSite = tCallSite.GetGenericTypeDefinition().MakeGenericType(tGenericParams);
if (tConvertFuncType != null)
tConvertFuncType = UpdateCallsiteFuncType(tConvertFuncType, tReturnType);
tInvokeFuncType = UpdateCallsiteFuncType(tInvokeFuncType, tReturnType != typeof(void) ? typeof(object) : typeof(void), tReducedParams);
@@ -713,6 +713,7 @@ MethodEmitInfo emitInfo
tIlGen.EmitDynamicMethodInvokeBinder(
emitInfo.ResolveReturnType == typeof(void) ? CSharpBinderFlags.ResultDiscarded : CSharpBinderFlags.None,
emitInfo.Name,
+ methodBuilder.GetGenericArguments(),
emitInfo.ContextType,
paramInfo,
emitInfo.ArgNames);
@@ -1035,6 +1036,7 @@ private static void MakeEvent(ModuleBuilder builder, EventInfo info, TypeBuilder
tIlGen.EmitDynamicMethodInvokeBinder(
CSharpBinderFlags.InvokeSpecialName | CSharpBinderFlags.ResultDiscarded,
tRemoveMethod.Name,
+ Enumerable.Empty<Type>(),
tEmitInfo.ContextType,
tRemoveMethod.GetParameters(),
Enumerable.Repeat(default(string),
@@ -1145,7 +1147,8 @@ private static void MakeEvent(ModuleBuilder builder, EventInfo info, TypeBuilder
{
tIlGen.EmitDynamicMethodInvokeBinder(
CSharpBinderFlags.InvokeSpecialName | CSharpBinderFlags.ResultDiscarded,
- tAddMethod.Name,
+ tAddMethod.Name,
+ Enumerable.Empty<Type>(),
tEmitInfo.ContextType,
tAddMethod.GetParameters(),
Enumerable.Repeat(default(string),
@@ -345,11 +345,21 @@ public static void EmitLoadLocation(this ILGenerator generator, int location)
/// <param name="context">The context.</param>
/// <param name="argInfo">The arg info.</param>
/// <param name="argNames">The arg names.</param>
- public static void EmitDynamicMethodInvokeBinder(this ILGenerator generator, CSharpBinderFlags flag, string name, Type context, ParameterInfo[] argInfo, IEnumerable<string> argNames)
+ public static void EmitDynamicMethodInvokeBinder(this ILGenerator generator, CSharpBinderFlags flag, string name, IEnumerable<Type> genericParms, Type context, ParameterInfo[] argInfo, IEnumerable<string> argNames)
{
+ if (genericParms != null && !genericParms.Any())
+ genericParms = null;
+
generator.Emit(OpCodes.Ldc_I4, (int)flag);
generator.Emit(OpCodes.Ldstr, name);
- generator.Emit(OpCodes.Ldnull);
+ if (genericParms == null)
+ {
+ generator.Emit(OpCodes.Ldnull);
+ }
+ else
+ {
+ generator.EmitArray(typeof(Type), genericParms.Select(arg => (Action<ILGenerator>)(gen => gen.EmitTypeOf(arg))).ToList());
+ }
generator.EmitTypeOf(context);
var tList = new List<Action<ILGenerator>> { gen => gen.EmitCreateCSharpArgumentInfo(CSharpArgumentInfoFlags.None) };
@@ -1,6 +1,6 @@
<metadata>
<id>ImpromptuInterface</id>
- <version>6.1.1</version>
+ <version>6.1.2</version>
<authors>Jay Tuley</authors>
<owners>Jay Tuley</owners>
<description>A Lightweight Duck Casting Framework for dynamic C# 4.0 (.net4 &amp; silverlight4 &amp; silveright5 ). Includes helper methods for dynamic invocation via method and property names known only at runtime (runs faster than reflection).</description>
@@ -2,7 +2,7 @@
<package>
<metadata>
<id>ImpromptuInterface</id>
- <version>6.1.1</version>
+ <version>6.1.2</version>
<authors>Jay Tuley</authors>
<owners>Jay Tuley</owners>
<description>A Lightweight Duck Casting Framework for dynamic C# 4.0 (.net4 &amp; silverlight4 &amp; silveright5 ). Includes helper methods for dynamic invocation via method and property names known only at runtime (runs faster than reflection).</description>
@@ -2,7 +2,7 @@
<package>
<metadata>
<id>ImpromptuInterface</id>
- <version>6.1.1</version>
+ <version>6.1.2</version>
<authors>Jay Tuley</authors>
<owners>Jay Tuley</owners>
<description>A Lightweight Duck Casting Framework for dynamic C# 4.0 (.net4 &amp; silverlight4 &amp; silveright5 ). Includes helper methods for dynamic invocation via method and property names known only at runtime (runs faster than reflection).</description>
Oops, something went wrong.

0 comments on commit 4aa1117

Please sign in to comment.