BotDataEx.cs
1 using System;
2 using System.Linq;
3 using Newtonsoft.Json.Linq;
4 using System.Runtime.CompilerServices;
5 
6 namespace Microsoft.Bot.Connector
7 {
8  public partial class BotData
9  {
15  public TypeT GetProperty<TypeT>(string property)
16  {
17  if (this.Data == null)
18  this.Data = new JObject();
19 
20  dynamic data = this.Data;
21  if (data[property] == null)
22  return default(TypeT);
23 
24  // convert jToken (JArray or JObject) to the given typeT
25  return (TypeT)(data[property].ToObject(typeof(TypeT)));
26  }
27 
28 
34  public void SetProperty<TypeT>(string property, TypeT data)
35  {
36  if (this.Data == null)
37  this.Data = new JObject();
38 
39  // convert (object or array) to JToken (JObject/JArray)
40  if (data == null)
41  ((JObject)this.Data)[property] = null;
42  else
43  ((JObject)this.Data)[property] = JToken.FromObject(data);
44  }
45 
50  public void RemoveProperty(string property)
51  {
52  if (this.Data == null)
53  this.Data = new JObject();
54 
55  ((JObject)this.Data).Remove(property);
56  }
57  }
58 }
void RemoveProperty(string property)
Remove a property from the BotData record
Definition: BotDataEx.cs:50