Example #1
0
        public static AppRegistryItem GetOrCreate <T>(this AppRegistry registry) where T : new()
        {
            var itemId    = registry.CreateItemId <T>();
            var itemValue = registry.TryFindItemValue <T>(itemId);

            if (itemValue != null)
            {
                return(itemValue);
            }
            itemValue = AppRegistryItem.Create(itemId, new T()).Register(registry);
            return(itemValue);
        }
Example #2
0
        public static AppRegistryItem LoadFromFile <T>(this AppRegistry registry, bool updateSelf) where T : new()
        {
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }
            var itemId    = registry.CreateItemId <T>();
            var theSource = registry.LoadFromFile(itemId);

            if (theSource != null)
            {
                var item = registry.GetOrCreate <T>();
                if (updateSelf)
                {
                    item.Id    = theSource.Id;
                    item.Title = theSource.Title;
                    item.Group = theSource.Group;
                    item.Value = theSource.Value;
                    return(item);
                }
            }
            return(theSource);
        }