Пример #1
0
        static void CanUseAnonymous()
        {
            dynamic obj = new FluidObject(new { A = 1 });
            int     i   = obj.A;

            Assert.Equal(1, i);
        }
Пример #2
0
        static void CanCompare()
        {
            dynamic obj   = new FluidObject(1);
            bool    equal = obj == 1;

            Assert.True(equal);
        }
Пример #3
0
        static void CanGetValue()
        {
            dynamic obj = new FluidObject();

            obj.A = "1";

            var parent = obj.A[FluidObject.Value];
        }
Пример #4
0
        static void CanGetParent()
        {
            dynamic obj = new FluidObject();

            obj.A = "1";

            var parent = obj.A[FluidObject.Parent];
        }
Пример #5
0
        static void CanChangeType()
        {
            dynamic obj = new FluidObject();

            obj.A = "1";
            obj.A = 1;

            Assert.IsType <int>(obj.A[FluidObject.Value]);
        }
Пример #6
0
        static void CanDoBinaryOperations()
        {
            dynamic obj = new FluidObject(1);
            bool    b1  = obj == 1;
            bool    b2  = obj != null;

            Assert.True(b1);
            Assert.True(b2);
        }
Пример #7
0
        static void CanAccessDeepMembers()
        {
            dynamic obj = new FluidObject();

            obj.A   = 1;
            obj.A.B = "1";

            Assert.Equal("1", obj.A.B[FluidObject.Value]);
        }
Пример #8
0
        static void CanGetType()
        {
            dynamic obj = new FluidObject();

            obj.A = "1";

            Type type = obj.A[FluidObject.Type];

            Assert.Equal(typeof(string), type);
        }
Пример #9
0
        static void CanDynamicAccessMembers()
        {
            dynamic obj = new FluidObject();

            obj.A = "A";

            var a = obj["A"];

            Assert.Equal("A", a[FluidObject.Value]);
        }
Пример #10
0
        static void CanGetRoot()
        {
            dynamic obj = new FluidObject();

            obj.A   = "1";
            obj.A.B = 0;

            var root = obj.A.B[FluidObject.Root];

            Assert.Equal(obj, root);
        }
Пример #11
0
        static void CanGetPath()
        {
            dynamic obj = new FluidObject();

            obj.A   = "1";
            obj.A.B = 0;

            var path = obj.A.B[FluidObject.Path];

            Assert.Equal("A.B", path);
        }
Пример #12
0
        static void CanDoUnaryOperations()
        {
            dynamic obj  = new FluidObject(1);
            int     n    = ~obj;
            int     prei = ++obj;
            int     pred = --obj;
            int     posi = obj++;
            int     posd = obj--;

            Assert.Equal(2, posd);
        }
Пример #13
0
        static void CanUseNotifyPropertyChanged()
        {
            dynamic obj = new FluidObject();
            var     set = false;

            (obj as INotifyPropertyChanged).PropertyChanged += (s, e) =>
            {
                set = true;
            };

            obj.Name = "ricardo";

            Assert.True(set);
        }
Пример #14
0
        static void CanUseTypeDescriptor()
        {
            dynamic obj = new FluidObject();

            obj.Name = "ricardo";
            var    provider   = TypeDescriptor.GetProvider(obj) as TypeDescriptionProvider;
            var    descriptor = provider.GetTypeDescriptor(obj) as ICustomTypeDescriptor;
            var    converter  = descriptor.GetConverter() as TypeConverter;
            var    attrs      = TypeDescriptor.GetAttributes(obj);
            var    props      = TypeDescriptor.GetProperties(obj) as PropertyDescriptorCollection;
            var    prop       = props["Name"] as PropertyDescriptor;
            string value      = (string)prop.GetValue(obj);

            Assert.Equal("ricardo", value);
        }
Пример #15
0
        static void CanConvert()
        {
            dynamic   obj = new FluidObject(1);
            int       i   = obj;
            float     f   = obj;
            string    s   = obj;
            DayOfWeek dow = obj;
            decimal   d   = obj;
            bool      b   = obj;

            Assert.Equal(1, i);
            Assert.Equal(1f, i);
            Assert.Equal("1", s);
            Assert.Equal(DayOfWeek.Monday, dow);
            Assert.Equal(1m, d);
            Assert.Equal(true, b);
        }
Пример #16
0
        static void CanAccessImmediateMembers()
        {
            dynamic obj = new FluidObject();

            obj.A = "1";
        }