コード例 #1
0
        public void InvokeMethodWithGenericsTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);
            var value    = (int)accessor.GenericMethod <int>(1);

            Assert.AreEqual(1, value);
        }
コード例 #2
0
        public void InvokeMethodWithDerivedParametersTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);
            var value    = (string)accessor.GetObjectString(12345);

            Assert.AreEqual("12345", value);
        }
コード例 #3
0
        public void InvokePrivateMethodTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);
            var value    = (string)accessor.PrivateMethod();

            Assert.AreEqual(DefaultMethodStringValue, value);
        }
コード例 #4
0
        public void InvokeMethodWithParametersTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);
            var value    = (int)accessor.AddMethod(1, 2);

            Assert.AreEqual(3, value);
        }
コード例 #5
0
ファイル: DynamicAccessorImpl.cs プロジェクト: i-kostikov/wpf
 public override DynamicMetaObject FallbackGetIndex(DynamicMetaObject target,
                                                    DynamicMetaObject[] indexes,
                                                    DynamicMetaObject errorSuggestion)
 {
     return(errorSuggestion ??
            TrivialBinderHelper.ThrowExpression(DynamicObjectAccessor.MissingMemberErrorString(target, "Items"), ReturnType));
 }
コード例 #6
0
ファイル: DynamicAccessorImpl.cs プロジェクト: i-kostikov/wpf
 public override DynamicMetaObject FallbackSetMember(DynamicMetaObject target,
                                                     DynamicMetaObject value,
                                                     DynamicMetaObject errorSuggestion)
 {
     return(errorSuggestion ??
            TrivialBinderHelper.ThrowExpression(DynamicObjectAccessor.MissingMemberErrorString(target, Name), ReturnType));
 }
コード例 #7
0
        public void GetThenInvokePublicMethodTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);
            var method   = accessor.PublicMethod;
            var value    = (string)method();

            Assert.AreEqual(DefaultMethodStringValue, value);
        }
コード例 #8
0
        public void InvokeHiddenMethodTest()
        {
            // This should only invoke the first method going down the types
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);
            var value    = (string)accessor.HiddenMethod();

            Assert.AreEqual(DefaultMethodStringValue, value);
        }
コード例 #9
0
        public void CastReturnToConvertableTypeTest()
        {
            var accessor         = DynamicObjectAccessor.Create(new TestClass(), true);
            var publicField      = accessor.PublicTestInt;
            var publicFieldValue = (long)publicField;

            Assert.IsNotNull(publicFieldValue);
        }
コード例 #10
0
        public void AccessPublicPropertyTest()
        {
            var accessor            = DynamicObjectAccessor.Create(new TestClass(), true);
            var publicProperty      = accessor.PublicProperty;
            var publicPropertyValue = (string)publicProperty;

            Assert.IsNotNull(publicProperty);
            Assert.AreEqual(PublicPropertyStringValue, publicPropertyValue);
        }
コード例 #11
0
        public void TestPropertyNullAssigning()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            accessor.TestProperty = null;
            var newPropertyValue = (string)accessor.TestProperty;

            Assert.AreEqual(null, newPropertyValue);
        }
コード例 #12
0
        public void GetByMultiIndexTest()
        {
            var accessor               = DynamicObjectAccessor.Create(new TestClass(), true);
            var privateClassField      = accessor["PublicTestObject", "PrivateClassString"];
            var privateClassFieldValue = (string)privateClassField;

            Assert.IsNotNull(privateClassField);
            Assert.AreEqual(PrivateFieldStringValue, privateClassFieldValue);
        }
コード例 #13
0
        public void GetByIndexTest()
        {
            var accessor         = DynamicObjectAccessor.Create(new TestClass(), true);
            var publicField      = accessor["PublicTestObject"];
            var publicFieldValue = (AccessorMemberTests.A)publicField;

            Assert.IsNotNull(publicFieldValue);
            Assert.IsTrue(publicFieldValue is AccessorMemberTests.A);
        }
