Exemple #1
0
        public void UpdateTypeInfo(Type type, [CanBeNull] Action <UmlEntity, bool> modification)
        {
            var created = false;

            if (!_entities.TryGetValue(type, out var info))
            {
                created         = true;
                _entities[type] = info = new UmlEntity(type, GetTypeName);
            }

            if (modification != null)
            {
                modification(info, created);
            }
            if (!created)
            {
                return;
            }
            var handler = OnAddTypeToDiagram;

            if (handler == null)
            {
                return;
            }
            var args = new AddTypeToDiagramEventArgs
            {
                Info    = info,
                Diagram = this
            };

            handler.Invoke(this, args);
        }
Exemple #2
0
        public void Visit(UmlDiagram diagram, UmlEntity info)
        {
            var t = info.Type;

            foreach (var att in t.GetCustomAttributes <T>())
            {
                VisitInternal(diagram, info, att);
            }
        }
Exemple #3
0
        public void Visit(UmlDiagram diagram, UmlEntity info)
        {
            var att = info.Type.GetCustomAttribute <T>();

            if (att == null)
            {
                return;
            }
            VisitInternal(diagram, info, att);
        }
Exemple #4
0
        private void AddToFile(Type type)
        {
            var cf = _state.File.Classes;

            if (!_entities.TryGetValue(type, out var info))
            {
                info = new UmlEntity(type, GetTypeName);
            }
            cf.Open(info.GetOpenClassCode());

            {
                var l = info.StartingLines?.SplitLines(true);
                if (l != null)
                {
                    foreach (var i in l)
                    {
                        cf.Writeln(i);
                    }
                }
            }
            foreach (var i in info.Members.OrderBy(q => q.Group))
            {
                if (i.HideOnList)
                {
                    continue;
                }
                i.WriteTo(cf, this);
            }

            cf.Close();
            var notes = info.Notes.OrderBy(a => a.Key);

            foreach (var i in notes)
            {
                var text  = i.Value.Text;
                var lines = text.SplitLines(true);
                if (lines is null)
                {
                    continue;
                }

                var bg = i.Value.Background?.GetCode();
                if (!string.IsNullOrEmpty(bg))
                {
                    bg = " " + bg;
                }
                var openNote = $"note {i.Key.ToString().ToLower()} of {info.Name.AddQuotesIfNecessary()}{bg}";
                cf.Writeln(openNote);
                foreach (var j in lines)
                {
                    cf.Writeln(j);
                }
                cf.Writeln("end note");
            }
        }
Exemple #5
0
        private static IEnumerable <Type> ProcessMethod(UmlDiagram diagram, UmlEntity diagClass, MethodUmlMember member)
        {
            if (diagClass.Type != member.Method.DeclaringType)
            {
                if (diagram.ContainsType(diagClass.Type.BaseType.MeOrGeneric()))
                {
                    member.HideOnList = true;
                    yield break;
                }
            }

            var att = member.Method.GetCustomAttribute <UmlRelationAttribute>();

            if (att == null)
            {
                yield break;
            }

            var ti = new TypeExInfo(att.RelatedType ?? member.Method.ReturnType, att.DoNotResolveCollections);

            if (!diagram.ContainsType(ti.ElementType))
            {
                yield break;
            }
            // create relation

            member.HideOnList = true;

            var          owner          = diagClass.Type;
            var          component      = ti.ElementType;
            const string ownerLabel     = "";
            const string componentLabel = "";

            var arrow = UmlRelationArrow.MkArrow(att, GetMultiplicity(att.Multiple, ti.IsCollection));

            if (att.ForceAddToDiagram)
            {
                yield return(ti.ElementType);
            }

            var rel = new UmlRelation
            {
                Left  = new UmlRelationEnd(diagram.GetTypeName(owner), ownerLabel),
                Right = new UmlRelationEnd(diagram.GetTypeName(component), componentLabel),
                Arrow = arrow,
                Label = string.IsNullOrEmpty(att.Name) ? GetLabel(member) : att.Name
            }
            .WithNote(att)
            .WitCreatorMeta <MemberToRelationVisitor>(owner, component);

            rel.Tag        = att.Tag;
            rel.BaseMember = member;

            diagram.Relations.Add(rel);
        }
        public void Visit(UmlDiagram diagram, UmlEntity info)
        {
            var members = info.Type.GetMembers(MyBindingFlags);

            foreach (var memberInfo in members)
            {
                var typeExInfo = GetTi(memberInfo);
                if (typeExInfo != null)
                {
                    diagram.UpdateTypeInfo(typeExInfo.ElementType, null);
                }
            }
        }
Exemple #7
0
 public void Visit(UmlDiagram diagram, UmlEntity info)
 {
     for (var index = 0; index < info.Members.Count; index++)
     {
         var umlMember  = info.Members[index];
         var memberInfo = umlMember.GetMemberInfo();
         var hide       = ShouldBeHidden(memberInfo);
         if (hide)
         {
             umlMember.HideOnList = true;
         }
     }
 }
        public void Visit(UmlDiagram diagram, UmlEntity info)
        {
            var type = info.Type;

            var properties = ScanProperties(type, ScanFlags);

            info.Members.AddRange(properties);

            var r = BindingFlags.Public | BindingFlags.NonPublic;

            if (ScanFlags.HasFlag(ReflectionFlags.InstanceMethod))
            {
                r |= BindingFlags.Instance;
            }
            if (ScanFlags.HasFlag(ReflectionFlags.StaticMethod))
            {
                r |= BindingFlags.Static;
            }

            var methodInfos = type.GetMethods(r);

            {
                var h = SortAndPrepareMethods;
                if (h != null)
                {
                    var args = new SortAndPrepareMethodsEventArgs {
                        Methods = methodInfos
                    };
                    h.Invoke(this, args);
                    methodInfos = args.Methods;
                }
            }
            foreach (var mi in methodInfos)
            {
                var add  = CheckSkipDefault(mi);
                var flag = GetMFlag(mi, ReflectionFlags.PublicMethod, ReflectionFlags.ProtectedMethod,
                                    ReflectionFlags.PrivateMethod);
                if (add)
                {
                    if (!H(flag, ScanFlags))
                    {
                        add = false;
                    }
                }

                var h = AddTypeToDiagram;
                if (h is null && !add)
                {
                    continue;
                }

                var member = new MethodUmlMember
                {
                    Group      = 20,
                    Name       = mi.Name,
                    Method     = mi,
                    Visibility = GetVisibilityFromFlags(flag)
                };
                if (mi.IsAbstract)
                {
                    member.Kind = UmlMemberKind.Abstract;
                }
                if (mi.IsStatic)
                {
                    member.Kind = UmlMemberKind.Static;
                }

                if (h != null)
                {
                    var args = new AddTypeToDiagramEventArgs
                    {
                        Decision  = add ? AddDecision.Add : AddDecision.Skip,
                        Member    = mi,
                        UmlMember = member
                    };
                    h(this, args);
                    if (args.Decision != AddDecision.Default)
                    {
                        add = args.Decision == AddDecision.Add;
                    }
                }

                if (!add)
                {
                    continue;
                }

                info.Members.Add(member);
            }
        }
Exemple #9
0
 private UmlPackageName GetPackageName(UmlEntity entity)
 {
     return(IgnorePackages ? UmlPackageName.Empty : new UmlPackageName(entity.PackageName));
 }
