Ejemplo n.º 1
0
 public virtual FlattenedItem FirstOnLeft(FlattenedItem searchItem)
 {
     if (Items == null)
         return null;
     var searchIndex = Items.IndexOf(searchItem);
     return searchIndex <= 0 ? null : Items[searchIndex - 1];
 }
Ejemplo n.º 2
0
 public virtual FlattenedItem FirstOnRight(FlattenedItem searchItem)
 {
     if (Items == null)
         return null;
     var searchIndex = Items.IndexOf(searchItem);
     if (searchIndex < 0)
         return null;
     return searchIndex == Items.Count - 1 ? null : Items[searchIndex + 1];
 }
Ejemplo n.º 3
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));
                }
            }
        }
Ejemplo n.º 4
0
 public FlattenMrecordEdge(FlattenedItem left, FlattenedItem right)
 {
     Left  = left;
     Right = right;
 }
Ejemplo n.º 5
0
 public FlattenMrecordEdge(FlattenedItem left, FlattenedItem right)
 {
     Left = left;
     Right = right;
 }
Ejemplo n.º 6
0
        internal static List<FlattenedLine> FlattenType(Assembly assembly, string typeFullName,
            ref int currentDepth, int maxDepth, string limitOnValueType, bool displayEnums, Stack<FlattenedItem> fiValueTypes, Stack typeStack)
        {
            var printList = new List<FlattenedLine>();
            if (string.IsNullOrWhiteSpace(typeFullName))
                return printList;

            Func<PropertyInfo, string, bool> limitOnPi =
                (info, s) =>
                    string.IsNullOrWhiteSpace(s) ||
                    string.Equals($"{info.PropertyType}", s, StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(NfTypeName.GetLastTypeNameFromArrayAndGeneric(info.PropertyType), s,
                        StringComparison.OrdinalIgnoreCase) ||
                    (s == Constants.ENUM && NfTypeName.IsEnumType(info.PropertyType));

            var currentType = assembly.NfGetType(typeFullName);
            if (currentType == null)
                return printList;

            //top frame of recursive calls will perform this
            if (fiValueTypes == null)
            {
                if (maxDepth <= 0)
                    maxDepth = 16;
                typeStack = new Stack();
                typeStack.Push(typeFullName);
                fiValueTypes = new Stack<FlattenedItem>();
                fiValueTypes.Push(new FlattenedItem(currentType)
                {
                    FlName = NfTypeName.GetTypeNameWithoutNamespace(typeFullName)
                });
            }

            var typeNamesList =
                currentType.GetProperties(NfConfig.DefaultFlags)
                    .Where(
                        x =>
                            (NfTypeName.IsValueTypeProperty(x) && limitOnPi(x, limitOnValueType)
                             || (limitOnValueType == Constants.ENUM && limitOnPi(x, limitOnValueType)))
                    //more limbo branching for enums
                    )
                    .Select(p => new Tuple<Type, string>(p.PropertyType, p.Name))
                    .ToList();

            foreach (var typeNamePair in typeNamesList)
            {
                var pVtype = typeNamePair.Item1;
                var pVname = typeNamePair.Item2;

                fiValueTypes.Push(new FlattenedItem(pVtype) { FlName = pVname });
                var fiItems = fiValueTypes.ToList();
                fiItems.Reverse();
                printList.Add(new FlattenedLine(fiItems.Distinct(new FlattenedItemComparer()).ToList())
                {
                    ValueType = $"{typeNamePair.Item1}"
                });
                fiValueTypes.Pop();
            }

            //then recurse the object types
            foreach (
                var p in
                    currentType.GetProperties(NfConfig.DefaultFlags)
                        .Where(x => !NfTypeName.IsValueTypeProperty(x)))
            {
                var typeIn = NfTypeName.GetLastTypeNameFromArrayAndGeneric(p.PropertyType);

                if (typeIn == null || typeStack.Contains(typeIn)) continue;

                var fi = new FlattenedItem(p.PropertyType) {FlName = p.Name};
                if (fiValueTypes.ToList().Any(x => x.FlType == p.PropertyType))
                    continue;

                fiValueTypes.Push(fi);
                typeStack.Push(typeIn);
                currentDepth += 1;

                //time to go
                if (currentDepth >= maxDepth)
                    return printList;

                //enum types being handled as limbo between value type and ref type
                string[] enumVals;
                if (displayEnums && NfTypeName.IsEnumType(p.PropertyType, out enumVals))
                {
                    foreach (var ev in enumVals)
                    {
                        fiValueTypes.Push(new FlattenedItem(typeof(Enum)) {FlName = ev});
                        var fiItems = fiValueTypes.ToList();
                        fiItems.Reverse();
                        printList.Add(new FlattenedLine(fiItems.Distinct(new FlattenedItemComparer()).ToList())
                        {
                            ValueType = String.Empty
                        });
                        fiValueTypes.Pop();
                    }
                }
                else
                {
                    printList.AddRange(FlattenType(assembly, fi.TypeFullName, ref currentDepth, maxDepth,
                        limitOnValueType, displayEnums, fiValueTypes, typeStack));
                }

                fiValueTypes.Pop();
                typeStack.Pop();
                currentDepth -= 1;
            }
            return printList;
        }
Ejemplo n.º 7
0
        public AsmDiagram(Assembly asm, bool withNamespaceSubGraphs = false)
        {
            if (asm == null)
            {
                throw new ArgumentNullException(nameof(asm));
            }

            _targetedNs = asm.GetName().Name;

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

                foreach (
                    var p in
                    asmType.NfGetProperties(NfSettings.DefaultFlags, false)
                    .Where(
                        x => x != null &&
                        !string.IsNullOrWhiteSpace(x.NfPropertyType(false)?.Namespace) &&
                        AssemblyName.ReferenceMatchesDefinition(x.NfPropertyType(false)?.Assembly.GetName(), asm.GetName()))
                    )
                {
                    if (NfReflect.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));
                }
            }
        }
Ejemplo n.º 8
0
 public override FlattenedItem FirstOnRight(FlattenedItem searchItem)
 {
     return _blank.FirstOrDefault();
 }