protected internal void AddRouteMappingsDescriptions(IRouteMappings routeMappings, IDictionary <string, IList <MappingDescription> > desc)
        {
            if (routeMappings == null)
            {
                return;
            }

            foreach (var router in routeMappings.Routers)
            {
                var route = router as Route;
                if (route != null)
                {
                    var details = GetRouteDetails(route);
                    desc.TryGetValue("CoreRouteHandler", out IList <MappingDescription> mapList);

                    if (mapList == null)
                    {
                        mapList = new List <MappingDescription>();
                        desc.Add("CoreRouteHandler", mapList);
                    }

                    var mapDesc = new MappingDescription("CoreRouteHandler", details);
                    mapList.Add(mapDesc);
                }
            }
        }
示例#2
0
        protected internal IDictionary <string, IList <MappingDescription> > GetMappingDescriptions(ApiDescriptionProviderContext apiContext)
        {
            IDictionary <string, IList <MappingDescription> > mappingDescriptions = new Dictionary <string, IList <MappingDescription> >();

            foreach (var desc in apiContext.Results)
            {
                var cdesc   = desc.ActionDescriptor as ControllerActionDescriptor;
                var details = GetRouteDetails(desc);
                mappingDescriptions.TryGetValue(cdesc.ControllerTypeInfo.FullName, out IList <MappingDescription> mapList);

                if (mapList == null)
                {
                    mapList = new List <MappingDescription>();
                    mappingDescriptions.Add(cdesc.ControllerTypeInfo.FullName, mapList);
                }

                var mapDesc = new MappingDescription(cdesc.MethodInfo, details);
                mapList.Add(mapDesc);
            }

            foreach (var desc in apiContext.Actions)
            {
                if (desc is ControllerActionDescriptor cdesc)
                {
                    if (apiContext.Results.Any() && mappingDescriptions.Any(description => description.Value.Any(n => n.Handler.Equals(cdesc.MethodInfo.ToString()))))
                    {
                        continue;
                    }

                    var details = GetRouteDetails(desc);
                    mappingDescriptions.TryGetValue(cdesc.ControllerTypeInfo.FullName, out IList <MappingDescription> mapList);

                    if (mapList == null)
                    {
                        mapList = new List <MappingDescription>();
                        mappingDescriptions.Add(cdesc.ControllerTypeInfo.FullName, mapList);
                    }

                    var mapDesc = new MappingDescription(cdesc.MethodInfo, details);
                    mapList.Add(mapDesc);
                }
            }

            return(mappingDescriptions);
        }