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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. global settings

global settings

Scheduled Pinned Locked Moved C#
helptutorialquestion
14 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.
  • E e_LA

    I thought so... Thanks for confirmation. I wondered if there is another way but I suppose not. Ela

    C Offline
    C Offline
    Colin Angus Mackay
    wrote on last edited by
    #4

    e_LA wrote:

    Thanks for confirmation. I wondered if there is another way but I suppose not.

    I just confirmed what I tend to do, and that has fit every situation that I've needed so far. There may be other ways - What kind of thing were you looking for?


    Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

    E 1 Reply Last reply
    0
    • C Colin Angus Mackay

      e_LA wrote:

      Thanks for confirmation. I wondered if there is another way but I suppose not.

      I just confirmed what I tend to do, and that has fit every situation that I've needed so far. There may be other ways - What kind of thing were you looking for?


      Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

      E Offline
      E Offline
      e_LA
      wrote on last edited by
      #5

      If I knew I wouldn't ask. I thought there is an easier way to do with global settings in Framework 2.0. Ela

      1 Reply Last reply
      0
      • C Colin Angus Mackay

        You could create a specific project for dealing with settings and then reference it from all the projects that need it. You can then access the classes from anywhere in your solution (just remember to include the namespace).


        Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

        E Offline
        E Offline
        e_LA
        wrote on last edited by
        #6

        I understand I have to create an object of settings class in each project? Ela

        C 1 Reply Last reply
        0
        • C Colin Angus Mackay

          You could create a specific project for dealing with settings and then reference it from all the projects that need it. You can then access the classes from anywhere in your solution (just remember to include the namespace).


          Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

          E Offline
          E Offline
          e_LA
          wrote on last edited by
          #7

          I think do not undrestand everything. I have many projects in solution and in almost all of them I need see global varialbes. Do I have to add a references to my "global" class with settings and create an object. There is something wrong. Ela

          C 1 Reply Last reply
          0
          • C Colin Angus Mackay

            You could create a specific project for dealing with settings and then reference it from all the projects that need it. You can then access the classes from anywhere in your solution (just remember to include the namespace).


            Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

            E Offline
            E Offline
            e_LA
            wrote on last edited by
            #8

            Colin, Could you provide me with any example for such a specific project? I have one class e.g. public class MyAppSettings : ApplicationSettingsBase { [UserScopedSetting()] [DefaultSettingValueAttribute("true")] [global::System.Configuration.ApplicationScopedSettingAttribute()] public bool someProperty { get { return (bool)this["someProperty"]; } set { this["someProperty"] = value; } } Then I have to create a project dealing with the setting. I suppose it should contain class with static properties?? Could you give me an example? Thanks Ela

            C 1 Reply Last reply
            0
            • C Colin Angus Mackay

              You could create a specific project for dealing with settings and then reference it from all the projects that need it. You can then access the classes from anywhere in your solution (just remember to include the namespace).


              Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

              E Offline
              E Offline
              e_LA
              wrote on last edited by
              #9

              ...but where to create the object of settings class?

              C 1 Reply Last reply
              0
              • E e_LA

                I understand I have to create an object of settings class in each project? Ela

                C Offline
                C Offline
                Colin Angus Mackay
                wrote on last edited by
                #10

                You can create one object only. (The class exists in a single project and it can use the singleton pattern so that only one instance of the object exists across the whole application)


                Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

                1 Reply Last reply
                0
                • E e_LA

                  I think do not undrestand everything. I have many projects in solution and in almost all of them I need see global varialbes. Do I have to add a references to my "global" class with settings and create an object. There is something wrong. Ela

                  C Offline
                  C Offline
                  Colin Angus Mackay
                  wrote on last edited by
                  #11

                  e_LA wrote:

                  Do I have to add a references to my "global" class with settings and create an object.

                  Every time you use your settings class you will need to include the namespace and reference the project that the in which the settings class resides. i.e. In the project that you wish to use the settings class you "Add Reference..." to the project that contains the settings class.


                  Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

                  1 Reply Last reply
                  0
                  • E e_LA

                    Colin, Could you provide me with any example for such a specific project? I have one class e.g. public class MyAppSettings : ApplicationSettingsBase { [UserScopedSetting()] [DefaultSettingValueAttribute("true")] [global::System.Configuration.ApplicationScopedSettingAttribute()] public bool someProperty { get { return (bool)this["someProperty"]; } set { this["someProperty"] = value; } } Then I have to create a project dealing with the setting. I suppose it should contain class with static properties?? Could you give me an example? Thanks Ela

                    C Offline
                    C Offline
                    Colin Angus Mackay
                    wrote on last edited by
                    #12

                    e_LA wrote:

                    Then I have to create a project dealing with the setting. I suppose it should contain class with static properties??

                    You can use a static class. Although I prefer to use the Singleton pattern because I can mock the class for unit testing.

                    public static MySettingsClass
                    {
                    public bool static SomeProperty
                    {
                    get
                    {
                    return this.someProperty
                    }
                    }
                    }

                    My settings classes never have setters. They are readonly.


                    Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

                    1 Reply Last reply
                    0
                    • E e_LA

                      ...but where to create the object of settings class?

                      C Offline
                      C Offline
                      Colin Angus Mackay
                      wrote on last edited by
                      #13

                      e_LA wrote:

                      but where to create the object of settings class?

                      If you are using the singleton pattern then the class itself creates the object. For example:

                      public Settings
                      {
                      // Field containing the only instance of the class
                      private static Settings onlyInstance;

                      // Private constructor so that nothing outside this class
                      // can construct it.
                      private Settings(){};
                      
                      // Property getter to return the only ever instance of the class
                      public static Instance
                      {
                          get
                          {
                              return this.onlyInstance;
                          }
                      }
                      
                      // Add your public methods and properties here
                      

                      }


                      Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

                      E 1 Reply Last reply
                      0
                      • C Colin Angus Mackay

                        e_LA wrote:

                        but where to create the object of settings class?

                        If you are using the singleton pattern then the class itself creates the object. For example:

                        public Settings
                        {
                        // Field containing the only instance of the class
                        private static Settings onlyInstance;

                        // Private constructor so that nothing outside this class
                        // can construct it.
                        private Settings(){};
                        
                        // Property getter to return the only ever instance of the class
                        public static Instance
                        {
                            get
                            {
                                return this.onlyInstance;
                            }
                        }
                        
                        // Add your public methods and properties here
                        

                        }


                        Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

                        E Offline
                        E Offline
                        e_LA
                        wrote on last edited by
                        #14

                        Colin, When I was waiting for the answer I managed to do that in such a way you explained and it works! I can make a few changes after reading you responses. Many thanks for the explanation! ...very strange this singleton pattern :-) I had problems with saving settings but I created public method in singleton and called settings save method. Redards Ela

                        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