Esempio n. 1
0
        private Type GetControllerTypeWithinNamespaces(string controllerName, HashSet <string> namespaces)
        {
            // Once the master list of controllers has been created we can quickly index into it
            ControllerTypeCache.EnsureInitialized(BuildManager);

            IList <Type> matchingTypes = ControllerTypeCache.GetControllerTypes(controllerName, namespaces);

            switch (matchingTypes.Count)
            {
            case 0:
                // no matching types
                return(null);

            case 1:
                // single matching type
                return(matchingTypes[0]);

            default:
                // multiple matching types
                // we need to generate an exception containing all the controller types
                StringBuilder sb = new StringBuilder();
                foreach (Type matchedType in matchingTypes)
                {
                    sb.AppendLine();
                    sb.Append(matchedType.FullName);
                }
                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentUICulture,
                              MvcResources.DefaultControllerFactory_ControllerNameAmbiguous,
                              controllerName, sb));
            }
        }