public void Ctor() { var first = ReflectData .GetProperties() .FirstOrDefault(); var reflect = new ReflectionProperty(first); assert.Equal(first.Name, reflect.Name); assert.Equal(first.PropertyType, reflect.ClrType); assert.Equal(true, reflect.CanRead); assert.Equal(true, reflect.CanWrite); var mods = reflect.GetterAccess; assert.Equal(true, mods.IsPublic); assert.Equal(false, mods.IsPrivate); assert.Equal(false, mods.IsInternal); assert.Equal(false, mods.IsVirtual); assert.Equal(false, mods.IsStatic); assert.Equal(true, mods.IsInstance); mods = reflect.SetterAccess; assert.Equal(true, mods.IsPublic); assert.Equal(false, mods.IsPrivate); assert.Equal(false, mods.IsInternal); assert.Equal(false, mods.IsVirtual); assert.Equal(false, mods.IsStatic); assert.Equal(true, mods.IsInstance); }
public void FindAttribute() { var first = ReflectData.GetMethod(); var reflect = new ReflectionMethod(first, new ReflectionFactory()); var attr = reflect.FindAttribute <DecoratorAttribute>(); assert.NotNull(attr); }
public void FindAttributes() { var first = ReflectData.GetMethod(); var reflect = new ReflectionMethod(first, new ReflectionFactory()); var attrs = reflect.FindAttributes <DecoratorAttribute>(); assert.NotNull(attrs); assert.Equal(1, attrs.Count); }
public void FindAttribute() { var first = ReflectData .GetParameters("GetUser") .FirstOrDefault(); var reflectionParameter = new ReflectionParameter(first); var attr = reflectionParameter.FindAttribute <DecoratorAttribute>(); assert.NotNull(attr); }
public void Invoke() { var first = ReflectData.GetMethod(); var reflect = new ReflectionMethod(first, new ReflectionFactory()); var data = new ReflectData(); var result = reflect.Invoke(data, "first", "last", DateTime.UtcNow); assert.NotNull(result); assert.IsType <string>(result); assert.Equal("Mike Tyson", result.ToString()); }
public void FindAttribute() { var first = ReflectData .GetProperties() .FirstOrDefault(); var reflect = new ReflectionProperty(first); var attr = reflect.FindAttribute <DecoratorAttribute>(); assert.NotNull(attr); }
public void FindAttributes() { var first = ReflectData .GetProperties() .FirstOrDefault(); var reflect = new ReflectionProperty(first); var attrs = reflect.FindAttributes <DecoratorAttribute>(); assert.NotNull(attrs); assert.Equal(1, attrs.Count); }
public void FindAttributes() { var first = ReflectData .GetParameters("GetUser") .FirstOrDefault(); var reflectionParameter = new ReflectionParameter(first); var attrs = reflectionParameter.FindAttributes <DecoratorAttribute>(); assert.NotNull(attrs); assert.Equal(1, attrs.Count); }
public void Ctor_ThrowsArgumentNull() { assert.Throws <ArgumentNullException>(() => { _ = new ReflectionMethod(null, null); }); assert.Throws <ArgumentNullException>(() => { var method = ReflectData.GetMethod(); _ = new ReflectionMethod(method, null); }); }
public void Private_GetValue() { var first = typeof(ReflectData).GetProperty( "Field4", BindingFlags.NonPublic | BindingFlags.Instance); assert.NotNull(first); var reflect = new ReflectionProperty(first); var data = new ReflectData(); assert.Equal(10, (int)reflect.GetValue(data)); }
public void GetValue() { var first = ReflectData .GetProperties() .FirstOrDefault(); var reflect = new ReflectionProperty(first); var data = new ReflectData() { Field2 = true }; assert.Ok((bool)reflect.GetValue(data)); }
public void Ctor() { var first = ReflectData .GetParameters("GetUser") .FirstOrDefault(); var reflectionParameter = new ReflectionParameter(first); assert.Equal(first.Name, reflectionParameter.Name); assert.Equal(first.ParameterType, reflectionParameter.ClrType); assert.Equal(first.Position, reflectionParameter.Position); assert.Equal(first.IsOut, reflectionParameter.IsOut); assert.Equal(first.IsOptional, reflectionParameter.IsOptional); assert.Equal(first.DefaultValue, reflectionParameter.DefaultValue); assert.NotNull(reflectionParameter.Attributes); }
/// <exception cref="System.Exception"/> public static void TestReflect(object value, Type type, string schema) { // check that schema matches expected Schema s = ((ReflectData)ReflectData.Get()).GetSchema(type); Assert.Equal(Schema.Parse(schema), s); // check that value is serialized correctly ReflectDatumWriter <object> writer = new ReflectDatumWriter <object>(s); ByteArrayOutputStream @out = new ByteArrayOutputStream(); writer.Write(value, EncoderFactory.Get().DirectBinaryEncoder(@out, null)); ReflectDatumReader <object> reader = new ReflectDatumReader <object>(s); object after = reader.Read(null, DecoderFactory.Get().BinaryDecoder(@out.ToByteArray (), null)); Assert.Equal(value, after); }
public void SetValue() { var first = ReflectData .GetProperties() .FirstOrDefault(); var reflect = new ReflectionProperty(first); var data = new ReflectData() { Field2 = true }; assert.True(data.Field2); reflect.SetValue(data, false); assert.False(data.Field2); }
public void Ctor() { var first = ReflectData .GetFields() .FirstOrDefault(); var reflectionField = new ReflectionField(first); assert.Equal(first.Name, reflectionField.Name); assert.Equal(first.FieldType, reflectionField.ClrType); assert.Equal(true, reflectionField.CanWrite); assert.Equal(true, reflectionField.CanRead); var mods = reflectionField.ModifierAccess; assert.Equal(true, mods.IsPublic); assert.Equal(false, mods.IsPrivate); assert.Equal(false, mods.IsInternal); assert.Equal(false, mods.IsVirtual); assert.Equal(false, mods.IsStatic); assert.Equal(true, mods.IsInstance); }
public void Ctor() { var first = ReflectData.GetMethod(); var reflect = new ReflectionMethod( first, new ReflectionFactory()); assert.Equal(first.Name, reflect.Name); assert.Equal(first.DeclaringType, reflect.ClrType); assert.Equal(first.ReturnParameter, reflect.ReturnParameter.ParameterInfo); assert.Equal(false, reflect.IsGenericMethodDefinition); assert.Equal(0, reflect.GenericArguments.Count); var mods = reflect.ModifierAccess; assert.Equal(true, mods.IsPublic); assert.Equal(false, mods.IsPrivate); assert.Equal(false, mods.IsInternal); assert.Equal(false, mods.IsVirtual); assert.Equal(false, mods.IsStatic); assert.Equal(true, mods.IsInstance); }
public override Schema GetSchema(object t) { return(((ReflectData)ReflectData.Get()).GetSchema(t.GetType())); }