示例#1
0
        public static T To <T>(this RelicItem item)
        {
            if (item == null)
            {
                return(default(T));
            }

            return((T)Convert.ChangeType(item.Value, typeof(T)));
        }
示例#2
0
        public void Set(string key, object value)
        {
            var item = new RelicItem {
                Key = key, Value = value
            };

            try {
                Provider.Set(key, value);
                Notifier.OnChanged(item);
            }
            catch (Exception exception) {
                Notifier.OnErrored(item, exception);
            }
        }
示例#3
0
        private void ExecuteHandlers(RelicItem item, RelicNotifyHandler tempNotifyHandler)
        {
            if (tempNotifyHandler == null)
            {
                return;
            }

            var handlerList = tempNotifyHandler.GetInvocationList();

            foreach (RelicNotifyHandler handler in handlerList)
            {
                try {
                    handler(item);
                }
                catch (Exception exception) {
                    OnErrored(item, exception);
                }
            }
        }
示例#4
0
        public void OnErrored(RelicItem item, Exception exception)
        {
            var tempHandler = Errored;

            if (tempHandler == null)
            {
                return;
            }

            var handlerList = tempHandler.GetInvocationList();

            foreach (RelicErrorHandler handler in handlerList)
            {
                try {
                    handler.BeginInvoke(item, exception, null, this);
                }
                catch {
                }
            }
        }
示例#5
0
 public void OnRemoved(RelicItem item)
 {
     ExecuteHandlers(item, Removed);
 }
示例#6
0
 public void OnChanged(RelicItem item)
 {
     ExecuteHandlers(item, Changed);
 }