Ejemplo n.º 1
0
        /* Indexator which gets and sets an element
         * at a specified index.
         */
        public Student this[int index]
        {
            get
            {
                try
                {
                    return(students.ElementAt(index));
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    return(null);
                }
            }

            set
            {
                if (index >= 0 & index < students.Count)
                {
                    students[index] = value;

                    StudentListEventHandlerEventArgs args = new StudentListEventHandlerEventArgs();
                    args.ChangedObject  = students[index];
                    args.ChangeType     = "An element was changed.";
                    args.CollectionName = this.CollectionName;
                    OnStudentReferenceChanged(args);
                }
            }
        }
Ejemplo n.º 2
0
        /* Abstraction method to separate event handler call */
        protected virtual void OnStudentReferenceChanged(StudentListEventHandlerEventArgs args)
        {
            StudentListHandler handler = StudentReferenceChanged;

            if (handler != null)
            {
                handler(this, args);
            }
        }
Ejemplo n.º 3
0
        /* Adds 5 default Student objects to students collection */
        public void AddDefaults()
        {
            if (students == null)
            {
                students = new List <Student>();
            }
            for (int i = 0; i < 5; i++)
            {
                Student stud = new Student();
                students.Add(stud);

                StudentListEventHandlerEventArgs args = new StudentListEventHandlerEventArgs();
                args.ChangedObject  = stud;
                args.ChangeType     = "A new default Student object was added to collection.";
                args.CollectionName = this.CollectionName;
                OnStudentsCountChanged(args);
            }
        }
Ejemplo n.º 4
0
        public void AddStudents(params Student[] student_array)
        {
            if (student_array != null)
            {
                if (this.students == null)
                {
                    this.students = new List <Student>();
                }

                for (int i = 0; i < student_array.Length; i++)
                {
                    this.students.Add(student_array[i]);

                    StudentListEventHandlerEventArgs args = new StudentListEventHandlerEventArgs();
                    args.ChangedObject  = student_array[i];
                    args.ChangeType     = "A new Student object from a source was added to collection.";
                    args.CollectionName = this.CollectionName;
                    OnStudentsCountChanged(args);
                }
            }
        }
Ejemplo n.º 5
0
        /* Removes an element from collection.
         * Returns "false" if there is no element with
         * specified index.
         */
        public bool Remove(int j)
        {
            Student stud = new Student();

            try
            {
                stud = students.ElementAt <Student>(j);
                students.RemoveAt(j);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                return(false);
            }

            StudentListEventHandlerEventArgs args = new StudentListEventHandlerEventArgs();

            args.ChangedObject  = stud;
            args.ChangeType     = "A Student at index " + j + " was  removed from collection.";
            args.CollectionName = this.CollectionName;
            OnStudentsCountChanged(args);
            return(true);
        }
Ejemplo n.º 6
0
        /* Event handler for StudentReferenceChanged event from StudentCollection. */
        public void handle_StudentReferenceChanged(object sender, StudentListEventHandlerEventArgs args)
        {
            JournalEntry je = new JournalEntry(args.CollectionName, args.ChangeType, args.ChangedObject.ToString());

            entries.Add(je);
        }