Data query file Settings

Asked

Viewed 71 times

0

I have some projects in my Solution and in one of them I will have the Settings configured with some parameters.

My question is: If I reference this project in others, I can read these parameters in each project?

2 answers

1


You basically have two options:

  • If you want to expose all properties defined in settings, you can change the class modifier Settings of internal for public
  • If nay want to expose all properties defined in settings, you can create a class to implement encapsulation. Ex:

    public class AcessoAoSettings 
    {
        public Propriedade1 
        { 
            get 
            {
                return Properties.Settings.Default.Propriedade1;
            }
            set
            {
                Properties.Settings.Default.Propriedade1 = value;
            }
        }
    
        public Propriedade2 
        { 
            get 
            {
                return Properties.Settings.Default.Propriedade2;
            }
            private set;
        }
    }
    

I particularly prefer the second option because if you want, you can control the write access (in this code, the Propriedade2 does this by leaving the set as private).

1

You can use the feature "Copy As Link".
In your project B, go to the option to add an existing item, and choose the project A configuration file and add as a link. See the images:

Add > Existing Item... Add As Link

See also.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.