static void CanUseAnonymous() { dynamic obj = new FluidObject(new { A = 1 }); int i = obj.A; Assert.Equal(1, i); }
static void CanCompare() { dynamic obj = new FluidObject(1); bool equal = obj == 1; Assert.True(equal); }
static void CanGetValue() { dynamic obj = new FluidObject(); obj.A = "1"; var parent = obj.A[FluidObject.Value]; }
static void CanGetParent() { dynamic obj = new FluidObject(); obj.A = "1"; var parent = obj.A[FluidObject.Parent]; }
static void CanChangeType() { dynamic obj = new FluidObject(); obj.A = "1"; obj.A = 1; Assert.IsType <int>(obj.A[FluidObject.Value]); }
static void CanDoBinaryOperations() { dynamic obj = new FluidObject(1); bool b1 = obj == 1; bool b2 = obj != null; Assert.True(b1); Assert.True(b2); }
static void CanAccessDeepMembers() { dynamic obj = new FluidObject(); obj.A = 1; obj.A.B = "1"; Assert.Equal("1", obj.A.B[FluidObject.Value]); }
static void CanGetType() { dynamic obj = new FluidObject(); obj.A = "1"; Type type = obj.A[FluidObject.Type]; Assert.Equal(typeof(string), type); }
static void CanDynamicAccessMembers() { dynamic obj = new FluidObject(); obj.A = "A"; var a = obj["A"]; Assert.Equal("A", a[FluidObject.Value]); }
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); }
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); }
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); }
static void CanUseNotifyPropertyChanged() { dynamic obj = new FluidObject(); var set = false; (obj as INotifyPropertyChanged).PropertyChanged += (s, e) => { set = true; }; obj.Name = "ricardo"; Assert.True(set); }
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); }
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); }
static void CanAccessImmediateMembers() { dynamic obj = new FluidObject(); obj.A = "1"; }