Пример #1
0
        public void TryViewOfGuardedListAsSCIList1()
        {
            B             b1_ = new B(), b2_ = new B();
            C             c1_ = new C(), c2_ = new C();
            ArrayList <B> mylist = new ArrayList <B>();

            mylist.AddAll(new B[] { new B(), b1_, b2_, c1_, new B() });
            System.Collections.IList list = new GuardedList <B>(mylist).View(1, 3);
            Object b1 = b1_, b2 = b2_, c1 = c1_, c2 = c2_;

            // Should be called with a three-element view of a GuardedList<B>
            Assert.AreEqual(3, list.Count);
            Assert.IsTrue(list.IsFixedSize);
            Assert.IsTrue(list.IsReadOnly);
            Assert.IsFalse(list.IsSynchronized);
            Assert.AreNotEqual(null, list.SyncRoot);
            Assert.AreEqual(list.SyncRoot, ((System.Collections.IList)mylist).SyncRoot);
            Assert.IsTrue(list.Contains(b1));
            Assert.IsTrue(list.Contains(b2));
            Assert.IsTrue(list.Contains(c1));
            Assert.IsFalse(list.Contains(c2));
            Array arrA = new A[3], arrB = new B[3];

            list.CopyTo(arrA, 0);
            list.CopyTo(arrB, 0);
            Assert.AreEqual(b1, arrA.GetValue(0));
            Assert.AreEqual(b1, arrB.GetValue(0));
            Assert.AreEqual(b2, arrA.GetValue(1));
            Assert.AreEqual(b2, arrB.GetValue(1));
            Assert.AreEqual(0, list.IndexOf(b1));
            Assert.AreEqual(-1, list.IndexOf(c2));
        }
Пример #2
0
        public void Freeze()
        {
            if (!Atoms.IsReadOnly)
            {
                Atoms = new GuardedList <IScriptAtom>(Atoms);
            }

            IsFrozen = true;
        }
Пример #3
0
        public void Freeze()
        {
            if (!Transactions.IsReadOnly)
            {
                Transactions = new GuardedList <Transaction>(Transactions);
            }
            foreach (var tx in Transactions)
            {
                tx.Freeze();
            }

            IsFrozen = true;
        }
Пример #4
0
        public void TryViewOfGuardedListAsSCIList2()
        {
            System.Collections.IList list = new GuardedList <B>(new ArrayList <B>()).View(0, 0);
            Assert.AreEqual(0, list.Count);
            list.CopyTo(new A[0], 0);
            list.CopyTo(new B[0], 0);
            list.CopyTo(new C[0], 0);
            Assert.IsFalse(list.IsSynchronized);
            Assert.AreNotEqual(null, list.SyncRoot);
            Object b1 = new B(), b2 = new B(), c1 = new C(), c2 = new C();

            Assert.IsFalse(list.Contains(b2));
            Assert.IsFalse(list.Contains(c2));
            Assert.AreEqual(-1, list.IndexOf(b1));
            Assert.AreEqual(-1, list.IndexOf(c1));
        }
Пример #5
0
 public static void Main(String[] args) {
   IList<int> list1 = new ArrayList<int>();
   list1.AddAll(new int[] { 2, 5, 7, 11, 37 });
   IList<int> list2 = new GuardedList<int>(list1);
   IList<int> 
     gv = new GuardedList<int>(list1.View(1,2)),
     vg = list2.View(1,2);
   IList<int> 
     gvu = gv.Underlying, 
     vgu = vg.Underlying;
   Console.WriteLine(gvu);  // Legal 
   Console.WriteLine(vgu);  // Legal 
   // gv.Slide(+1);         // Illegal: guarded view cannot be slid
   vg.Slide(+1);            // Legal: view of guarded can be slid
   // gvu[1] = 9;           // Illegal: list is guarded
   // vgu[1] = 9;           // Illegal: list is guarded
 }
