Ejemplo n.º 1
0
        /// <summary />
        public void Load(object target)
        {
            // preconditions

            Argument.IsNotNull("target", target);

            // implementation

            Type myType = target.GetType();
            Type attribType = typeof(PersistableAttribute);

            IsolatedLocalSettings settings = new IsolatedLocalSettings(myType.Name + ".settings");
            IsolatedRemoteSettings remote = new IsolatedRemoteSettings(myType);

            if (settings.Count > 0)
            {
                foreach (PropertyInfo p in myType.GetProperties())
                {
                    // should automatically cast to a persistable attribute.
                    foreach (PersistableAttribute attribute in p.GetCustomAttributes(attribType, true))
                    {
                        string key = attribute.SettingsKey;
                        if (string.IsNullOrEmpty(key))
                        {
                            key = p.Name;
                        }

                        if (settings.Contains(key))
                        {
                            p.SetValue(target, settings[key], null);
                        }

                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary />
        public void Save(object target)
        {
            // preconditions

            Argument.IsNotNull("target", target);

            // implementation

            Type myType = target.GetType();
            Type attribType = typeof(PersistableAttribute);

            IsolatedLocalSettings local = new IsolatedLocalSettings(myType.Name + ".settings");
            IsolatedRemoteSettings remote = new IsolatedRemoteSettings(myType);

            foreach (PropertyInfo p in myType.GetProperties())
            {
                // should automatically cast to a persistable attribute.
                foreach (PersistableAttribute attribute in p.GetCustomAttributes(attribType, true))
                {
                    string key = attribute.SettingsKey;
                    if (string.IsNullOrEmpty(key))
                    {
                        key = p.Name;
                    }

                    // save name / value pair in settings store.
                    object value = p.GetValue(target, null);

                    if (local.Contains(key))
                    {
                        local[key] = value;
                    }
                    else
                    {
                        local.Add(key, value);
                    }

                    break;
                }
            }

            local.Save();
            remote.Save();
        }