示例#1
0
 public Person(string firstName, string lastName, DateTime dateOfBirth)
     : this(
         id : UniqueIds.GenerateUniqueId <Person>(),
         firstName : firstName,
         lastName : lastName,
         dateOfBirth : dateOfBirth)
 {
 }
示例#2
0
        public University(string name, string address)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            this.Id      = UniqueIds.GenerateUniqueId <University>();
            this.Name    = name;
            this.Address = address;
        }
示例#3
0
 public Student(
     string firstName,
     string lastName,
     DateTime dateOfBirth,
     IEnumerable <AttendedUniversity> attendedUniversities = null)
     : this(
         id : UniqueIds.GenerateUniqueId <Student>(),
         firstName : firstName,
         lastName : lastName,
         dateOfBirth : dateOfBirth)
 {
 }
示例#4
0
        public static void UseUniqueId <T>(int id)
        {
            Type targetType = typeof(T);

            if (!UniqueIds.IsUniqueId <T>(id))
            {
                throw new ArgumentException($"The identifier value '{id}' used for type '{targetType}' is not unique");
            }

            if (!uniqueIDs.ContainsKey(targetType))
            {
                uniqueIDs.Add(targetType, new Dictionary <int, bool>());
            }

            uniqueIDs[targetType].Add(id, true);
        }
示例#5
0
        public static void UseUniqueId(int id, Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (!UniqueIds.IsUniqueId(id, type))
            {
                throw new ArgumentException($"The identifier value '{id}' used for type '{type}' is not unique");
            }

            if (!uniqueIDs.ContainsKey(type))
            {
                uniqueIDs.Add(type, new Dictionary <int, bool>());
            }

            uniqueIDs[type].Add(id, true);
        }
示例#6
0
        public static int GenerateUniqueId(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (!uniqueIDs.ContainsKey(type))
            {
                uniqueIDs.Add(type, new Dictionary <int, bool>());
            }

            int nextId = uniqueIDs[type].Keys.Count > 0
                    ?
                         uniqueIDs[type].Keys.Max() + 1
                    :
                         1;

            UniqueIds.UseUniqueId(nextId, type);

            return(nextId);
        }
示例#7
0
        public Course(int universityId, string title, int yearOfStudy, int semesterOfStudy)
        {
            if (string.IsNullOrWhiteSpace(title))
            {
                throw new ArgumentNullException(nameof(title));
            }

            if (yearOfStudy <= 0)
            {
                throw new ArgumentException($"The year of study (passed value={yearOfStudy}) must be a positive number");
            }

            if ((semesterOfStudy <= 0) || (semesterOfStudy > 2))
            {
                throw new ArgumentException($"The semester of study (passed value={semesterOfStudy}) must be a valid semester value (1 or 2)");
            }

            this.Id              = UniqueIds.GenerateUniqueId <Course>();
            this.UniversityId    = universityId;
            this.Title           = title;
            this.YearOfStudy     = yearOfStudy;
            this.SemesterOfStudy = semesterOfStudy;
        }
示例#8
0
 public static int GenerateUniqueId <T>()
 {
     return(UniqueIds.GenerateUniqueId(typeof(T)));
 }
示例#9
0
        public static bool IsUniqueId <T>(int id)
        {
            Type targetType = typeof(T);

            return(UniqueIds.IsUniqueId(id, targetType));
        }