ImpromptuInterface/src/Impromptu.cs
/// <summary>
/// Extension Method that Wraps an existing object with an Explicit interface definition
/// </summary>
/// <typeparam name="TInterface">The type of the interface.</typeparam>
/// <param name="originalDynamic">The original object can be annoymous type, System.DynamicObject as well as any others.</param>
/// <param name="otherInterfaces">Optional other interfaces.</param>
/// <returns></returns>
Extension Method that Wraps an existing object with an Explicit interface definition
Extension Method that Wraps an existing object with an Explicit interface definition
public static TInterface ActLike<TInterface>(this object originalDynamic, params Type[] otherInterfaces) where TInterface : class
        {
            Type tContext;
            bool tDummy;
            originalDynamic = originalDynamic.GetTargetContext(out tContext, out tDummy);
            tContext = tContext.FixContext();
            var tProxy = BuildProxy.BuildType(tContext, typeof(TInterface), otherInterfaces);
            return
                (TInterface)
                InitializeProxy(tProxy, originalDynamic, new[] {typeof (TInterface)}.Concat(otherInterfaces));
        }
public static TInterface ActLike < TInterface > ( this object originalDynamic , params Type [ ] otherInterfaces ) where TInterface : class { Type tContext ; bool tDummy ; originalDynamic = originalDynamic . GetTargetContext ( out tContext , out tDummy ) ; tContext = tContext . FixContext ( ) ; var tProxy = BuildProxy . BuildType ( tContext , typeof ( TInterface ) , otherInterfaces ) ; return ( TInterface ) InitializeProxy ( tProxy , originalDynamic , new [ ] { typeof ( TInterface ) } . Concat ( otherInterfaces ) ) ; }
Extension Method that Wraps an existing object with an Explicit interface definition
Extension Method that Wraps an existing object with an Explicit interface definition
None
object
this
originalDynamic
The original object can be annoymous type, System.DynamicObject as well as any others.
The original object can be annoymous type System . DynamicObject as well as any others .
otherInterfaces
Optional other interfaces.
Optional other interfaces .
typeparam
The type of the interface.
The type of the interface .