Exemple #1
0
 /// <summary>
 /// Creates the call site.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="binder">The binder.</param>
 /// <param name="name">The name.</param>
 /// <param name="context">The context.</param>
 /// <param name="argNames">The arg names.</param>
 /// <param name="staticContext">if set to <c>true</c> [static context].</param>
 /// <param name="isEvent">if set to <c>true</c> [is event].</param>
 /// <returns></returns>
 /// ///
 /// <example>
 /// Unit test that exhibits usage
 /// <code><![CDATA[
 /// string tResult = String.Empty;
 /// var tPoco = new MethOutPoco();
 /// var tBinder =
 /// Binder.InvokeMember(BinderFlags.None, "Func", null, GetType(),
 /// new[]
 /// {
 /// Info.Create(
 /// InfoFlags.None, null),
 /// Info.Create(
 /// InfoFlags.IsOut |
 /// InfoFlags.UseCompileTimeType, null)
 /// });
 /// var tSite = Impromptu.CreateCallSite<DynamicTryString>(tBinder);
 /// tSite.Target.Invoke(tSite, tPoco, out tResult);
 /// Assert.AreEqual("success", tResult);
 /// ]]></code>
 /// </example>
 /// <seealso cref="CreateCallSite"/>
 public static CallSite <T> CreateCallSite <T>(CallSiteBinder binder, String_OR_InvokeMemberName name, Type context,
                                               string[] argNames = null, bool staticContext = false,
                                               bool isEvent      = false) where T : class
 {
     return(InvokeHelper.CreateCallSite <T>(binder.GetType(), InvokeHelper.Unknown, () => binder, name, context, argNames, staticContext,
                                            isEvent));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ImpromptuRelayCommand"/> class.
 /// </summary>
 /// <param name="executeTarget">The execute target.</param>
 /// <param name="executeName">Name of the execute.</param>
 /// <param name="setup">The setup which has the on error event</param>
 public ImpromptuRelayCommand(object executeTarget, String_OR_InvokeMemberName executeName, ISetupViewModel setup =null)
 {
     _executeTarget = executeTarget;
     _setup = setup;
     _executeInvoke = new CacheableInvocation(InvocationKind.InvokeMemberAction, executeName,1);
     _executeInvokeNoArg = new CacheableInvocation(InvocationKind.InvokeMemberAction, executeName, 0); 
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ImpromptuRelayCommand"/> class.
 /// </summary>
 /// <param name="executeTarget">The execute target.</param>
 /// <param name="executeName">Name of the execute method.</param>
 /// <param name="canExecuteTarget">The can execute target.</param>
 /// <param name="canExecuteName">Name of the can execute method.</param>
 public ImpromptuRelayCommand(object executeTarget, String_OR_InvokeMemberName executeName, object canExecuteTarget, String_OR_InvokeMemberName canExecuteName, ISetupViewModel setup = null)
     :this(executeTarget, executeName, setup)
 {
     _canExecuteTarget = canExecuteTarget;
     _canExecuteInvoke = new CacheableInvocation(InvocationKind.InvokeMember, canExecuteName ,1);
     _canExecuteInvokeGet = new CacheableInvocation(InvocationKind.Get,canExecuteName);
     _canExecuteInvokeNoArg = new CacheableInvocation(InvocationKind.InvokeMember, canExecuteName);
 }
Exemple #4
0
        /// <summary>
        /// Dynamically Invokes a member method using the DLR
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="name">The name. Can be a string it will be implicitly converted</param>
        /// <param name="args">The args.</param>
        /// <returns> The result</returns>
        /// <example>
        /// Unit test that exhibits usage:
        /// <code>
        /// <![CDATA[
        ///    dynamic tExpando = new ExpandoObject();
        ///    tExpando.Func = new Func<int, string>(it => it.ToString());
        ///
        ///    var tValue = 1;
        ///    var tOut = Impromptu.InvokeMember(tExpando, "Func", tValue);
        ///
        ///    Assert.AreEqual(tValue.ToString(), tOut);
        /// ]]>
        /// </code>
        /// </example>
        public static dynamic InvokeMember(object target, String_OR_InvokeMemberName name, params object[] args)
        {
            string[] tArgNames;
            Type     tContext;
            bool     tStaticContext;

            target = target.GetTargetContext(out tContext, out tStaticContext);
            args   = Util.GetArgsAndNames(args, out tArgNames);
            CallSite tCallSite = null;

            return(InvokeHelper.InvokeMemberCallSite(target, name, args, tArgNames, tContext, tStaticContext,
                                                     ref tCallSite));
        }
Exemple #5
0
 /// <summary>
 /// Creates a cached call site at runtime.
 /// </summary>
 /// <param name="delegateType">Type of the delegate.</param>
 /// <param name="binder">The CallSite binder.</param>
 /// <param name="name">Member Name</param>
 /// <param name="context">Permissions Context type</param>
 /// <param name="argNames">The arg names.</param>
 /// <param name="staticContext">if set to <c>true</c> [static context].</param>
 /// <param name="isEvent">if set to <c>true</c> [is event].</param>
 /// <returns>The CallSite</returns>
 /// <remarks>
 /// Advanced usage only for serious custom dynamic invocation.
 /// </remarks>
 /// <seealso cref="CreateCallSite{T}"/>
 public static CallSite CreateCallSite(Type delegateType, CallSiteBinder binder, String_OR_InvokeMemberName name,
                                       Type context, string[] argNames = null, bool staticContext = false,
                                       bool isEvent = false)
 {
     return(InvokeHelper.CreateCallSite(delegateType, binder.GetType(), InvokeHelper.Unknown, () => binder, name, context, argNames,
                                        staticContext,
                                        isEvent));
 }
 public ReflexCommandClosure(object target, String_OR_InvokeMemberName invokeName)
 {
     this.target = target;
     this.invoke = new CacheableInvocation(InvocationKind.InvokeMemberAction, invokeName, 1);
     this.invokeNoArg = new CacheableInvocation(InvocationKind.InvokeMemberAction, invokeName, 0);
 }