예제 #1
0
        private string GetExceptionMessage(LogicalDictionaryEvent e, K key,
                                           V newVal, V oldVal)
        {
            var msg = GetExceptionMessage_Internal(e, key, newVal, oldVal);

            if (msg != null)
            {
                return(msg);
            }

            if (e == LogicalDictionaryEvent.Add)
            {
                return($"Cannot add {newVal} for key `{key}`");
            }
            else if (e == LogicalDictionaryEvent.Change)
            {
                return($"Cannot change key `{key}` from {oldVal} to {newVal}");
            }
            else if (e == LogicalDictionaryEvent.Remove)
            {
                return($"Cannot remove key `{key}`");
            }

            return($"Unknown event {e}");
        }
예제 #2
0
        public void Validate(LogicalDictionaryEvent e, K key, V newVal = default(V), V oldVal = default(V))
        {
            Func <K, V, V, bool> validator = (k, n, o) => false;

            switch (e)
            {
            case LogicalDictionaryEvent.Add:
                validator = (k, n, o) => CanAddKey(k, n);
                break;

            case LogicalDictionaryEvent.Change:
                validator = CanChangeKey;
                break;

            case LogicalDictionaryEvent.Remove:
                validator = (k, n, o) => CanRemoveKey(k);
                break;

            default:
                break;
            }

            if (!validator(key, newVal, oldVal))
            {
                throw new InvalidOperationException(GetExceptionMessage(e, key, newVal, oldVal));
            }
        }
예제 #3
0
        protected override string GetExceptionMessage_Internal(LogicalDictionaryEvent e, string key, Type newVal, Type oldVal)
        {
            if (e == LogicalDictionaryEvent.Remove)
            {
                return("Removals not allowed for this dictionary!");
            }

            return($"Cannot change value for {key} storage engine once set!");
        }
예제 #4
0
 protected virtual string GetExceptionMessage_Internal(LogicalDictionaryEvent e, K key,
                                                       V newVal, V oldVal)
 {
     return(null);
 }