Esempio n. 1
0
        public static void RemoveValue(this IBotData botData, DataStoreKey key)
        {
            DataStoreEntryAttribute attribute = key.GetDataStoreEntry();

            if (attribute != null)
            {
                switch (attribute.DataStore)
                {
                case DataStore.User:
                    botData.UserData.RemoveValue(key.GetKey());
                    break;

                case DataStore.Conversation:
                    botData.ConversationData.RemoveValue(key.GetKey());
                    break;

                case DataStore.PrivateConversation:
                    botData.PrivateConversationData.RemoveValue(key.GetKey());
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Esempio n. 2
0
        public static T GetValueOrDefault <T>(this IBotData botData, DataStoreKey key, T defaultValue = default(T))
        {
            DataStoreEntryAttribute attribute = key.GetDataStoreEntry();

            if (attribute != null)
            {
                switch (attribute.DataStore)
                {
                case DataStore.User:
                    return(botData.UserData.GetValueOrDefault(key.GetKey(), defaultValue));

                case DataStore.Conversation:
                    return(botData.ConversationData.GetValueOrDefault(key.GetKey(), defaultValue));

                case DataStore.PrivateConversation:
                    return(botData.PrivateConversationData.GetValueOrDefault(key.GetKey(), defaultValue));

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(defaultValue);
        }