예제 #1
0
        /// <exception cref="ArgumentNullException">
        /// <paramref name="comment"/> is null.-or-
        /// <paramref name="entity"/> is null.
        /// </exception>
        public CommentRelation AddCommentRelation(Comment comment, IEntity entity)
        {
            CommentRelation commentRelation = new CommentRelation(comment, entity);

            AddRelation(commentRelation);
            return(commentRelation);
        }
예제 #2
0
        /// <exception cref="ArgumentException">
        /// Cannot create relationship between <paramref name="first"/>
        /// and <paramref name="second"/>.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="first"/> is null.-or-
        /// <paramref name="second"/> is null.
        /// </exception>
        public Relation Add(Entity first, Entity second, RelationType type)
        {
            if (first == null)
            {
                throw new ArgumentNullException("first");
            }
            if (second == null)
            {
                throw new ArgumentNullException("second");
            }
            if (first is TypeBase && second is TypeBase &&
                ((TypeBase)first).Language != ((TypeBase)second).Language)
            {
                throw new ArgumentException("error_cannot_create_relation");
            }

            Relation relation = null;

            try {
                switch (type)
                {
                case RelationType.Association:
                case RelationType.Composition:
                case RelationType.Aggregation:
                    if (first is TypeBase && second is TypeBase)
                    {
                        relation = AddAssociation((TypeBase)first, (TypeBase)second, type);
                    }
                    break;

                case RelationType.Generalization:
                    if (first is TypeBase && second is TypeBase)
                    {
                        relation = AddGeneralization((TypeBase)first, (TypeBase)second);
                    }
                    break;

                case RelationType.Realization:
                    if (first is TypeBase && second is InterfaceType)
                    {
                        relation = AddRealization((TypeBase)first, (InterfaceType)second);
                    }
                    break;

                case RelationType.Dependency:
                    if (first is TypeBase && second is TypeBase)
                    {
                        relation = new Dependency((TypeBase)first, (TypeBase)second);
                    }
                    break;

                case RelationType.Nesting:
                    if (first is FieldContainer && second is TypeBase)
                    {
                        relation = AddNesting((FieldContainer)first, (TypeBase)second);
                    }
                    break;

                case RelationType.CommentRelation:
                    if (first is Comment)
                    {
                        relation = new CommentRelation((Comment)first, second);
                    }
                    else
                    {
                        relation = new CommentRelation(first, (Comment)second);
                    }
                    break;
                }
            }
            catch (ArgumentException ex) {
                throw new ArgumentException("error_cannot_create_relation" + ex.Message);
            }

            if (relation == null)
            {
                throw new ArgumentException("error_cannot_create_relation");
            }
            else
            {
                InnerList.Add(relation);
            }

            return(relation);
        }