using System.Collections.Generic; using MongoDB.Bson; namespace Common.Component { public class Object { public ObjectId Id { get; set; } public Dictionary Dict { get; private set; } protected Object() { this.Id = ObjectId.GenerateNewId(); this.Dict = new Dictionary(); } public object this[string key] { set { this.Dict[key] = value; } get { return this.Dict[key]; } } public T Get(string key) { if (!this.Dict.ContainsKey(key)) { return default(T); } return (T) this.Dict[key]; } public T Get() { return this.Get(typeof (T).Name); } public void Set(string key, object obj) { this.Dict[key] = obj; } public void Set(T obj) { this.Dict[typeof (T).Name] = obj; } public bool Contain(string key) { return this.Dict.ContainsKey(key); } public bool Remove(string key) { return this.Dict.Remove(key); } } }