protected override void VisitInternal(UmlDiagram diagram, UmlEntity info, UmlAddRelationAttribute att)
        {
            var rel = new UmlRelation
            {
                Left  = new UmlRelationEnd(diagram.GetTypeName(info.Type)),
                Right = new UmlRelationEnd(diagram.GetTypeName(att.RelatedType)),
                Arrow = UmlRelationArrow.MkArrow(att, att.Multiple),
                Label = att.Name
            }
            .WitCreatorMeta <UmlAddRelationAttributeVisitor>(info.Type, att.RelatedType)
            .WithNote(att);

            rel.Tag = att.Tag;
            diagram.Relations.Add(rel);
            if (att.ForceAddToDiagram)
            {
                diagram.UpdateTypeInfo(att.RelatedType, null);
            }
        }
Beispiel #2
0
        private IEnumerable <Type> AddTypeToGraph(PlantUmlResult rr, Type t, List <UmlRelation> relations,
                                                  HashSet <Type> processed)
        {
            var result = new List <Type>();

            if (!_types.TryGetValue(t, out var info))
            {
                return(result);
            }
            if (!processed.Add(t))
            {
                return(result);
            }

            var cf = rr.Classes;

            cf.Open(GetClassOpen(t));
            foreach (var pi in t.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                if (SkipDrawing(t, pi.DeclaringType))
                {
                    continue;
                }
                var att  = pi.GetCustomAttribute <UmlRelationAttribute>();
                var kind = att?.Kind ?? UmlRelationKind.AggregationWithArrow;
                var rel  = FindRelation(pi.PropertyType, kind, att, pi.Name, t);
                if (rel != null)
                {
                    relations.Add(rel);
                    result.Add(pi.PropertyType);
                    continue;
                }

                cf.Writeln(GetTypeName(pi.PropertyType) + " " + pi.Name);
            }

            foreach (var mi in t.GetMethods(BindingFlags.Instance | BindingFlags.Public))
            {
                if (mi.IsSpecialName)
                {
                    continue;
                }
                if (mi.DeclaringType == typeof(object))
                {
                    continue;
                }
                if (SkipDrawing(t, mi.DeclaringType))
                {
                    continue;
                }
                cf.Writeln(MethodToUml(mi));

                var att = mi.GetCustomAttribute <UmlRelationAttribute>();
                if (att != null)
                {
                    var kind = att.Kind;
                    var rel  = FindRelation(mi.ReturnType, kind, att, mi.Name + "() >", t);
                    if (rel != null)
                    {
                        var a = rel.Arrow;
                        a.Dotted  = true;
                        rel.Arrow = a;

                        relations.Add(rel);
                        result.Add(mi.ReturnType);
                    }
                }
            }

            foreach (var i in t.GetCustomAttributes <UmlAddRelationAttribute>())
            {
                var rel = new UmlRelation
                {
                    Left      = new UmlRelationEnd(GetTypeName(t)),
                    Right     = new UmlRelationEnd(GetTypeName(i.RelatedType)),
                    Arrow     = UmlRelationArrow.GetRelationByKind(i.Kind),
                    Label     = i.Name,
                    Note      = i.Note,
                    NoteColor = i.NoteColor
                };
                relations.Add(rel);
            }

            cf.Close();

            foreach (var i in t.GetCustomAttributes <UmlNoteAttribute>())
            {
                // cf.Writeln("-- note --");
                cf.Writeln("note bottom of " + GetTypeName(t));
                foreach (var line in i.Text.Split('\n', '\r'))
                {
                    if (!string.IsNullOrEmpty(line))
                    {
                        cf.Writeln(line);
                    }
                }
                cf.Writeln("end note");
            }

            if (t.BaseType != null && _types.ContainsKey(t.BaseType))
            {
                relations.Add(Inherits(t.BaseType, t).With(UmlArrowDirections.Up));
            }
            foreach (var i in t.GetInterfaces())
            {
                if (_types.ContainsKey(i))
                {
                    relations.Add(Inherits(i, t).With(UmlArrowDirections.Up));
                }
            }

            return(result);
        }