예제 #1
0
        private bool TryGetTemporaryContext <T>(Type drawerType, string key, out TemporaryPropertyContext <T> context, out bool isNew)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            if (drawerType == null)
            {
                throw new ArgumentNullException("drawerType");
            }

            var contexts = this.GetCurrentTemporaryContexts();

            ITemporaryContext value;

            if (contexts.TryGetInnerValue(drawerType, key, out value))
            {
                isNew   = false;
                context = value as TemporaryPropertyContext <T>;

                if (context == null)
                {
                    throw new InvalidOperationException("Tried to get temporary property of type " + typeof(T).GetNiceName() + " with key " + key + " for drawer " + drawerType.GetNiceName() + " on property at path " + this.property.Path + ", but a temporary property for the same drawer type, of a different value type (" + value.GetType().GetArgumentsOfInheritedOpenGenericClass(typeof(PropertyContext <>))[0].GetNiceName() + ") already existed with the same key.");
                }
            }
            else
            {
                isNew   = true;
                context = new TemporaryPropertyContext <T>();
                contexts[drawerType][key] = context;
            }

            return(true);
        }
예제 #2
0
        private bool TryGetGlobalTemporaryConfig <T>(string key, out TemporaryPropertyContext <T> context, out bool isNew)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            context = null;
            ITemporaryContext value;

            if (this.globalTemporaryContexts == null)
            {
                this.globalTemporaryContexts = new Dictionary <string, ITemporaryContext>();
            }

            var contexts = this.globalTemporaryContexts;

            if (contexts.TryGetValue(key, out value))
            {
                isNew   = false;
                context = value as TemporaryPropertyContext <T>;

                if (context == null)
                {
                    throw new InvalidOperationException("Tried to get global property of type " + typeof(T).GetNiceName() + " with key " + key + " on property at path " + this.property.Path + ", but a global property of a different type (" + value.GetType().GetArgumentsOfInheritedOpenGenericClass(typeof(PropertyContext <>))[0].GetNiceName() + ") already existed with the same key.");
                }
            }
            else
            {
                isNew         = true;
                context       = new TemporaryPropertyContext <T>();
                contexts[key] = context;
            }

            return(true);
        }