An elegant way to store options?? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

An elegant way to store options??

phreak_coderphreak_coder Posts: 6Member
Is there a safe an elegant way i can create a class to store options, such as filenames locations, units ect ect, that can be accessed from all classes in the application?

thankyou in adavnce..

Comments

  • IDKIDK Posts: 1,784Member
    : Is there a safe an elegant way i can create a class to store options, such as filenames locations, units ect ect, that can be accessed from all classes in the application?
    :
    : thankyou in adavnce..
    :
    If you got visual c# express:
    Right click on youre project in
    the solution explorer and click
    properteries. The settings tab
    shows you what you want. It is
    safe and elegant to use.

    ===============================
    El [b]PRO[/b]grammador Niklas Ulvinge

  • dehadedehade Posts: 31Member
    : Is there a safe an elegant way i can create a class to store options, such as filenames locations, units ect ect, that can be accessed from all classes in the application?
    :
    : thankyou in adavnce..
    :

    When you need read-only access, use configuration files! But i guess you will need read/write access to your options.
    That case take a look at Isolated storage (not versioned when unsigned, versioned on major version number when signed and Can be used from partially trusted assemblies).
    To give you a head start I'll provide some code as example:

    [code]
    //storing items
    IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly();
    using(Stream stream = new IsolatedStorageFileStream("options.txt", FileMode.Create, store) {
    //Add your items to store here into the stream.
    }
    [/code]

    [code]
    //reading items
    try {
    IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly();
    using (Stream stream = new IsolatedStorageFileStream("options.txt", FileMode.Open, store) {
    //Read back your items from the stream
    }
    }
    //Don't let missing settings scare the user
    catch(Exception)
    {
    //you could set some default settings for your application here
    }
    [/code]


    dehade
Sign In or Register to comment.