Exemple #10
0
        private IEnumerable <Type> ProcessProperty(UmlDiagram diagram, UmlEntity diagClass,
                                                   PropertyUmlMember property)
        {
            var decision = ConvertToRelation?.Invoke(property) ?? ChangeDecision.Auto;

            if (decision == ChangeDecision.Auto)
            {
                if (property.Property.GetCustomAttribute <DontConvertToRelationAttribute>() != null)
                {
                    decision = ChangeDecision.No;
                }
                else
                {
                    decision = ChangeDecision.Yes;
                }
            }

            if (decision == ChangeDecision.No)
            {
                yield break;
            }

            if (diagClass.Type != property.Property.DeclaringType)
            {
                if (diagram.ContainsType(diagClass.Type.BaseType))
                {
                    property.HideOnList = true;
                    yield break;
                }
            }

            var doNotResolveCollections =
                property.Property.GetCustomAttribute <BaseRelationAttribute>()?.DoNotResolveCollections ?? false;
            var ti = new TypeExInfo(property.Property.PropertyType, doNotResolveCollections);

            if (!diagram.ContainsType(ti.ElementType))
            {
                yield break;
            }
            // create relation
            if (!CanAddRelation(diagram, property))
            {
                yield break;
            }
            property.HideOnList = true;
            var arrow = new UmlRelationArrow(
                ArrowEnd.Empty,
                ti.IsCollection ? ArrowEnd.Multiple : ArrowEnd.ArrowOpen);
            var          owner           = diagClass.Type;
            var          arrowTargetType = ti.ElementType;
            const string ownerLabel      = "";
            const string componentLabel  = "";

            var att = property.Property.GetCustomAttribute <UmlRelationAttribute>();

            if (att != null)
            {
                var relationTi = new TypeExInfo(att.RelatedType ?? property.Property.PropertyType,
                                                att.DoNotResolveCollections);
                arrow = UmlRelationArrow.MkArrow(att, GetMultiplicity(att.Multiple, relationTi.IsCollection));
                if (att.ForceAddToDiagram)
                {
                    yield return(relationTi.ElementType);
                }
                arrowTargetType = relationTi.ElementType;
            }

            var rel = new UmlRelation
            {
                Left  = new UmlRelationEnd(diagram.GetTypeName(owner), ownerLabel),
                Right = new UmlRelationEnd(diagram.GetTypeName(arrowTargetType), componentLabel),
                Arrow = arrow,
                Label = string.IsNullOrEmpty(att?.Name) ? property.Name : att.Name
            }
            .WithNote(att)
            .WitCreatorMeta <MemberToRelationVisitor>(owner, arrowTargetType);

            rel.Tag        = att?.Tag;
            rel.BaseMember = property;
            {
                var eventHandler = AfterConversionProperty;
                if (eventHandler != null)
                {
                    var args = new AfterConversionPropertyEventArgs
                    {
                        Diagram       = diagram,
                        Entity        = diagClass,
                        BaseUmlMember = property,
                        Relation      = rel
                    };
                    eventHandler(this, args);
                }
            }
            diagram.Relations.Add(rel);
        }
Exemple #11
0
 protected abstract void VisitInternal(UmlDiagram diagram, UmlEntity info, [NotNull] T att);
Exemple #12
0
        public SetFlagResult DefaultHideMethod(UmlDiagram diagram, UmlMember umlMember, UmlEntity entity)
        {
            bool AlreadyOnDiagram(Type entityType, Type declaringType)
            {
                if (entityType == null || entityType == declaringType)
                {
                    return(false);
                }
                while (true)
                {
                    var bt = entityType.BaseType.MeOrGeneric();
                    if (bt == null)
                    {
                        return(false);
                    }
                    if (diagram.ContainsType(bt))
                    {
                        return(true);
                    }
                    entityType = bt;
                }
            }

            if (!(umlMember is MethodUmlMember mum))
            {
                return(SetFlagResult.LeaveUnchanged);
            }
            var mi = mum.Method;

            if (mi.DeclaringType == typeof(object))
            {
                return(SetFlagResult.SetToTrue);
            }
            if (AlreadyOnDiagram(entity.Type, mi.DeclaringType))
            {
                return(SetFlagResult.SetToTrue);
            }

            if (HideShouldSerializeMethods)
            {
                if (IsShouldSerializeMethod(mi))
                {
                    return(SetFlagResult.SetToTrue);
                }
            }

            return(SetFlagResult.LeaveUnchanged);
        }