Advertisement
Guest User

Untitled

a guest
May 25th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Configuration;
  6.  
  7. namespace settingstest
  8. {
  9.   class Program
  10.   {
  11.     static void Main(string[] args)
  12.     {
  13.       MySettings s = new MySettings();
  14.  
  15.       Console.WriteLine(s.StringValue1);
  16.  
  17.       showItems("before", s);
  18.  
  19.       int numItems = s.Items.Count;
  20.  
  21.       s.Items.Add(string.Format("item{0}", numItems));
  22.  
  23.       s.StringValue1 = "init";
  24.  
  25.       s.Save();
  26.  
  27.       showItems("after", s);
  28.     }
  29.  
  30.     private static void showItems(string title, MySettings s)
  31.     {
  32.       Console.WriteLine(title);
  33.       foreach (string str in s.Items)
  34.       {
  35.         Console.WriteLine("Item: {0}", str);
  36.       }
  37.     }
  38.   }
  39.  
  40.   class MySettings : ApplicationSettingsBase
  41.   {
  42.     public MySettings()
  43.       : base()
  44.     {
  45.       if (Items == null)
  46.         Items = new List<string>();
  47.     }
  48.  
  49.     [UserScopedSetting()]
  50.     public string StringValue1 { get; set; }
  51.  
  52.     [UserScopedSetting()]
  53.     [SettingsSerializeAs(SettingsSerializeAs.Xml)]
  54.     public List<string> Items
  55.     {
  56.       get { return (List<string>)this["Items"]; }
  57.       set { this["Items"] = value; }
  58.     }
  59.   }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement