Example #1
0
        public static ControlsCache <TControl> InstanceFor(object key)
        {
            if (!SpecialInstancesCache.TryGetValue(key, out var foundInstance))
            {
                SpecialInstancesCache[key] = foundInstance = new ControlsCache <TControl>();
            }

            return(foundInstance);
        }
Example #2
0
        public void Dispose()
        {
            if (this.isDisposed)
            {
                return;
            }

            this.isDisposed = true;

            if (this.controls.Count > 0)
            {
                // there is no actual need to dispose them explicitly on scripts shutdown
                //foreach (var control in this.controls.ToList())
                //{
                //    control.Dispose();
                //}

                this.controls.Clear();
            }

            if (instance == this)
            {
                // remove from static default instance
                instance = null;
            }
            else
            {
                // remove from special instances cache
                foreach (var pair in SpecialInstancesCache)
                {
                    if (pair.Value == this)
                    {
                        SpecialInstancesCache.Remove(pair.Key);
                        break;
                    }
                }
            }
        }