Exemplo n.º 1
0
 public int CompareTo(MyEntity other)
 {
     return(this.CompareTo(other));
 }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello, world!");


            const string clubReg    = @"(FC\.|AS\.)\s(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+(\d{4})";
            const string personReg  = @"(Mr\.|Mrs\.|Ms\.)\s(\w+)\s(\w+)\swas\sborn\son\s(\d{4}/\d{2}/\d{2})";
            const string companyReg = @"(\w+\s+)*?(\w+)\s+\(([^,]*)[^)]([^)]*)\)(\w+\s+)*?";


            var objectsParser = new Parser();

            Func <Match, Person>       personParser  = Person.CreatePerson;
            Func <Match, FootballClub> clubsParser   = FootballClub.CreateClub;
            Func <Match, Company>      companyParser = Company.CreateCompany;
            Dictionary <string, Func <Match, MyEntity> > delDictionary = new Dictionary <string, Func <Match, MyEntity> >
            {
                [personReg]  = personParser,
                [clubReg]    = clubsParser,
                [companyReg] = companyParser
            };

            string text = "Mr. John Smith was born on 2001/11/03. Mrs. Jessica Brown was born on 1999/12/31. Mr. John Smith was born on 2001/11/03. Last year winner FC. Dynamo from Kyiv Ukraine 1927 won against AS. Milan from Milan Italy 1899. Company Microsoft (Information Technology, US) was closed. Share price of Microsoft (Information Technology, US) dropped to $100. Company Google (IT, US) bought a new product."
            ;

            var objects = objectsParser.Parse(text, delDictionary);

            Console.WriteLine("Before:");
            objectsParser.ShowArr(objects);

            objects = objectsParser.RemoveD(objects);
            Console.WriteLine("\nAfter:");
            objectsParser.ShowArr(objects);

            //Закоментував метод, після того як записав, щоб продемонструвати, що зчитування також виконується
            //коли відкоментовані і запис і зчитування, видає помилку, що Рідер доступається до файлу, який зайнятий іншим (Врайтером)
            //objectsParser.SaveToXML(objects);

            MyEntity me = new MyEntity();

            Console.WriteLine("\n\nPersons from XML:");
            var personsList = new List <MyEntity>();

            personsList = Person.ReadPersonXml();

            me.Print(personsList);

            Console.WriteLine("\n\nClubs from XML:");
            var clubsList = new List <MyEntity>();

            clubsList = FootballClub.ReadClubXml();
            me.Print(clubsList);

            Console.WriteLine("\n\nCompanies from XML:");
            var companiesList = new List <MyEntity>();

            companiesList = Company.ReadCompanyXml();
            me.Print(companiesList);

            Console.ReadLine();
        }