コード例 #1
0
        public static Newspaper[] Extract(String input)
        {
            var           type       = typeof(Newspaper);
            RegexStr      reg        = (RegexStr)type.GetTypeInfo().GetCustomAttribute(typeof(RegexStr));
            List <String> newspapers = MyParser.GetEntries(input, reg.Value);

            Newspaper[] result = new Newspaper[newspapers.Count];
            int         i      = 0;

            foreach (String s in newspapers)
            {
                String   Name;
                String   Country;
                String   Frequency;
                String   Subject;
                String[] parts = s.Split(' ');
                Name      = parts[1].Substring(0, parts[1].Length - 1);
                Country   = parts[2];
                Frequency = parts[3].Substring(1, parts[3].Length - 2);
                Subject   = parts[4].Substring(0, parts[4].Length - 1);
                Newspaper res = new Newspaper(Name, Country, Frequency, Subject);
                result[i++] = res;
            }
            return(result);
        }
コード例 #2
0
        public int CompareTo(IParsee obj)
        {
            if (obj == null)
            {
                return(1);
            }

            Newspaper other = obj as Newspaper;

            if (this.Name.CompareTo(other.Name) > 0)
            {
                return(1);
            }
            else if (this.Name.CompareTo(other.Name) < 0)
            {
                return(-1);
            }
            else
            {
                if (this.Country.CompareTo(other.Country) > 0)
                {
                    return(1);
                }
                else if (this.Country.CompareTo(other.Country) < 0)
                {
                    return(-1);
                }
                else
                {
                    if (this.Frequency.CompareTo(other.Frequency) > 0)
                    {
                        return(1);
                    }
                    else if (this.Frequency.CompareTo(other.Frequency) < 0)
                    {
                        return(-1);
                    }
                    else
                    {
                        return(this.Subject.CompareTo(other.Subject));
                    }
                }
            }
        }