コード例 #14
0
        public void CastReturnToBaseTypeTest()
        {
            var accessor         = DynamicObjectAccessor.Create(new TestClass(), true);
            var publicField      = accessor.PublicTestObject;
            var publicFieldValue = (AccessorMemberTests.A)publicField;

            Assert.IsNotNull(publicFieldValue);
            Assert.IsTrue(publicFieldValue is AccessorMemberTests.A);
        }
コード例 #15
0
        public void AccessPrivateFieldTest()
        {
            var accessor          = DynamicObjectAccessor.Create(new TestClass(), true);
            var privateField      = accessor.PrivateField;
            var privateFieldValue = (string)privateField;

            Assert.IsNotNull(privateField);
            Assert.AreEqual(PrivateFieldStringValue, privateFieldValue);
        }
コード例 #16
0
        public void TestFieldNullAssigning()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            accessor.TestField = null;
            var newFieldValue = (string)accessor.TestField;

            Assert.AreEqual(null, newFieldValue);
        }
コード例 #17
0
        public void SetByMultiIndexTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            accessor["Child", "PublicStringField"] = TestStringValue;
            var newFieldValue = (string)accessor.Child.PublicStringField;

            Assert.AreEqual(TestStringValue, newFieldValue);
        }
コード例 #18
0
        public void AccessPrivateFieldOnBaseClassTest()
        {
            var accessor = DynamicObjectAccessor.Create(new B(), true);
            var privateBaseClassProperty      = accessor.PrivateBaseClassString;
            var privateBaseClassPropertyValue = (string)privateBaseClassProperty;

            Assert.IsNotNull(privateBaseClassProperty);
            Assert.AreEqual(PrivateFieldStringValue, privateBaseClassPropertyValue);
        }
コード例 #19
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="BindingMemberInfo" /> class.
        /// </summary>
        public BindingMemberInfo(string path)
            : this(path, BindingMemberType.Dynamic, typeof(object))
        {
            var accessor = new DynamicObjectAccessor(path);

            _getValueAccessor = accessor.GetValue;
            _setValueAccessor = accessor.SetValue;
            _canRead          = true;
            _canWrite         = true;
        }
コード例 #20
0
        public void AccessHiddenFieldTest()
        {
            var accessor       = DynamicObjectAccessor.Create(new B(), true);
            var accessorHidden = DynamicObjectAccessor.Create(new B(), true, typeof(A));

            var privateFieldValue       = (string)accessor.HiddenStringField;
            var hiddenPrivateFieldValue = (string)accessorHidden.HiddenStringField;

            Assert.AreEqual(privateFieldValue, string.Empty);
            Assert.AreEqual(hiddenPrivateFieldValue, PrivateFieldStringValue);
        }
コード例 #21
0
 public BindingMemberInfo(string path, bool expandoObject)
     : this(path, BindingMemberType.Dynamic, typeof(object))
 {
     object[] indexerValues = null;
     if (expandoObject)
     {
         _isSingleParameter      = true;
         _getValueAccessorSingle = o =>
         {
             object value;
             ((IDictionary <string, object>)o).TryGetValue(path, out value);
             return(value);
         };
         _setValueAccessorSingleAction = (o, v) => ((IDictionary <string, object>)o)[path] = v;
     }
     else
     {
         if (path.StartsWith("[", StringComparison.Ordinal) || path.StartsWith("Item[", StringComparison.Ordinal))
         {
             indexerValues = BindingReflectionExtensions.GetIndexerValues(path, castType: typeof(string));
         }
         var accessor = new DynamicObjectAccessor(path, indexerValues);
         if (indexerValues == null)
         {
             _getValueAccessor = accessor.GetValue;
             _setValueAccessor = accessor.SetValue;
         }
         else
         {
             _getValueAccessor = accessor.GetValueIndex;
             _setValueAccessor = accessor.SetValueIndex;
         }
         _isDynamic  = true;
         _canObserve = true;
     }
     _canRead  = true;
     _canWrite = true;
 }