Пример #6
0
    public static void Main()
    {
        IList <int> list1 = new ArrayList <int> {
            2, 5, 7, 11, 37
        };
        IList <int> gv  = new GuardedList <int>(list1.View(1, 2));
        IList <int> gvu = gv.Underlying;

        IList <int> list2 = new GuardedList <int>(list1);
        IList <int> vg    = list2.View(1, 2);
        IList <int> vgu   = vg.Underlying;

        Console.WriteLine(gvu);  // Legal
        Console.WriteLine(vgu);  // Legal
                                 // gv.Slide(+1);         // Illegal: guarded view cannot be slid
        vg.Slide(+1);            // Legal: view of guarded can be slid
                                 // gvu[1] = 9;           // Illegal: list is guarded
                                 // vgu[1] = 9;           // Illegal: list is guarded
    }
Пример #7
0
        public void Freeze()
        {
            if (!TransactionInputs.IsReadOnly)
            {
                TransactionInputs = new GuardedList <TransactionInput>(TransactionInputs);
            }
            foreach (var txIn in TransactionInputs)
            {
                txIn.Freeze();
            }

            if (!TransactionOutputs.IsReadOnly)
            {
                TransactionOutputs = new GuardedList <TransactionOutput>(TransactionOutputs);
            }
            foreach (var txOut in TransactionOutputs)
            {
                txOut.Freeze();
            }

            IsFrozen = true;
        }
Пример #8
0
 public void TryViewOfGuardedListAsSCIList2()
 {
     System.Collections.IList list = new GuardedList<B>(new ArrayList<B>()).View(0, 0);
       Assert.AreEqual(0, list.Count);
       list.CopyTo(new A[0], 0);
       list.CopyTo(new B[0], 0);
       list.CopyTo(new C[0], 0);
       Assert.IsFalse(list.IsSynchronized);
       Assert.AreNotEqual(null, list.SyncRoot);
       Object b1 = new B(), b2 = new B(), c1 = new C(), c2 = new C();
       Assert.IsFalse(list.Contains(b2));
       Assert.IsFalse(list.Contains(c2));
       Assert.AreEqual(-1, list.IndexOf(b1));
       Assert.AreEqual(-1, list.IndexOf(c1));
 }
Пример #9
0
 public void TryViewOfGuardedListAsSCIList1()
 {
     B b1_ = new B(), b2_ = new B();
       C c1_ = new C(), c2_ = new C();
       ArrayList<B> mylist = new ArrayList<B>();
       mylist.AddAll(new B[] { new B(), b1_, b2_, c1_, new B()});
       System.Collections.IList list = new GuardedList<B>(mylist).View(1, 3);
       Object b1 = b1_, b2 = b2_, c1 = c1_, c2 = c2_;
       // Should be called with a three-element view of a GuardedList<B>
       Assert.AreEqual(3, list.Count);
       Assert.IsTrue(list.IsFixedSize);
       Assert.IsTrue(list.IsReadOnly);
       Assert.IsFalse(list.IsSynchronized);
       Assert.AreNotEqual(null, list.SyncRoot);
       Assert.AreEqual(list.SyncRoot, ((System.Collections.IList)mylist).SyncRoot);
       Assert.IsTrue(list.Contains(b1));
       Assert.IsTrue(list.Contains(b2));
       Assert.IsTrue(list.Contains(c1));
       Assert.IsFalse(list.Contains(c2));
       Array arrA = new A[3], arrB = new B[3];
       list.CopyTo(arrA, 0);
       list.CopyTo(arrB, 0);
       Assert.AreEqual(b1, arrA.GetValue(0));
       Assert.AreEqual(b1, arrB.GetValue(0));
       Assert.AreEqual(b2, arrA.GetValue(1));
       Assert.AreEqual(b2, arrB.GetValue(1));
       Assert.AreEqual(0, list.IndexOf(b1));
       Assert.AreEqual(-1, list.IndexOf(c2));
 }