Skip to content

Commit

Permalink
Performance and More Targets, Docs
Browse files Browse the repository at this point in the history
  - Improved Tuple Performance (2-5x faster the FSharp.Reflection)
  - Improved Invocation Performance (minor)
  - Added LateType(Assembly,String)
  - One Project Two DLL targets and Testing
  • Loading branch information
jbtule committed Jun 7, 2013
1 parent 554a5b2 commit e6c6fb6
Show file tree
Hide file tree
Showing 35 changed files with 814 additions and 194 deletions.
23 changes: 22 additions & 1 deletion Dynamitey/CacheableInvocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,26 @@ public bool Equals(CacheableInvocation other)
&& Equals(other._convertType, _convertType);
}

/// <summary>
/// Determines whether the specified <see cref="System.Object" /> is equal to this instance.
/// </summary>
/// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
/// <returns>
/// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
/// </returns>
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return Equals(obj as CacheableInvocation);
}

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode()
{
unchecked
Expand All @@ -196,8 +209,16 @@ public override int GetHashCode()
return result;
}
}



/// <summary>
/// Invokes the invocation on specified target with specific args.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="args">The args.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentException">CacheableInvocation can't change conversion type on invoke.;args</exception>
/// <exception cref="System.InvalidOperationException">Unknown Invocation Kind: </exception>
public override object Invoke(object target, params object[] args)
{
var tIContext = target as InvokeContext;
Expand Down
9 changes: 7 additions & 2 deletions Dynamitey/Dynamic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public static CallSite<T> CreateCallSite<T>(CallSiteBinder binder, String_OR_Inv
}


/// <summary>
/// Puts a dynamic linq proxy around the specified enumerable.
/// </summary>
/// <param name="enumerable">The enumerable.</param>
/// <returns></returns>
public static dynamic Linq(object enumerable)
{
if(enumerable.GetType().GetInterfaces().Where(it=>it.IsGenericType)
Expand Down Expand Up @@ -782,10 +787,10 @@ internal static readonly dynamic Impromptu
= new DynamicObjects.LateType("ImpromptuInterface.Impromptu, ImpromptuInterface, PublicKeyToken=0b1781c923b2975b");

internal static readonly dynamic TypeDescriptor
= new DynamicObjects.LateType("System.ComponentModel.TypeDescriptor, System, PublicKeyToken=b77a5c561934e089");
= new DynamicObjects.LateType("System.ComponentModel.TypeDescriptor, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

internal static readonly Type TypeConverterAttributeSL
= Type.GetType("System.ComponentModel.TypeConverter, System, PublicKeyToken=7cec85d7bea7798e", false);
= Type.GetType("System.ComponentModel.TypeConverter, System, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", false);

/// <summary>
/// Goes the extra mile to convert target to type.
Expand Down
7 changes: 6 additions & 1 deletion Dynamitey/DynamicObjects/BaseDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,13 @@ public bool TryGetValue(string key, out object value)
return _dictionary.TryGetValue(key, out value);
}




/// <summary>
/// Sets the property.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
protected void SetProperty(string key, object value)
{
object tOldValue;
Expand Down
57 changes: 52 additions & 5 deletions Dynamitey/DynamicObjects/BaseForwarder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
namespace Dynamitey.DynamicObjects
{

/// <summary>
/// An proxy object
/// </summary>
public interface IForwarder
{
/// <summary>
Expand All @@ -46,7 +49,10 @@ public interface IForwarder

public abstract class BaseForwarder : BaseObject, IForwarder
{


/// <summary>
/// Marks whether we are adding or removing the delegate
/// </summary>
public class AddRemoveMarker
{
/// <summary>
Expand Down Expand Up @@ -174,16 +180,17 @@ public override bool TryGetMember(GetMemberBinder binder, out object result)
return true;

}

#pragma warning disable 1734
/// <summary>
/// Provides the implementation for operations that invoke an object. Classes derived from the <see cref="T:System.Dynamic.DynamicObject"/> class can override this method to specify dynamic behavior for operations such as invoking an object or a delegate.
/// Provides the implementation for operations that invoke an object. Classes derived from the <see cref="T:System.Dynamic.DynamicObject" /> class can override this method to specify dynamic behavior for operations such as invoking an object or a delegate.
/// </summary>
/// <param name="binder">Provides information about the invoke operation.</param>
/// <param name="args">The arguments that are passed to the object during the invoke operation. For example, for the sampleObject(100) operation, where sampleObject is derived from the <see cref="T:System.Dynamic.DynamicObject"/> class, <paramref name="args[0]"/> is equal to 100.</param>
/// <param name="args">The arguments that are passed to the object during the invoke operation. For example, for the sampleObject(100) operation, where sampleObject is derived from the <see cref="T:System.Dynamic.DynamicObject" /> class, <paramref name="args[0]" /> is equal to 100.</param>
/// <param name="result">The result of the object invocation.</param>
/// <returns>
/// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown.
/// </returns>
#pragma warning restore 1734
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
{
if (CallTarget == null)
Expand Down Expand Up @@ -215,6 +222,13 @@ public override bool TryInvoke(InvokeBinder binder, object[] args, out object re
return true;
}

/// <summary>
/// Tries the invoke member.
/// </summary>
/// <param name="binder">The binder.</param>
/// <param name="args">The args.</param>
/// <param name="result">The result.</param>
/// <returns></returns>
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
if (CallTarget == null)
Expand Down Expand Up @@ -246,8 +260,14 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o
return true;
}




/// <summary>
/// Tries the set member.
/// </summary>
/// <param name="binder">The binder.</param>
/// <param name="value">The value.</param>
/// <returns></returns>
public override bool TrySetMember(SetMemberBinder binder, object value)
{
if (CallTarget == null)
Expand Down Expand Up @@ -283,6 +303,13 @@ public override bool TrySetMember(SetMemberBinder binder, object value)
}
}

/// <summary>
/// Tries the index of the get.
/// </summary>
/// <param name="binder">The binder.</param>
/// <param name="indexes">The indexes.</param>
/// <param name="result">The result.</param>
/// <returns></returns>
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
{
if (CallTarget == null)
Expand All @@ -305,6 +332,13 @@ public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out ob
}
}

/// <summary>
/// Tries the index of the set.
/// </summary>
/// <param name="binder">The binder.</param>
/// <param name="indexes">The indexes.</param>
/// <param name="value">The value.</param>
/// <returns></returns>
public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
{
if (CallTarget == null)
Expand Down Expand Up @@ -340,6 +374,13 @@ public bool Equals(BaseForwarder other)
return Equals(other.CallTarget, CallTarget);
}

/// <summary>
/// Determines whether the specified <see cref="System.Object" /> is equal to this instance.
/// </summary>
/// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
/// <returns>
/// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
/// </returns>
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return ReferenceEquals(null, CallTarget);
Expand All @@ -348,6 +389,12 @@ public override bool Equals(object obj)
return Equals((BaseForwarder) obj);
}

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode()
{
return (CallTarget != null ? CallTarget.GetHashCode() : 0);
Expand Down
21 changes: 18 additions & 3 deletions Dynamitey/DynamicObjects/BaseObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,26 @@
using System.Reflection;
namespace Dynamitey.DynamicObjects
{

/// <summary>
/// Dynamic Object that knows about the Impromtu Interface return types;
/// Override Typical Dynamic Object methods, and use TypeForName to get the return type of an interface member.
/// Can Represent an equivalent static type to help dynamically convert member output
/// </summary>

public interface IEquivalentType
{
/// <summary>
/// Gets or sets the type of the equivalent.
/// </summary>
/// <value>
/// The type of the equivalent.
/// </value>
FauxType EquivalentType { get; set; }
}


/// <summary>
/// Dynamic Object that knows about the Impromtu Interface return types;
/// Override Typical Dynamic Object methods, and use TypeForName to get the return type of an interface member.
/// </summary>
public abstract class BaseObject : DynamicObject, IEquivalentType, IServiceProvider

{
Expand All @@ -47,6 +56,12 @@ protected BaseObject()



/// <summary>
/// Tries the name of the member to see if it has a type.
/// </summary>
/// <param name="binderName">Name of the binder.</param>
/// <param name="type">The type.</param>
/// <returns></returns>
public bool TryTypeForName(string binderName, out Type type)
{
var eqType = (IEquivalentType) this;
Expand Down
62 changes: 60 additions & 2 deletions Dynamitey/DynamicObjects/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ public dynamic List(params dynamic[] contents)



/// <summary>
/// Setup List or Array, takes either one <see cref="Activate" /> or a list of constructor args that will use objects Type
/// </summary>
/// <param name="constructorArgs">The constructor args.</param>
/// <returns></returns>
public dynamic ListSetup(params dynamic[] constructorArgs)
{
var tActivate =constructorArgs.OfType<Activate>().SingleOrDefault();
Expand All @@ -191,26 +196,51 @@ public dynamic ListSetup(params dynamic[] constructorArgs)
return this;
}

/// <summary>
/// Setup List or Array if list has a default constrcutor
/// </summary>
/// <typeparam name="TList"></typeparam>
/// <returns></returns>
public dynamic ListSetup<TList>()
{
return ListSetup(new Activate<TList>());
}

/// <summary>
/// Setup List or Array, takes either one <see cref="Activate" /> or a list of constructor args that will use objects Type
/// </summary>
/// <param name="constructorArgsFactory">The constructor args factory.</param>
/// <returns></returns>
public dynamic ListSetup(Func<object[]> constructorArgsFactory)
{
return ListSetup((object)constructorArgsFactory);
}

/// <summary>
/// Setup List or Array if list has a default constrcutor
/// </summary>
/// <typeparam name="TList"></typeparam>
/// <returns></returns>
public dynamic ArraySetup<TList>()
{
return ListSetup(new Activate<TList>());
}

/// <summary>
/// Alternative name for <see cref="ListSetup(object[])" />
/// </summary>
/// <param name="constructorArgs">The constructor args.</param>
/// <returns></returns>
public dynamic ArraySetup(params dynamic[] constructorArgs)
{
return ListSetup(constructorArgs);
}

/// <summary>
/// Alternative name for <see cref="ListSetup{TList}" />
/// </summary>
/// <param name="constructorArgsFactory">The constructor args factory.</param>
/// <returns></returns>
public dynamic ArraySetup(Func<object[]> constructorArgsFactory)
{
return ListSetup((object)constructorArgsFactory);
Expand Down Expand Up @@ -275,6 +305,13 @@ public BuilderTrampoline(Builder<TObjectProtoType> builder)
_buider = builder;
}

/// <summary>
/// Tries the invoke.
/// </summary>
/// <param name="binder">The binder.</param>
/// <param name="args">The args.</param>
/// <param name="result">The result.</param>
/// <returns></returns>
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
{
Activate tBuildType;
Expand All @@ -300,7 +337,15 @@ public class SetupTrampoline : DynamicObject
public SetupTrampoline(Builder<TObjectProtoType> builder){
_buider = builder;
}


/// <summary>
/// Tries the invoke.
/// </summary>
/// <param name="binder">The binder.</param>
/// <param name="args">The args.</param>
/// <param name="result">The result.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentException">Requires argument names for every argument</exception>
public override bool TryInvoke(InvokeBinder binder, dynamic[] args, out object result)
{
if (binder.CallInfo.ArgumentNames.Count != binder.CallInfo.ArgumentCount)
Expand All @@ -315,7 +360,13 @@ public override bool TryInvoke(InvokeBinder binder, dynamic[] args, out object r
}

}


/// <summary>
/// Tries the set member.
/// </summary>
/// <param name="binder">The binder.</param>
/// <param name="value">The value.</param>
/// <returns></returns>
public override bool TrySetMember(SetMemberBinder binder, dynamic value){
if (value != null)
{
Expand All @@ -339,6 +390,13 @@ public override bool TrySetMember(SetMemberBinder binder, dynamic value){
return false;
}

/// <summary>
/// Tries the invoke member.
/// </summary>
/// <param name="binder">The binder.</param>
/// <param name="args">The args.</param>
/// <param name="result">The result.</param>
/// <returns></returns>
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
Type tType;
Expand Down
Loading

0 comments on commit e6c6fb6

Please sign in to comment.