Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can I do the following...

How can I do the following...

Scheduled Pinned Locked Moved C#
jsonquestiontoolsxmllearning
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    profoundwhispers
    wrote on last edited by
    #1

    I have an application, that needs to have a settings dialog. I want the settings to be available to the rest of the application all the time, even when the settings dialog is closed. In other words, this dialog is merely a utility for the user to modify these settings and save them. I'm thinking, I should have the settings struct, so that it's a value type, which doesn't need instantiation to be used, and be available all through the application lifetime. Now the challenges are: 1- What's the best method to load/save this struct? Can XML serialization work here? If so, how? 2- Can I bind the struct's fields/properties to controls on the settings dialog, so that any modification will automatically reflect in the struct, which, in turn is the one responsible for actually loading/saving all the settings? Thank you. Sammy "A good friend, is like a good book: the inside is better than the cover..."

    H 1 Reply Last reply
    0
    • P profoundwhispers

      I have an application, that needs to have a settings dialog. I want the settings to be available to the rest of the application all the time, even when the settings dialog is closed. In other words, this dialog is merely a utility for the user to modify these settings and save them. I'm thinking, I should have the settings struct, so that it's a value type, which doesn't need instantiation to be used, and be available all through the application lifetime. Now the challenges are: 1- What's the best method to load/save this struct? Can XML serialization work here? If so, how? 2- Can I bind the struct's fields/properties to controls on the settings dialog, so that any modification will automatically reflect in the struct, which, in turn is the one responsible for actually loading/saving all the settings? Thank you. Sammy "A good friend, is like a good book: the inside is better than the cover..."

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      A singleton pattern works well for this. We use a PropertyGrid for the time being in our application. I create a singleton that uses a collection of classes implementing the ICustomTypeDescriptor and gets everything from a database. The application allows the changing of these values while callers throughout our application have a simple means to get these values. Just put the classes in an assembly that is shared and used by all the assemblies in your application. I put ours, for example, in our toolkit assembly. XML Serialization would be a good way to read and save your preferences. Just see the System.Xml.Serialization namespace for all the attributes you can use, as well as the XmlSerializer that does include a sample of how to use it. It's really very simple.

      Microsoft MVP, Visual C# My Articles

      P 1 Reply Last reply
      0
      • H Heath Stewart

        A singleton pattern works well for this. We use a PropertyGrid for the time being in our application. I create a singleton that uses a collection of classes implementing the ICustomTypeDescriptor and gets everything from a database. The application allows the changing of these values while callers throughout our application have a simple means to get these values. Just put the classes in an assembly that is shared and used by all the assemblies in your application. I put ours, for example, in our toolkit assembly. XML Serialization would be a good way to read and save your preferences. Just see the System.Xml.Serialization namespace for all the attributes you can use, as well as the XmlSerializer that does include a sample of how to use it. It's really very simple.

        Microsoft MVP, Visual C# My Articles

        P Offline
        P Offline
        profoundwhispers
        wrote on last edited by
        #3

        Heath Stewart wrote: singleton pattern I'm sorry, but I don't know what that is :( Heath Stewart wrote: Just put the classes in an assembly... So you do suggest classes instead of structs? I read in an article on CodeProject before by Nishant that whenever you find that you're using a class merely to store values, it's better to use a struct. Comments? Sammy "A good friend, is like a good book: the inside is better than the cover..."

        H 1 Reply Last reply
        0
        • P profoundwhispers

          Heath Stewart wrote: singleton pattern I'm sorry, but I don't know what that is :( Heath Stewart wrote: Just put the classes in an assembly... So you do suggest classes instead of structs? I read in an article on CodeProject before by Nishant that whenever you find that you're using a class merely to store values, it's better to use a struct. Comments? Sammy "A good friend, is like a good book: the inside is better than the cover..."

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          A singleton is a single instance of an object. You can either use a simple approach like:

          public sealed class MySingleton
          {
          private static MySingleton instance;
          private int i;
          private MySingleton()
          {
          i = 1;
          }
          public static MySingleton Instance // Often private, though
          {
          get
          {
          if (instance == null)
          lock (typeof(MySingleton))
          if (instance == null)
          instance = new MySingleton();
          return instance;
          }
          }
          public static int SomeMethod()
          {
          return Instance.i; // Use Instance, not instance to make sure it's init'd.
          }
          }

          Or you could use a ContextBoundObject with its own RealProxy derivative that returns the same instance when someone tries to instantiate your object.

          Microsoft MVP, Visual C# My Articles

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups