public void GetPropertyValue() { var propertyOrFieldReflection = new ClassToAnalyze(1, 1, 1).Reflection().GetPropertyOrField("PrivateProperty"); var value = propertyOrFieldReflection.GetValue <string>(); value.Should().Be("PrivateProperty"); }
public void InvokeGeneric() { var methodReflection = new ClassToAnalyze(1, 1, 1).Reflection().GetMethod("GenericMethod"); var returnValue = methodReflection.InvokeGeneric(new Type[] { typeof(object) }); returnValue.Should().BeNull(); }
public void GetEnclosingType() { var propertyOrFieldReflection = new ClassToAnalyze(1, 1, 1).Reflection().GetPropertyOrField("_privateField"); var result = propertyOrFieldReflection.GetEnclosingType <ClassToAnalyze>(); result.Should().NotBeNull(); }
public void InvokeMethod() { var methodReflection = new ClassToAnalyze(1, 1, 1).Reflection().GetMethod("PrivateMethod"); var returnValue = methodReflection.Invoke(1); returnValue.Should().BeNull(); }
public void SetFieldValue() { var propertyOrFieldReflection = new ClassToAnalyze(1, 1, 1).Reflection().GetPropertyOrField("_privateField"); propertyOrFieldReflection.SetValue("test"); var value = propertyOrFieldReflection.GetValue <string>(); value.Should().Be("test"); }
public void InvokeGenericOnNonGenericMethod() { var methodReflection = new ClassToAnalyze(1, 1, 1).Reflection().GetMethod("PrivateMethod"); methodReflection .Invoking(x => x.InvokeGeneric(new Type[] { typeof(object) })) .Should() .Throw <InvalidOperationException>(); }
public void InvokeOnGenericMethodThrowsException() { var methodReflection = new ClassToAnalyze(1, 1, 1).Reflection().GetMethod("GenericMethod"); methodReflection .Invoking(x => x.Invoke()) .Should() .Throw <InvalidOperationException>(); }
public void SetPropertyOrField() { var methodReflection = new ClassToAnalyze(1, 1, 1).Reflection(); methodReflection.SetPropertyOrField("_privateField", "test"); var newValue = methodReflection.GetPropertyOrField("_privateField").GetValue <string>(); newValue.Should().Be("test"); }