private static bool HasBreadcrumb(Type type, out BreadcrumbNodeEntry entry)
        {
            entry = null;

            if (!type.IsRazorPage())
            {
                return(false);
            }

            var attr = type.GetCustomAttribute <BreadcrumbAttribute>();

            if (attr == null)
            {
                return(false);
            }

            string path = type.ExtractRazorPageKey();

            entry = new BreadcrumbNodeEntry
            {
                Key     = path,
                Node    = new RazorPageBreadcrumbNode(path, attr),
                FromKey = attr.ExtractFromKey(type),
                Default = attr.Default
            };

            return(true);
        }
        private bool TryGetBreadcrumbNodeEntry(Type type, out BreadcrumbNodeEntry entry)
        {
            entry = null;
            if (!type.IsController())
            {
                return(false);
            }

            var attr = type.GetCustomAttribute <BreadcrumbAttribute>();

            if (attr == null)
            {
                return(false);
            }

            //if no title is given, then fallback to controller name.
            if (string.IsNullOrWhiteSpace(attr.Title))
            {
                attr.Title = type.Name.Replace("Controller", string.Empty);
            }

            string key = type.ExtractMvcControllerKey();

            entry = new BreadcrumbNodeEntry
            {
                Key     = key,
                Node    = new MvcControllerBreadcrumbNode(type.Name.Replace("Controller", string.Empty), attr),
                FromKey = attr.ExtractFromKey(type),
                Default = attr.Default
            };

            return(true);
        }
        private void GenerateHierarchy(Dictionary <string, BreadcrumbNodeEntry> entries)
        {
            // Mandatory single default entry
            BreadcrumbNodeEntry defaultEntry = entries.Values.Single(e => e.Default);

            DefaultNode = defaultEntry.Node;
            _nodes.Add(defaultEntry.Key, DefaultNode);

            foreach (var entry in entries.Values)
            {
                if (entry.Default)
                {
                    continue;
                }

                var fromKey = entry.FromKey ?? defaultEntry.Key;
                if (!entries.ContainsKey(fromKey))
                {
                    throw new SmartBreadcrumbsException($"No node exists that has a '{fromKey}' as a key.\n" +
                                                        $"Make sure that razor page or controller action has a BreadcrumbAttribute.");
                }

                var fromEntry = entries[fromKey];
                entry.Node.Parent = fromEntry.Node;
                _nodes.Add(entry.Key, entry.Node);
            }
        }
        private static bool HasBreadcrumb(Type type, out BreadcrumbNodeEntry entry)
        {
            entry = null;

            if (!type.IsRazorPage())
            {
                return(false);
            }

            var attr = type.GetCustomAttribute <BreadcrumbAttribute>();

            if (attr == null)
            {
                return(false);
            }

            //if no title is given, then fallback to type name (razor page name).
            if (string.IsNullOrWhiteSpace(attr.Title))
            {
                attr.Title = type.Name.Replace("Page", string.Empty);
            }

            string path = type.ExtractRazorPageKey();

            entry = new BreadcrumbNodeEntry
            {
                Key     = path,
                Node    = new RazorPageBreadcrumbNode(path, attr),
                FromKey = attr.ExtractFromKey(type),
                Default = attr.Default
            };

            return(true);
        }