public bool TryGet <T>(StorageItemType key, [NotNullWhen(true)][MaybeNullWhen(false)] out T obj) { obj = default; if (!Contains(key)) { return(false); } if (_objectDictionary[key] is T output) { obj = output; return(true); } return(false); }
//string scheme, string host, string path, string name) public StorageItem(StorageItemType type, IWebsite website, Uri url) { this._website = website; this._scheme = url.Scheme; this._host = url.Host + "/" + url.Segments[1]; string localPath = url.LocalPath; if (localPath.EndsWith("/")) { localPath = localPath.Substring(0, localPath.Length - 1); } var segments = localPath.Split('/'); this._name = segments[segments.Length - 1]; for (int i = 2; i < segments.Length - 1; i++) { this._path += segments[i] + "/"; } if (type == StorageItemType.Folder) { //this._name = this._name.Substring(0, this._name.Length - 1); } //return new Folder(website, uri.Scheme, host, path, fileName.Substring(0, fileName.Length - 1)); //string fileName = uri.Segments[uri.Segments.Length - 1]; //for (int i = 0; i < 2; i++) { host += uri.Segments[i]; } //for (int i = 2; i < uri.Segments.Length - 1; i++) { path += uri.Segments[i]; } //this._path = path; //this._name = name; if (!string.IsNullOrEmpty(this._path)) { string[] parents = this._path.Split('/'); string parentPath = string.Empty; if (parents.Length >= 2) { string parentFileName = parents[parents.Length - 2]; for (int i = 0; i < parents.Length - 2; i++) { parentPath += parents[i]; } this.Parent = new Folder(website, new Uri(this._scheme + "://" + this._host + this._path)); } } }
public bool Store <T>(StorageItemType key, T obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj), "Cannot store null items."); } if (!Contains(key)) { _objectDictionary[key] = obj; } else { _objectDictionary.Add(key, obj); } return(true); }
public IEnumerable <IItem> Read(StorageItemType itemType) { return(this.AllItems.Where(item => item.ItemType == itemType)); }
public T Get <T>(StorageItemType key) { return((T)_objectDictionary[key]); }
public bool Contains(StorageItemType key) { return(_objectDictionary.ContainsKey(key)); }
public StorageItem(StorageItemType type) { this._storageItemType = type; }