public void InvokeMethodWithGenericsTest() { var accessor = DynamicObjectAccessor.Create(new TestClass(), true); var value = (int)accessor.GenericMethod <int>(1); Assert.AreEqual(1, value); }
public void InvokeMethodWithDerivedParametersTest() { var accessor = DynamicObjectAccessor.Create(new TestClass(), true); var value = (string)accessor.GetObjectString(12345); Assert.AreEqual("12345", value); }
public void InvokePrivateMethodTest() { var accessor = DynamicObjectAccessor.Create(new TestClass(), true); var value = (string)accessor.PrivateMethod(); Assert.AreEqual(DefaultMethodStringValue, value); }
public void InvokeMethodWithParametersTest() { var accessor = DynamicObjectAccessor.Create(new TestClass(), true); var value = (int)accessor.AddMethod(1, 2); Assert.AreEqual(3, value); }
public override DynamicMetaObject FallbackGetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject errorSuggestion) { return(errorSuggestion ?? TrivialBinderHelper.ThrowExpression(DynamicObjectAccessor.MissingMemberErrorString(target, "Items"), ReturnType)); }
public override DynamicMetaObject FallbackSetMember(DynamicMetaObject target, DynamicMetaObject value, DynamicMetaObject errorSuggestion) { return(errorSuggestion ?? TrivialBinderHelper.ThrowExpression(DynamicObjectAccessor.MissingMemberErrorString(target, Name), ReturnType)); }
public void GetThenInvokePublicMethodTest() { var accessor = DynamicObjectAccessor.Create(new TestClass(), true); var method = accessor.PublicMethod; var value = (string)method(); Assert.AreEqual(DefaultMethodStringValue, value); }
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); }
public void CastReturnToConvertableTypeTest() { var accessor = DynamicObjectAccessor.Create(new TestClass(), true); var publicField = accessor.PublicTestInt; var publicFieldValue = (long)publicField; Assert.IsNotNull(publicFieldValue); }
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); }
public void TestPropertyNullAssigning() { var accessor = DynamicObjectAccessor.Create(new TestClass(), true); accessor.TestProperty = null; var newPropertyValue = (string)accessor.TestProperty; Assert.AreEqual(null, newPropertyValue); }
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); }
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); }
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); }
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); }
public void TestFieldNullAssigning() { var accessor = DynamicObjectAccessor.Create(new TestClass(), true); accessor.TestField = null; var newFieldValue = (string)accessor.TestField; Assert.AreEqual(null, newFieldValue); }
public void SetByMultiIndexTest() { var accessor = DynamicObjectAccessor.Create(new TestClass(), true); accessor["Child", "PublicStringField"] = TestStringValue; var newFieldValue = (string)accessor.Child.PublicStringField; Assert.AreEqual(TestStringValue, newFieldValue); }
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); }
/// <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; }
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); }
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; }
// 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); }
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; }
public void AccessInvalidIndexTest() { var accessor = DynamicObjectAccessor.Create(new TestClass(), true); Assert.ThrowsException <RuntimeBinderException>(() => accessor["PropertyThatDoesNotExist"]); }
public void AccessUsingInvalidIndexType() { var accessor = DynamicObjectAccessor.Create(new TestClass(), true); Assert.ThrowsException <RuntimeBinderException>(() => accessor[42]); }
public void AccessStaticFieldTest() { var accessor = DynamicObjectAccessor.Create(new TestClass(), true); Assert.ThrowsException <RuntimeBinderException>(() => accessor.StaticField); }
public void TestThrowOnInvalidTypeAssign() { var accessor = DynamicObjectAccessor.Create(new TestClass(), true); Assert.ThrowsException <RuntimeBinderException>(() => accessor.TestField = 42); }
public void InvokeMethodWithInvalidParametersTest() { var accessor = DynamicObjectAccessor.Create(new TestClass(), true); Assert.ThrowsException <RuntimeBinderException>(() => accessor.AddMethod("1", "2")); }
public void TestThrowOnNullAssignOnvalueType() { var accessor = DynamicObjectAccessor.Create(new TestClass(), true); Assert.ThrowsException <RuntimeBinderException>(() => accessor.TestValueField = null); }
//------------------------------------------------------ // // 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; } }
public void TestThrowOnGetProperty() { var accessor = DynamicObjectAccessor.Create(new TestClass(), true); Assert.ThrowsException <RuntimeBinderException>(() => accessor.TestGetOnlyProperty = TestStringValue); }