コード例 #1
0
        private static void LoadRoutes(Type controllerType, IEqualityComparer <string> propertyNameComparer)
        {
            if (!LoadedControllerRoutes.Contains(controllerType))
            {
                lock (SyncRoot)
                {
                    if (!LoadedControllerRoutes.Contains(controllerType))
                    {
                        foreach (var prop in controllerType.GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(p => p.PropertyType == typeof(IController)))
                        {
                            Routes.Add(new ControllerRoute(controllerType, prop.Name, propertyNameComparer),
                                       GenerateRouteFunction(prop.GetMethod));
                        }
                        // Indexers
                        var methods = controllerType.GetMethods().Where(m => Attribute.IsDefined(m, typeof(IndexerAttribute))).OrderBy(m => m.GetCustomAttribute <IndexerAttribute>().Precedence).ToList();

                        if (methods.Select(m => m.GetCustomAttribute <IndexerAttribute>().Precedence)
                            .GroupBy(c => c)
                            .Any(c => c.Count() > 1))
                        {
                            throw new ArgumentException("Controller " + controllerType + " Has more then two indexer functions with the same precedence, Please set precedence.");
                        }

                        if (methods.Count > 0)
                        {
                            IndexerRoutes.Add(controllerType, methods.Select(m => ClassRouter.CreateIndexerFunction <IController>(controllerType, m)).ToArray());
                        }

                        LoadedControllerRoutes.Add(controllerType);
                    }
                }
            }
        }
コード例 #2
0
        private static void LoadRoutes(Type controllerType)
        {
            if (!LoadedControllerRoutes.Contains(controllerType))
            {
                lock (SyncRoot)
                {
                    if (!LoadedControllerRoutes.Contains(controllerType))
                    {
                        foreach (var prop in controllerType.GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(p => p.PropertyType == typeof(IController)))
                        {
                            Routes.Add(new ControllerRoute(controllerType, prop.Name),
                                       GenerateRouteFunction(prop.GetMethod));
                        }
                        // Indexers
                        var method = controllerType.GetMethods().SingleOrDefault(m => Attribute.IsDefined(m, typeof(IndexerAttribute)));
                        if (method != null)
                        {
                            IndexerRoutes.Add(controllerType, ClassRouter.CreateIndexerFunction <IController>(controllerType, method));
                        }

                        LoadedControllerRoutes.Add(controllerType);
                    }
                }
            }
        }