/// <summary>
        /// Executes the future queries.
        /// </summary>
        /// <param name="context">The <see cref="ObjectContext"/> to run the queries against.</param>
        /// <param name="futureQueries">The future queries list.</param>
        public void ExecuteFutureQueries(ObjectContext context, IList<IFutureQuery> futureQueries)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            if (futureQueries == null)
                throw new ArgumentNullException("futureQueries");

            // used to call internal methods
            dynamic contextProxy = new DynamicProxy(context);
            contextProxy.EnsureConnection();

            try
            {
                using (var command = CreateFutureCommand(context, futureQueries))
                using (var reader = command.ExecuteReader())
                {
                    foreach (var futureQuery in futureQueries)
                    {
                        futureQuery.SetResult(context, reader);
                        reader.NextResult();
                    }
                }
            }
            finally
            {
                contextProxy.ReleaseConnection();
                // once all queries processed, clear from queue
                futureQueries.Clear();
            }
        }
    public void TestMethodNulls()
    {
      var t = new TestWrapper();
      dynamic w = new DynamicProxy(t);

      string r = w.EchoInternal(null);
      Assert.AreEqual("Internal: ", r);

      r = w.EchoInternal2(1);
      Assert.AreEqual("Int: 1", r);
      r = w.EchoInternal2("Test");
      Assert.AreEqual("String: Test", r);

      r = w.EchoInternal2("Test", "Testing");
      Assert.AreEqual("Name: Test Value: Testing", r);

      r = w.EchoInternal2("Test", null);
      Assert.AreEqual("Name: Test Value: ", r);


      r = w.EchoInternal3("Test", "Testing", null);
      Assert.AreEqual("Name: Test Value: Testing Value2: ", r);

      r = w.EchoInternal3("Test", 1, null);
      Assert.AreEqual("Name: Test Value: 1 Value2: ", r);

    }
    public void TestMethod()
    {
      var t = new TestWrapper();
      dynamic w = new DynamicProxy(t);

      string r = w.Name;
      Assert.AreEqual("Test", r);

      r = w.Internal;
      Assert.AreEqual("InternalTest", r);

      r = w.Private;
      Assert.AreEqual("PrivateTest", r);

      r = w.EchoPublic("Tester");
      Assert.AreEqual("Public: Tester", r);

      r = w.EchoPrivate("Tester");
      Assert.AreEqual("Private: Tester", r);

      r = w.EchoInternal("Tester");
      Assert.AreEqual("Internal: Tester", r);

      r = w.EchoInternal(null);
      Assert.AreEqual("Internal: ", r);

    }
Пример #4
0
        /// <summary>
        /// Provides the implementation for operations that get member values. Classes derived from the <see cref="T:System.Dynamic.DynamicObject"/> class can override this method to specify dynamic behavior for operations such as getting a value for a property.
        /// </summary>
        /// <param name="binder">Provides information about the object that called the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the Console.WriteLine(sampleObject.SampleProperty) statement, where sampleObject is an instance of the class derived from the <see cref="T:System.Dynamic.DynamicObject"/> class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.</param>
        /// <param name="result">The result of the get operation. For example, if the method is called for a property, you can assign the property value to <paramref name="result"/>.</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 run-time exception is thrown.)
        /// </returns>
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = null;

            var memeber = _typeAccessor.Find(binder.Name, _flags);

            if (memeber == null)
            {
                return(SafeMode);
            }

            if (!memeber.HasGetter)
            {
                return(SafeMode);
            }

            var value = memeber.GetValue(_wrapped);

            if (value == null)
            {
                return(true);
            }

            result = new DynamicProxy(value, SafeMode);
            return(true);
        }
    /// <summary>
    /// Provides the implementation for operations that invoke a member. Classes derived from the <see cref="T:System.Dynamic.DynamicObject"/> class can override this method to specify dynamic behavior for operations such as calling a method.
    /// </summary>
    /// <param name="binder">Provides information about the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is an instance of the class derived from the <see cref="T:System.Dynamic.DynamicObject"/> class, binder.Name returns "SampleMethod". The binder.IgnoreCase property specifies whether the member name is case-sensitive.</param>
    /// <param name="args">The arguments that are passed to the object member during the invoke operation. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is derived from the <see cref="T:System.Dynamic.DynamicObject"/> class, args[0] is equal to 100.</param>
    /// <param name="result">The result of the member 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>
    public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
    {
      result = null;
      
      var types = args.Select(a => a == null ? typeof(object) : a.GetType()).ToArray();
      var method = _typeAccessor.FindMethod(binder.Name, types, _flags);

      if (method == null)
        return SafeMode;

      var value = method.Invoke(_wrapped, args);
      if (value == null)
        return true;

      result = new DynamicProxy(value, SafeMode);
      return true;
    }
        /// <summary>
        /// Provides the implementation for operations that invoke a member. Classes derived from the <see cref="T:System.Dynamic.DynamicObject"/> class can override this method to specify dynamic behavior for operations such as calling a method.
        /// </summary>
        /// <param name="binder">Provides information about the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is an instance of the class derived from the <see cref="T:System.Dynamic.DynamicObject"/> class, binder.Name returns "SampleMethod". The binder.IgnoreCase property specifies whether the member name is case-sensitive.</param>
        /// <param name="args">The arguments that are passed to the object member during the invoke operation. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is derived from the <see cref="T:System.Dynamic.DynamicObject"/> class, args[0] is equal to 100.</param>
        /// <param name="result">The result of the member 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>
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            result = null;

            var types  = args.Select(a => a == null ? typeof(object) : a.GetType()).ToArray();
            var method = _typeAccessor.FindMethod(binder.Name, types, _flags);

            if (method == null)
            {
                return(SafeMode);
            }

            var value = method.Invoke(_wrapped, args);

            if (value == null)
            {
                return(true);
            }

            result = new DynamicProxy(value, SafeMode);
            return(true);
        }
    /// <summary>
    /// Provides the implementation for operations that get member values. Classes derived from the <see cref="T:System.Dynamic.DynamicObject"/> class can override this method to specify dynamic behavior for operations such as getting a value for a property.
    /// </summary>
    /// <param name="binder">Provides information about the object that called the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the Console.WriteLine(sampleObject.SampleProperty) statement, where sampleObject is an instance of the class derived from the <see cref="T:System.Dynamic.DynamicObject"/> class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.</param>
    /// <param name="result">The result of the get operation. For example, if the method is called for a property, you can assign the property value to <paramref name="result"/>.</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 run-time exception is thrown.)
    /// </returns>
    public override bool TryGetMember(GetMemberBinder binder, out object result)
    {
      result = null;

      var memeber = _typeAccessor.Find(binder.Name, _flags);
      if (memeber == null)
        return SafeMode;

      if (!memeber.HasGetter)
        return SafeMode;

      var value = memeber.GetValue(_wrapped);
      if (value == null)
        return true;

      result = new DynamicProxy(value, SafeMode);      
      return true;
    }