コード例 #1
0
    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);
    }
コード例 #2
0
    public void FindAttribute()
    {
        var first   = ReflectData.GetMethod();
        var reflect = new ReflectionMethod(first, new ReflectionFactory());

        var attr = reflect.FindAttribute <DecoratorAttribute>();

        assert.NotNull(attr);
    }
コード例 #3
0
    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);
    }
コード例 #4
0
    public void FindAttribute()
    {
        var first = ReflectData
                    .GetParameters("GetUser")
                    .FirstOrDefault();
        var reflectionParameter = new ReflectionParameter(first);

        var attr = reflectionParameter.FindAttribute <DecoratorAttribute>();

        assert.NotNull(attr);
    }
コード例 #5
0
    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());
    }
コード例 #6
0
    public void FindAttribute()
    {
        var first = ReflectData
                    .GetProperties()
                    .FirstOrDefault();
        var reflect = new ReflectionProperty(first);

        var attr = reflect.FindAttribute <DecoratorAttribute>();

        assert.NotNull(attr);
    }
コード例 #7
0
    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);
    }
コード例 #8
0
    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);
    }
コード例 #9
0
    public void Ctor_ThrowsArgumentNull()
    {
        assert.Throws <ArgumentNullException>(() =>
        {
            _ = new ReflectionMethod(null, null);
        });

        assert.Throws <ArgumentNullException>(() =>
        {
            var method = ReflectData.GetMethod();
            _          = new ReflectionMethod(method, null);
        });
    }
コード例 #10
0
    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));
    }
コード例 #11
0
    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));
    }
コード例 #12
0
    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);
    }
コード例 #13
0
        /// <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);
        }
コード例 #14
0
    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);
    }
コード例 #15
0
    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);
    }
コード例 #16
0
    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);
    }
コード例 #17
0
 public override Schema GetSchema(object t)
 {
     return(((ReflectData)ReflectData.Get()).GetSchema(t.GetType()));
 }