private static ControllerIdentification GetControllerName(Type type) { string fullName = type.FullName; Debug.Assert(fullName != null); fullName = fullName.Substring(0, fullName.Length - VersionedControllerSelector.ControllerSuffix.Length); // split by dot and find version string[] nameSplit = fullName.Split('.'); string name = nameSplit[nameSplit.Length - 1]; // same as Type.Name string version = null; for (int i = nameSplit.Length - 2; i >= 0; i--) { string namePart = nameSplit[i]; if (!namePart.StartsWith(VersionedControllerSelector.VersionPrefix, StringComparison.InvariantCultureIgnoreCase)) { continue; } if (VersionedControllerSelector.IsVersionNumber(namePart)) { version = VersionedControllerSelector.ToVersionNumber(namePart); break; } } return(new ControllerIdentification(name, version)); }
public static string Version(this HttpControllerDescriptor controllerDescriptor) { string version = "???"; if (controllerDescriptor != null) { var parts = controllerDescriptor.ControllerType.Namespace.Split('.'); foreach (var part in parts.Where(VersionedControllerSelector.IsVersionNumber)) { return(VersionedControllerSelector.ToVersionNumber(part)); } } return(version); }