コード例 #22
0
        // Token: 0x060007AC RID: 1964 RVA: 0x00017DB4 File Offset: 0x00015FB4
        internal static void DowncastAccessor(object accessor, out DependencyProperty dp, out PropertyInfo pi, out PropertyDescriptor pd, out DynamicObjectAccessor doa)
        {
            DependencyProperty dependencyProperty;

            dp = (dependencyProperty = (accessor as DependencyProperty));
            if (dependencyProperty != null)
            {
                pd  = null;
                pi  = null;
                doa = null;
                return;
            }
            PropertyInfo left;

            pi = (left = (accessor as PropertyInfo));
            if (left != null)
            {
                pd  = null;
                doa = null;
                return;
            }
            PropertyDescriptor propertyDescriptor;

            pd = (propertyDescriptor = (accessor as PropertyDescriptor));
            if (propertyDescriptor != null)
            {
                doa = null;
                return;
            }
            doa = (accessor as DynamicObjectAccessor);
        }
コード例 #23
0
 public BindingMemberInfo(string path, bool expandoObject)
     : this(path, BindingMemberType.Dynamic, typeof(object))
 {
     object[] indexerValues = null;
     if (expandoObject)
     {
         _isSingleParameter = true;
         _getValueAccessorSingle = o =>
         {
             object value;
             ((IDictionary<string, object>)o).TryGetValue(path, out value);
             return value;
         };
         _setValueAccessorSingleAction = (o, v) => ((IDictionary<string, object>)o)[path] = v;
     }
     else
     {
         if (path.StartsWith("Item[", StringComparison.Ordinal) || path.StartsWith("[", StringComparison.Ordinal))
             indexerValues = BindingReflectionExtensions.GetIndexerValues(path, castType: typeof(string));
         var accessor = new DynamicObjectAccessor(path, indexerValues);
         if (indexerValues == null)
         {
             _getValueAccessor = accessor.GetValue;
             _setValueAccessor = accessor.SetValue;
         }
         else
         {
             _getValueAccessor = accessor.GetValueIndex;
             _setValueAccessor = accessor.SetValueIndex;
         }
         _isDynamic = true;
         _canObserve = true;
     }
     _canRead = true;
     _canWrite = true;
 }
コード例 #24
0
        public void AccessInvalidIndexTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            Assert.ThrowsException <RuntimeBinderException>(() => accessor["PropertyThatDoesNotExist"]);
        }
コード例 #25
0
        public void AccessUsingInvalidIndexType()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            Assert.ThrowsException <RuntimeBinderException>(() => accessor[42]);
        }
コード例 #26
0
        public void AccessStaticFieldTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            Assert.ThrowsException <RuntimeBinderException>(() => accessor.StaticField);
        }
コード例 #27
0
        public void TestThrowOnInvalidTypeAssign()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            Assert.ThrowsException <RuntimeBinderException>(() => accessor.TestField = 42);
        }
コード例 #28
0
        public void InvokeMethodWithInvalidParametersTest()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            Assert.ThrowsException <RuntimeBinderException>(() => accessor.AddMethod("1", "2"));
        }
コード例 #29
0
        public void TestThrowOnNullAssignOnvalueType()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            Assert.ThrowsException <RuntimeBinderException>(() => accessor.TestValueField = null);
        }
コード例 #30
0
        //------------------------------------------------------
        //
        //  Internal methods
        //
        //------------------------------------------------------

        // Convert an "accessor" into one of the legal types
        internal static void DowncastAccessor(object accessor,
                                              out DependencyProperty dp, out PropertyInfo pi, out PropertyDescriptor pd, out DynamicObjectAccessor doa)
        {
            if ((dp = accessor as DependencyProperty) != null)
            {
                pd  = null;
                pi  = null;
                doa = null;
            }
            else if ((pi = accessor as PropertyInfo) != null)
            {
                pd  = null;
                doa = null;
            }
            else if ((pd = accessor as PropertyDescriptor) != null)
            {
                doa = null;
            }
            else
            {
                doa = accessor as DynamicObjectAccessor;
            }
        }
コード例 #31
0
        public void TestThrowOnGetProperty()
        {
            var accessor = DynamicObjectAccessor.Create(new TestClass(), true);

            Assert.ThrowsException <RuntimeBinderException>(() => accessor.TestGetOnlyProperty = TestStringValue);
        }