Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Non parameter generic methods fixed.

  • Loading branch information...
commit 4aa1117b0430406952bc13673d8679c00836a2c5 1 parent 5b743c6
@jbtule jbtule authored
Showing with 239 additions and 92 deletions.
  1. +2 −2 ImpromptuInterface.FSharp/AssemblyInfo.fs
  2. +3 −3 ImpromptuInterface.MVVM/Properties/AssemblyInfo.cs
  3. +3 −3 ImpromptuInterface/Properties/AssemblyInfo.cs
  4. +94 −28 ImpromptuInterface/src/Dynamic/ExtensionToInstanceProxy.cs
  5. +8 −0 ImpromptuInterface/src/Dynamic/LinqInstanceProxy.cs
  6. +6 −3 ImpromptuInterface/src/EmitProxy/BuildProxy.cs
  7. +12 −2 ImpromptuInterface/src/EmitProxy/EmitExtensions.cs
  8. +1 −1  NuGetBuild/Core/ImpromptuInterface.MetaData.xml
  9. +1 −1  NuGetBuild/Core/ImpromptuInterface.Symbol.nuspec
  10. +1 −1  NuGetBuild/Core/ImpromptuInterface.nuspec
  11. +2 −2 NuGetBuild/FSharp/ImpromptuInterface.FSharp.MetaData.xml
  12. +2 −2 NuGetBuild/FSharp/ImpromptuInterface.FSharp.Symbol.nuspec
  13. +2 −2 NuGetBuild/FSharp/ImpromptuInterface.FSharp.nuspec
  14. +2 −2 NuGetBuild/MVVM/ImpromptuInterface.MVVM.MetaData.xml
  15. +2 −2 NuGetBuild/MVVM/ImpromptuInterface.MVVM.Symbol.nuspec
  16. +2 −2 NuGetBuild/MVVM/ImpromptuInterface.MVVM.nuspec
  17. +1 −0  NuGetBuild/NuGetBuild.csproj
  18. +14 −0 Tests/UnitTestImpromptuInterface/Basic.cs
  19. +62 −35 Tests/UnitTestImpromptuInterface/Linq.cs
  20. +19 −1 Tests/UnitTestImpromptuInterface/Support/SupportDefinitions.cs
