export class Dictionary { private items: { [index: string]: T } = {}; private count = 0; public Clear() { this.Keys().forEach(key => this.Remove(key)); this.count = 0; } public ContainsKey(key: string): boolean { return this.items.hasOwnProperty(key); } public Count(): number { return this.count; } public Add(key: string, value: T): void { if (!this.items.hasOwnProperty(key)) { this.count++; } this.items[key] = value; } public Remove(key: string): T { const val = this.items[key]; delete this.items[key]; this.count--; return val; } public Item(key: string): T { return this.items[key]; } public Keys(): string[] { const keySet: string[] = Object.keys(this.items); for (const prop in this.items) { if (this.items.hasOwnProperty(prop)) { keySet.push(prop); } } return keySet; } public Values(): T[] { const values: T[] = []; for (const prop in this.items) { if (this.items.hasOwnProperty(prop)) { values.push(this.items[prop]); } } return values; } public toObject(): any { return this.items; } constructor(private _type: new () => T) { } get type(): T { return new this._type(); } }