Example #1
0
        private CoupleAttribute GetCorrectAttribute(Type type1, Type type2)
        {
            IEnumerator enumerator = Attribute.GetCustomAttributes(type1, false).GetEnumerator();

            while (enumerator.MoveNext())
            {
                if (enumerator.Current is CoupleAttribute)
                {
                    CoupleAttribute attr = enumerator.Current as CoupleAttribute;
                    if (attr.Pair.Equals(type2.Name))
                    {
                        return(attr);
                    }
                }
            }

            throw new ArgumentException("Type without correct attribute");
        }
Example #2
0
        public IHasName MakeCouple(Human human1, Human human2)
        {
            if (human1.Sex == human2.Sex)
            {
                throw new WrongCoupleException();
            }
            Type            human1Type = human1.GetType();
            Type            human2Type = human2.GetType();
            CoupleAttribute attr1      = GetCorrectAttribute(human1Type, human2Type);

            if (IsLike(attr1.Probability))
            {
                CoupleAttribute attr2 = GetCorrectAttribute(human2Type, human1Type);
                if (IsLike(attr2.Probability))
                {
                    Human father = SelectFather(human1, human2);
                    Human mother = SelectMother(human1, human2);
                    return(CreateCoupleResult(attr1.ChildType, mother.Name, father.Name));
                }
            }

            return(null);
        }