コード例 #1
0
        /// <summary>
        /// Adds a person to list.
        /// </summary>
        public void AddPerson()
        {
            Person newPerson = NewPersonCreator();
            bool   key       = false;

            foreach (Person p in list)
            {
                if (p.LastName == newPerson.LastName)
                {
                    key = true;
                }
            }
            if (key)
            {
                SameLastNamesHappenedEventArgs args = new SameLastNamesHappenedEventArgs();
                args.LastName = newPerson.LastName;
                OnSameLastNamesHappened(args);
            }
            list.Add(newPerson);
            Console.WriteLine("Successfully added.");
        }
コード例 #2
0
        private void Receiver_SameLastNamesHappened(object sender, SameLastNamesHappenedEventArgs eventArgs)
        {
            string sameLastName = eventArgs.LastName;

            Console.WriteLine($"Similar last name '{sameLastName}' has detected. Here's list of namesake:");

            List <Person> newList = new List <Person>();

            foreach (Person p in ListOfPersonas.GetListOfPersonas().GetPersonas())
            {
                if (p.LastName == sameLastName)
                {
                    p.OutputPerson();
                    newList.Add(p);
                }
            }
            string path = @"D:\Workspace\TAT\DEV-8\DEV-8\listOfPersonas.json";

            using (StreamWriter file = File.CreateText(path))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(file, newList);
            }
        }
コード例 #3
0
 /// <summary>
 /// Invokes event SameLastNamesHappened.
 /// </summary>
 /// <param name="eventArgs">Event arguments.</param>
 public virtual void OnSameLastNamesHappened(SameLastNamesHappenedEventArgs eventArgs)
 {
     SameLastNamesHappened?.Invoke(this, eventArgs);
 }