Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.