Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

IBotDataBagExtensions.cs 1.0 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  1. namespace ContosoFlowers.BotAssets.Extensions
  2. {
  3. using System;
  4. using Microsoft.Bot.Builder.Dialogs;
  5. public static class IBotDataBagExtensions
  6. {
  7. /// <summary>
  8. /// Retrieves, initializes and manipulates an IBotDataBag value.
  9. /// </summary>
  10. /// <typeparam name="T">The generic type of the value to be retrieved or initialized. Must allow new().</typeparam>
  11. /// <param name="botDataBag"> UserData, ConversationData or PrivateConversationData.</param>
  12. /// <param name="key">The key of the value to get.</param>
  13. /// <param name="updateAction">A lamba Action<T> to manipulate the retrieve or new value to save.</param>
  14. public static void UpdateValue<T>(this IBotDataBag botDataBag, string key, Action<T> updateAction) where T : new()
  15. {
  16. T value = default(T);
  17. if (!botDataBag.TryGetValue(key, out value))
  18. {
  19. value = new T();
  20. }
  21. updateAction(value);
  22. botDataBag.SetValue(key, value);
  23. }
  24. }
  25. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...