示例#1
0
        private static async Task RunSetMapSamplesAsync(ISetMap <Guid, Data> setMap)
        {
            var id   = Guid.NewGuid();
            var data = new Data()
            {
                Name = "A name", Value = 5
            };

            // A SetMap is a map of sets items with special extensions methods
            // Uses an extension method that adds an item to a set in the key
            await setMap.AddItemAsync(id, data);

            var set = await setMap.GetValueOrDefaultAsync(id);

            if (await set.ContainsAsync(data))
            {
                Console.WriteLine($"The value '{data}' is present in the set");
            }

            // Removes the item from the set map
            if (await setMap.TryRemoveItemAsync(id, data))
            {
                Console.WriteLine($"The item of the set in the key '{id}' was removed");
            }
        }
示例#2
0
 protected internal virtual Task RemoveKeyAsync(string identifier, string key)
 {
     if (!ScopedMapDictionary.ContainsKey(identifier))
     {
         throw new InvalidOperationException("The scoped map must be registered before changing the scope");
     }
     return(KeysSetMap.TryRemoveItemAsync(Name, new IdentifierKey()
     {
         Identifier = identifier, Key = key
     }));
 }