| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using System.Collections.Generic;
- using MongoDB.Bson.Serialization.Attributes;
- namespace Model
- {
- /// <summary>
- /// Key Value组件用于保存一些数据
- /// </summary>
- public class KVComponent: Component
- {
- [BsonElement]
- private readonly Dictionary<string, object> kv = new Dictionary<string, object>();
- public void Add(string key, object value)
- {
- this.kv.Add(key, value);
- }
- public void Remove(string key)
- {
- this.kv.Remove(key);
- }
- public T Get<T>(string key)
- {
- object k;
- if (!this.kv.TryGetValue(key, out k))
- {
- return default(T);
- }
- return (T) k;
- }
- public override void Dispose()
- {
- if (this.Id == 0)
- {
- return;
- }
- base.Dispose();
- }
- }
- }
|