Permalink
Browse files

Merge

  • Loading branch information...
2 parents 078a5c3 + 0d08284 commit 256573726d8b2cd55b499b25f9ffe17028456e58 jayt committed May 18, 2012
View
@@ -23,3 +23,5 @@ daf2f8290741326cf4336ad999f3e12307a4b2f3 Core 5.1.1/MVVM 3.1.1
921fa9326fb0757e0ed6be74cfa635d1b373d652 Core 5.6.2 /MVVM 3.6.2/FSharp 1.0.2
35f8ce1afaaffef1658e173b61a3c3c9f127d342 FSharp 1.1.0
ced636805c17d1bce5dec19bab446b2002f99b21 5.6.4
+899af95cc13343166c6fea4c95fb3f7a39e634e4 Core 5.6.6
+465dff2029006ef55c20c39489a376be5342be62 Core 5.6.7
@@ -85,6 +85,9 @@
<Compile Include="..\ImpromptuInterface\Properties\AssemblyInfo.cs">
<Link>Properties\AssemblyInfo.cs</Link>
</Compile>
+ <Compile Include="..\ImpromptuInterface\src\ActLikeCaster.cs">
+ <Link>src\ActLikeCaster.cs</Link>
+ </Compile>
<Compile Include="..\ImpromptuInterface\src\Dynamic\Builder.cs">
<Link>src\Dynamic\Builder.cs</Link>
</Compile>
@@ -58,7 +58,15 @@
// [assembly: AssemblyVersion("1.0.*")]
#if SILVERLIGHT
+<<<<<<< local
[assembly: AssemblyVersion("5.7.0.0")]
+=======
+[assembly: AssemblyVersion("5.6.7.0")]
+>>>>>>> other
#else
+<<<<<<< local
[assembly: AssemblyVersion("5.7.0.*")]
+=======
+[assembly: AssemblyVersion("5.6.7.*")]
+>>>>>>> other
#endif
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using ImpromptuInterface.Dynamic;
+
+namespace ImpromptuInterface
+{
+
+ public class ActLikeCaster: ImpromptuForwarder
+ {
+ private List<Type> _interfaceTypes;
+
+ public override bool TryConvert(System.Dynamic.ConvertBinder binder, out object result)
+ {
+ result = null;
+
+ if (binder.Type.IsInterface)
+ {
+ _interfaceTypes.Insert(0, binder.Type);
+ result = Impromptu.DynamicActLike(Target, _interfaceTypes.ToArray());
+ return true;
+ }
+
+ if(binder.Type.IsInstanceOfType(Target))
+ {
+ result = Target;
+ }
+
+ return false;
+ }
+
+
+ public ActLikeCaster(object target, IEnumerable<Type> types) : base(target)
+ {
+ _interfaceTypes = types.ToList();
+ }
+
+ #if !SILVERLIGHT
+
+ public ActLikeCaster(SerializationInfo info, StreamingContext context)
+ : base(info, context)
+ {
+ }
+
+ #endif
+ }
+}
@@ -29,12 +29,32 @@ namespace ImpromptuInterface
using System;
+
+
/// <summary>
/// Main API
/// </summary>
public static class Impromptu
{
+
+ private static readonly Type ComObjectType;
+
+ private static readonly dynamic ComBinder;
+
+ static Impromptu()
+ {
+ try
+ {
+ ComObjectType = typeof(object).Assembly.GetType("System.__ComObject");
+ ComBinder = new Dynamic.ImpromptuLateLibraryType(
+ "System.Dynamic.ComBinder, System.Dynamic, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
+ }
+ catch
+ {
+
+ }
+ }
/// <summary>
/// Creates a cached call site at runtime.
/// </summary>
@@ -651,7 +671,7 @@ public static Type GenericDelegateType(int paramCount, bool returnVoid = false)
{
var tParamCount = returnVoid ? paramCount : paramCount - 1;
if (tParamCount > 16)
- throw new ArgumentException(String.Format("{0} only handle at most {1} parameters", returnVoid ? "Action" : "Func", returnVoid ? 16 : 17), "paramCount");
+ throw new ArgumentException(String.Format("{0} only handle at most {1} parameters", returnVoid ? "Action" : "Func", returnVoid ? 16 : 17), "paramCount");
if(tParamCount < 0)
throw new ArgumentException(String.Format("{0} must have at least {1} parameter(s)", returnVoid ? "Action" : "Func", returnVoid ? 0 : 1), "paramCount");
@@ -679,6 +699,13 @@ public static IEnumerable<string> GetMemberNames(object target, bool dynamicOnly
if (tTarget !=null)
{
tList.AddRange(tTarget.GetMetaObject(Expression.Constant(tTarget)).GetDynamicMemberNames());
+ }else
+ {
+
+ if(ComObjectType !=null && ComObjectType.IsInstanceOfType(target))
+ {
+ tList.AddRange(ComBinder.GetDynamicDataMemberNames(target));
+ }
}
return tList;
}
@@ -758,6 +785,18 @@ public static dynamic Invoke(CallSite callSite, object target, params object[] a
/// <summary>
+ /// Extension Method that Wraps an existing object with an Interface of what it is implicitly assigned to.
+ /// </summary>
+ /// <param name="originalDynamic">The original dynamic.</param>
+ /// <param name="otherInterfaces">The other interfaces.</param>
+ /// <returns></returns>
+ public static dynamic ActLike(this object originalDynamic, params Type[] otherInterfaces)
+ {
+ return new ActLikeCaster(originalDynamic, otherInterfaces);
+ }
+
+
+ /// <summary>
/// Makes static methods for the passed in property spec, designed to be used with old api's that reflect properties.
/// </summary>
/// <param name="originalDynamic">The original dynamic.</param>
@@ -287,6 +287,7 @@ internal static object[] GetArgsAndNames(object[]args,out string[]argNames)
argNames = new string[args.Length];
var tArgSet = false;
+ var tNewArgs = new object[args.Length];
for (int i = 0; i < args.Length; i++)
{
var tArg = args[i];
@@ -296,16 +297,20 @@ internal static object[] GetArgsAndNames(object[]args,out string[]argNames)
{
tName = ((InvokeArg)tArg).Name;
- args[i] = ((InvokeArg)tArg).Value;
+ tNewArgs[i] = ((InvokeArg)tArg).Value;
tArgSet = true;
+ }else
+ {
+ tNewArgs[i] = tArg;
}
argNames[i] = tName;
}
+
// ReSharper restore ForCanBeConvertedToForeach
// ReSharper restore LoopCanBeConvertedToQuery
if (!tArgSet)
argNames = null;
- return args;
+ return tNewArgs;
}
}
}
@@ -1,6 +1,10 @@
<metadata>
<id>ImpromptuInterface</id>
+<<<<<<< local
<version>5.7.0</version>
+=======
+ <version>5.6.7</version>
+>>>>>>> other
<authors>Jay Tuley</authors>
<owners>Jay Tuley</owners>
<description>A Lightweight Duck Casting Framework for dynamic C# 4.0 (.net4 &amp; silverlight4). Includes helper methods for dynamic invocation via method and property names known only at runtime (runs faster than reflection).</description>
@@ -2,7 +2,11 @@
<package>
<metadata>
<id>ImpromptuInterface</id>
+<<<<<<< local
<version>5.7.0</version>
+=======
+ <version>5.6.7</version>
+>>>>>>> other
<authors>Jay Tuley</authors>
<owners>Jay Tuley</owners>
<description>A Lightweight Duck Casting Framework for dynamic C# 4.0 (.net4 &amp; silverlight4). Includes helper methods for dynamic invocation via method and property names known only at runtime (runs faster than reflection).</description>
@@ -2,7 +2,11 @@
<package>
<metadata>
<id>ImpromptuInterface</id>
+<<<<<<< local
<version>5.7.0</version>
+=======
+ <version>5.6.7</version>
+>>>>>>> other
<authors>Jay Tuley</authors>
<owners>Jay Tuley</owners>
<description>A Lightweight Duck Casting Framework for dynamic C# 4.0 (.net4 &amp; silverlight4). 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 2565737

Please sign in to comment.