View
4 ImpromptuInterface.FSharp/AssemblyInfo.fs
@@ -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")>]
()
View
6 ImpromptuInterface.MVVM/Properties/AssemblyInfo.cs
@@ -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
View
6 ImpromptuInterface/Properties/AssemblyInfo.cs
@@ -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
View
122 ImpromptuInterface/src/Dynamic/ExtensionToInstanceProxy.cs
@@ -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,26 +187,68 @@ 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);
@@ -216,17 +256,38 @@ protected object InvokeStaticMethod(string name, object[] 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,7 +316,7 @@ 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);
}
}
}
@@ -263,12 +324,17 @@ protected object InvokeStaticMethod(string name, object[] args)
{
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)
{
View
8 ImpromptuInterface/src/Dynamic/LinqInstanceProxy.cs
@@ -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);
}
+
}
View
9 ImpromptuInterface/src/EmitProxy/BuildProxy.cs
@@ -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),
View
14 ImpromptuInterface/src/EmitProxy/EmitExtensions.cs
@@ -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) };
View
2  NuGetBuild/Core/ImpromptuInterface.MetaData.xml
@@ -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>
View
2  NuGetBuild/Core/ImpromptuInterface.Symbol.nuspec
@@ -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>
View
2  NuGetBuild/Core/ImpromptuInterface.nuspec
@@ -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>
View
4 NuGetBuild/FSharp/ImpromptuInterface.FSharp.MetaData.xml
@@ -1,6 +1,6 @@
<metadata>
<id>ImpromptuInterface.FSharp</id>
- <version>1.2.8</version>
+ <version>1.2.9</version>
<authors>Jay Tuley</authors>
<owners>Jay Tuley</owners>
<description>A complete dlr based dynamic operator implementation for F# (.net4 &amp; silverlight4)</description>
@@ -13,6 +13,6 @@
<frameworkAssembly assemblyName="Microsoft.CSharp" />
</frameworkAssemblies>
<dependencies>
- <dependency id="ImpromptuInterface" version="6.1.1" />
+ <dependency id="ImpromptuInterface" version="6.1.2" />
</dependencies>
</metadata>
View
4 NuGetBuild/FSharp/ImpromptuInterface.FSharp.Symbol.nuspec
@@ -2,7 +2,7 @@
<package>
<metadata>
<id>ImpromptuInterface.FSharp</id>
- <version>1.2.8</version>
+ <version>1.2.9</version>
<authors>Jay Tuley</authors>
<owners>Jay Tuley</owners>
<description>A complete dlr based dynamic operator implementation for F# (.net4 &amp; silverlight4)</description>
@@ -15,7 +15,7 @@
<frameworkAssembly assemblyName="Microsoft.CSharp" />
</frameworkAssemblies>
<dependencies>
- <dependency id="ImpromptuInterface" version="6.1.1" />
+ <dependency id="ImpromptuInterface" version="6.1.2" />
</dependencies>
</metadata>
<files>
View
4 NuGetBuild/FSharp/ImpromptuInterface.FSharp.nuspec
@@ -2,7 +2,7 @@
<package>
<metadata>
<id>ImpromptuInterface.FSharp</id>
- <version>1.2.8</version>
+ <version>1.2.9</version>
<authors>Jay Tuley</authors>
<owners>Jay Tuley</owners>
<description>A complete dlr based dynamic operator implementation for F# (.net4 &amp; silverlight4)</description>
@@ -15,7 +15,7 @@
<frameworkAssembly assemblyName="Microsoft.CSharp" />
</frameworkAssemblies>
<dependencies>
- <dependency id="ImpromptuInterface" version="6.1.1" />
+ <dependency id="ImpromptuInterface" version="6.1.2" />
</dependencies>
</metadata>
<files>
View
4 NuGetBuild/MVVM/ImpromptuInterface.MVVM.MetaData.xml
@@ -1,6 +1,6 @@
<metadata>
<id>ImpromptuInterface.MVVM</id>
- <version>4.0.8-beta</version>
+ <version>4.0.9-beta</version>
<authors>Jay Tuley</authors>
<owners>Jay Tuley</owners>
<description>A Lightweight Dynamic MVVM View Model(.net4 &amp; silverlight4 &amp; silverlight5).
@@ -15,6 +15,6 @@
<frameworkAssembly assemblyName="Microsoft.CSharp" />
</frameworkAssemblies>
<dependencies>
- <dependency id="ImpromptuInterface" version="6.1.1" />
+ <dependency id="ImpromptuInterface" version="6.1.2" />
</dependencies>
</metadata>
View
4 NuGetBuild/MVVM/ImpromptuInterface.MVVM.Symbol.nuspec
@@ -2,7 +2,7 @@
<package>
<metadata>
<id>ImpromptuInterface.MVVM</id>
- <version>4.0.8-beta</version>
+ <version>4.0.9-beta</version>
<authors>Jay Tuley</authors>
<owners>Jay Tuley</owners>
<description>A Lightweight Dynamic MVVM View Model(.net4 &amp; silverlight4 &amp; silverlight5).
@@ -17,7 +17,7 @@
<frameworkAssembly assemblyName="Microsoft.CSharp" />
</frameworkAssemblies>
<dependencies>
- <dependency id="ImpromptuInterface" version="6.1.1" />
+ <dependency id="ImpromptuInterface" version="6.1.2" />
</dependencies>
</metadata>
<files>
View
4 NuGetBuild/MVVM/ImpromptuInterface.MVVM.nuspec
@@ -2,7 +2,7 @@
<package>
<metadata>
<id>ImpromptuInterface.MVVM</id>
- <version>4.0.8-beta</version>
+ <version>4.0.9-beta</version>
<authors>Jay Tuley</authors>
<owners>Jay Tuley</owners>
<description>A Lightweight Dynamic MVVM View Model(.net4 &amp; silverlight4 &amp; silverlight5).
@@ -17,7 +17,7 @@
<frameworkAssembly assemblyName="Microsoft.CSharp" />
</frameworkAssemblies>
<dependencies>
- <dependency id="ImpromptuInterface" version="6.1.1" />
+ <dependency id="ImpromptuInterface" version="6.1.2" />
</dependencies>
</metadata>
<files>
View
1  NuGetBuild/NuGetBuild.csproj
@@ -76,6 +76,7 @@
<None Include="Core\ImpromptuInterface.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>ImpromptuInterface.nuspec</LastGenOutput>
+ <SubType>Designer</SubType>
</None>
<None Include="FSharp\ImpromptuInterface.FSharp.nuspec">
<DependentUpon>ImpromptuInterface.FSharp.tt</DependentUpon>
View
14 Tests/UnitTestImpromptuInterface/Basic.cs
@@ -545,6 +545,20 @@ public void OutMethodTest3()
}
[Test]
+ public void GenericMethodTest()
+ {
+ dynamic ot = new OtherThing();
+ IGenericTest test = Impromptu.ActLike(ot);
+
+ var tResult =test.GetThings<Thing>(Guid.Empty);
+
+ Assert.AreEqual(true, tResult is List<Thing>);
+
+ }
+
+
+
+ [Test]
public void GenericOutMethodTest()
{
var tPoco = new GenericMethOutPoco();
View
97 Tests/UnitTestImpromptuInterface/Linq.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@@ -61,50 +62,75 @@ public void MoreGenericsDynamicLinq()
}
+ private dynamic RunPythonHelper( object linq, string code)
+ {
+
+ var tEngine = Python.CreateEngine();
+ var tScope = tEngine.CreateScope();
+
+ tScope.SetVariable("linq", linq);
+
+ var tSource = tEngine.CreateScriptSourceFromString(code.Trim(), SourceCodeKind.Statements);
+ var tCompiled = tSource.Compile();
+
+ tCompiled.Execute(tScope);
+ return tScope.GetVariable("result");
+ }
+
+
[Test]
public void PythonLinq()
{
var expected = Enumerable.Range(1, 10).Where(x=> x < 5).OrderBy(x => 10 - x).First();
+ var actual = RunPythonHelper(Impromptu.Linq(Enumerable.Range(1, 10)),@"
+import System
+result = linq.Where.Overloads[System.Func[int, bool]](lambda x: x < 5).OrderBy(lambda x: 10-x).First()
- var tEngine = Python.CreateEngine();
- var tScope = tEngine.CreateScope();
-
- tScope.SetVariable("linq", Impromptu.Linq(Enumerable.Range(1, 10)));
+");
+ Assert.AreEqual( expected,actual);
+ }
- var tSource = tEngine.CreateScriptSourceFromString(@"
+ [Test]
+ public void PythonLinqGenericArgs()
+ {
+ var start = new Object[] {1, "string", 4, Guid.Empty, 6};
+ var expected = start.OfType<int>().Skip(1).First();
+ var actual = RunPythonHelper(Impromptu.Linq(start), @"
import System
-result = linq.Where.Overloads[System.Func[int, bool]](lambda x: x < 5).OrderBy(lambda x: 10-x).First()
+result = linq.OfType[System.Int32]().Skip(1).First()
-".Trim(), SourceCodeKind.Statements);
- var tCompiled = tSource.Compile();
+");
+ Assert.AreEqual(expected,actual);
+ }
- tCompiled.Execute(tScope);
- var actual = tScope.GetVariable("result");
+ [Test]
+ public void PythonDynamicLinqGenericArgs()
+ {
+ var start = new Object[] { 1, "string", 4, Guid.Empty, 6 };
+ var expected = start.OfType<int>().Skip(1).First();
+ var actual = RunPythonHelper(Impromptu.DynamicLinq(start), @"
+import System
+result = linq.OfType[System.Int32]().Skip(1).First()
+
+");
+ Assert.AreEqual(expected, actual);
+ }
- Assert.AreEqual( expected,actual);
- }
[Test]
public void PythonDynamicLinq()
{
var expected = Enumerable.Range(1, 10).Where(x => x < 5).OrderBy(x => 10 - x).First();
- var tEngine = Python.CreateEngine();
- var tScope = tEngine.CreateScope();
-
- tScope.SetVariable("linq", Impromptu.DynamicLinq(Enumerable.Range(1, 10)));
- var tSource = tEngine.CreateScriptSourceFromString(@"
+ var actual = RunPythonHelper(Impromptu.DynamicLinq(Enumerable.Range(1, 10)),
+ @"
import System
result = linq.Where.Overloads[System.Func[int, bool]](lambda x: x < 5).OrderBy(lambda x: 10-x).First()
-".Trim(), SourceCodeKind.Statements);
- var tCompiled = tSource.Compile();
-
- tCompiled.Execute(tScope);
- var actual = tScope.GetVariable("result");
+");
Assert.AreEqual(expected, actual);
}
@@ -121,9 +147,8 @@ public void PrintOutInterface()
Console.WriteLine("{");
foreach (var line in tList
.Where(it => it.GetParameters().Any()
- && it.GetParameters().First().ParameterType.IsGenericType
- && it.GetParameters().First().ParameterType.GetGenericTypeDefinition() == typeof(IEnumerable<>)
- && HelperSignleGenericArgMatch(it.GetParameters().First().ParameterType.GetGenericArguments().Single())
+ && (HelperIsGenericExtension(it,typeof(IEnumerable<>))
+ || it.GetParameters().First().ParameterType == typeof(IEnumerable))
)
.Select(HelperMakeName))
{
@@ -136,9 +161,7 @@ public void PrintOutInterface()
Console.WriteLine("{");
foreach (var line in tList
.Where(it => it.GetParameters().Any()
- && it.GetParameters().First().ParameterType.IsGenericType
- && it.GetParameters().First().ParameterType.GetGenericTypeDefinition() == typeof(IOrderedEnumerable<>)
- && HelperSignleGenericArgMatch(it.GetParameters().First().ParameterType.GetGenericArguments().Single())
+ && HelperIsGenericExtension(it,typeof(IOrderedEnumerable<>))
)
.Select(HelperMakeName))
{
@@ -150,13 +173,10 @@ public void PrintOutInterface()
Console.WriteLine("//Skipped Methods");
foreach (var line in tList
.Where(it => it.GetParameters().Any()
- && !(it.GetParameters().First().ParameterType.IsGenericType
- && it.GetParameters().First().ParameterType.GetGenericTypeDefinition() != typeof(IOrderedEnumerable<>)
- && HelperSignleGenericArgMatch(it.GetParameters().First().ParameterType.GetGenericArguments().Single()))
- && !(it.GetParameters().First().ParameterType.IsGenericType
- && it.GetParameters().First().ParameterType.GetGenericTypeDefinition() == typeof(IOrderedEnumerable<>)
- && HelperSignleGenericArgMatch(it.GetParameters().First().ParameterType.GetGenericArguments().Single()))
- ).Select(HelperMakeNameDebug))
+ && !(HelperIsGenericExtension(it, typeof(IEnumerable<>)))
+ && !(HelperIsGenericExtension(it, typeof(IOrderedEnumerable<>)))
+ && !(it.GetParameters().First().ParameterType == typeof(IEnumerable)))
+ .Select(HelperMakeNameDebug))
{
Console.WriteLine("//" + line);
}
@@ -164,6 +184,13 @@ public void PrintOutInterface()
}
+ private bool HelperIsGenericExtension(MethodInfo it, Type genericType)
+ {
+ return it.GetParameters().First().ParameterType.IsGenericType
+ && it.GetParameters().First().ParameterType.GetGenericTypeDefinition() == genericType
+ && HelperSignleGenericArgMatch(it.GetParameters().First().ParameterType.GetGenericArguments().Single());
+ }
+
bool HelperSignleGenericArgMatch(Type info)
{
foreach (var name in new[] { "TSource", "TFirst", "TOuter" })
View
20 Tests/UnitTestImpromptuInterface/Support/SupportDefinitions.cs
@@ -16,6 +16,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Dynamic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
@@ -343,10 +344,27 @@ public bool Func(out string result)
result = "success";
return true;
}
+ }
+
+
+ public class Thing { }
+
+ public interface IGenericTest
+ {
+ List<T> GetThings<T>(Guid test) where T : Thing;
+ }
+ public class OtherThing
+ {
+
+ List<T> GetThings<T>(Guid test) where T : Thing
+ {
+ return new List<T>();
+ }
-
}
+
+
public class GenericMethOutPoco
{
public bool Func<T>(out T result)
Please sign in to comment.
Something went wrong with that request. Please try again.