/// <summary> /// Finds a resource by a search string. The string can be a partial resource name. /// <param name="searchString">The case insensitive string to use for the search</param> /// <param name="resource">The found resource (if any)</param> /// <param name="error">Describes the error that occured when locating the resource (if any)</param> /// <param name="kind">The resource kind to filter results against</param> /// </summary> public static bool TryFind(string searchString, out IResource resource, out Error error, ResourceKind kind = ResourceKind.All) { searchString = searchString.ToLower(); error = null; resource = Admin.ResourceAlias.GetByAlias(searchString)?.IResource; if (resource != null) { return(true); } if (!RESTarConfig.ResourceFinder.TryGetValue(searchString, out resource)) { error = new UnknownResource(searchString); return(false); } if (resource == null) { error = new AmbiguousResource(searchString); return(false); } if (!kind.HasFlag(resource.ResourceKind)) { error = new WrongResourceKind(searchString, kind, resource.ResourceKind); return(false); } return(true); }
/// <summary> /// Finds a resource by a search string. The string can be a partial resource name. /// <param name="searchString">The case insensitive string to use for the search</param> /// <param name="resource">The found resource (if any)</param> /// <param name="error">Describes the error that occured when locating the resource (if any)</param> /// <param name="kind">The resource kind to filter results against</param> /// </summary> public bool TryFindResource(string searchString, out IResource resource, out Error error, ResourceKind kind = ResourceKind.All) { searchString = searchString.ToLower(); error = null; if (!ResourceFinder.TryGetValue(searchString, out resource)) { error = new UnknownResource(searchString); return(false); } if (resource == null) { error = new AmbiguousResource(searchString); return(false); } if (!kind.HasFlag(resource.ResourceKind)) { error = new WrongResourceKind(searchString, kind, resource.ResourceKind); return(false); } return(true); }