예제 #1
0
        public void IndexGetAndRetrieve()
        {
            dynamic d = new IndexableObject();

            d[23] = 42;
            Assert.Equal(42, d[23]);
            d[1, 2] = "Hello";
            Assert.Equal("Hello", d[1, 2]);
            Assert.Throws <KeyNotFoundException>(() => d[1]);
            Assert.Throws <KeyNotFoundException>(() => d[2, 3]);
            Assert.Throws <RuntimeBinderException>(() => d[2]    = "Test");
            Assert.Throws <RuntimeBinderException>(() => d[2, 4] = 1);
            Assert.Throws <RuntimeBinderException>(() => d["index"]);
            Assert.Throws <RuntimeBinderException>(() => d["index"] = 2);
            Assert.Throws <RuntimeBinderException>(() =>
            {
                string val = d[23];
            });
            Assert.Throws <RuntimeBinderException>(() =>
            {
                int val = d[1, 2];
            });
            Assert.Throws <RuntimeBinderException>(() => d[1, 2, 3]);
        }
예제 #2
0
 public void IndexGetAndRetrieve()
 {
     dynamic d = new IndexableObject();
     d[23] = 42;
     Assert.Equal(42, d[23]);
     d[1, 2] = "Hello";
     Assert.Equal("Hello", d[1, 2]);
     Assert.Throws<KeyNotFoundException>(() => d[1]);
     Assert.Throws<KeyNotFoundException>(() => d[2, 3]);
     Assert.Throws<RuntimeBinderException>(() => d[2] = "Test");
     Assert.Throws<RuntimeBinderException>(() => d[2, 4] = 1);
     Assert.Throws<RuntimeBinderException>(() => d["index"]);
     Assert.Throws<RuntimeBinderException>(() => d["index"] = 2);
     Assert.Throws<RuntimeBinderException>(() =>
     {
         string val = d[23];
     });
     Assert.Throws<RuntimeBinderException>(() =>
     {
         int val = d[1, 2];
     });
     Assert.Throws<RuntimeBinderException>(() => d[1, 2, 3]);
 }