Beispiel #1
0
        public AsmDiagram(Assembly asm, bool withNamespaceSubGraphs = false)
        {
            if (asm == null)
                throw new ArgumentNullException(nameof(asm));

            _targetedNs = asm.GetName().Name;

            _withNsSubgraphs = withNamespaceSubGraphs;
            _asmName = NfTypeName.SafeDotNetIdentifier(asm.GetName().Name);
            foreach (
                var asmType in
                    asm.NfGetExportedTypes()
                        .Where(x => !string.IsNullOrWhiteSpace(x.Namespace) && x.Namespace.StartsWith(_targetedNs)))
            {
                var item1 = new FlattenedItem(asmType) {FlName = asmType.Name};
                if (item1.IsTerminalNode || NfTypeName.IsEnumType(asmType))
                    continue;

                foreach (
                    var p in
                        asmType.GetProperties(NfConfig.DefaultFlags)
                            .Where(
                                x =>
                                    !string.IsNullOrWhiteSpace(x.PropertyType.Namespace) &&
                                    x.PropertyType.Namespace.StartsWith(_targetedNs))
                    )
                {
                    if (NfTypeName.IsEnumType(p.PropertyType))
                        continue;
                    var item2 = new FlattenedItem(p.PropertyType) {FlName = p.Name};
                    if (item2.IsTerminalNode)
                        continue;
                    var tupleOfItems = new Tuple<FlattenedItem, FlattenedItem>(item1, item2);
                    var itemEv = new AsmDiagramEdge(tupleOfItems);
                    if (Edges.Any(x => x.AreSame(itemEv)))
                        continue;
                    Edges.Add(itemEv);
                }
            }

            Edges = RemoveDuplicates(Edges);

            var names = Edges.SelectMany(x => x.NodeName).ToList();
            var uqNames = names.Distinct().OrderBy(x => x).ToList();
            _nodes = uqNames.Select(x => new AsmDiagramNode(x, GetCountOfEdgesOn(x))).ToList();

            if (_withNsSubgraphs)
            {
                var uqNamespaces = _nodes.Select(x => x.NodeNamespace).Distinct().ToList();
                foreach (var ns in uqNamespaces)
                {
                    _nsSubGraphs.Add(new AsmDiagramSubGraph(ns, _nodes));
                }
            }
        }
Beispiel #2
0
 public bool AreSame(AsmDiagramEdge ed)
 {
     if (ed == null)
         return false;
     return ed.Node1 == Node1 && ed.Node2 == Node2;
 }
Beispiel #3
0
 public bool AreCounterparts(AsmDiagramEdge ed)
 {
     if(ed == null)
         return false;
     return ed.Node2 == Node1 && ed.Node1 == Node2;
 }