Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1bdfb24

Browse files
Added Settings Snippet
1 parent 9529430 commit 1bdfb24

File tree

9 files changed

+252
-0
lines changed

9 files changed

+252
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3+
<configSections>
4+
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
5+
<section name="CodeSamples.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
6+
<section name="CodeSamples.Properties.OtherSettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
7+
</sectionGroup>
8+
</configSections>
39
<startup>
410
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
511
</startup>
12+
<userSettings>
13+
<CodeSamples.Properties.Settings>
14+
<setting name="SettingString" serializeAs="String">
15+
<value>StringValue</value>
16+
</setting>
17+
<setting name="SettingInt" serializeAs="String">
18+
<value>0</value>
19+
</setting>
20+
</CodeSamples.Properties.Settings>
21+
<CodeSamples.Properties.OtherSettings>
22+
<setting name="SomeOtherStringSetting" serializeAs="String">
23+
<value />
24+
</setting>
25+
<setting name="SomeOtherIntSetting" serializeAs="String">
26+
<value>0</value>
27+
</setting>
28+
</CodeSamples.Properties.OtherSettings>
29+
</userSettings>
630
</configuration>

‎CSharp Code Samples/CodeSamples/CodeSamples.csproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,19 @@
8484
<Compile Include="Patterns\Behavioral\StrategyPattern.cs" />
8585
<Compile Include="Program.cs" />
8686
<Compile Include="Properties\AssemblyInfo.cs" />
87+
<Compile Include="Properties\OtherSettings.Designer.cs">
88+
<AutoGen>True</AutoGen>
89+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
90+
<DependentUpon>OtherSettings.settings</DependentUpon>
91+
</Compile>
92+
<Compile Include="Properties\Settings.Designer.cs">
93+
<AutoGen>True</AutoGen>
94+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
95+
<DependentUpon>Settings.settings</DependentUpon>
96+
</Compile>
8797
<Compile Include="SampleExecute.cs" />
98+
<Compile Include="Settings.cs" />
99+
<Compile Include="Settings\SettingsSample.cs" />
88100
<Compile Include="SOLID\S01-SingleResponsibilityPrinciple_SRP\GarageStation.cs" />
89101
<Compile Include="SOLID\S01-SingleResponsibilityPrinciple_SRP\GarageUtility.cs" />
90102
<Compile Include="SOLID\S01-SingleResponsibilityPrinciple_SRP\IGarageUtility.cs" />
@@ -114,6 +126,14 @@
114126
<ItemGroup>
115127
<None Include="App.config" />
116128
<None Include="packages.config" />
129+
<None Include="Properties\OtherSettings.settings">
130+
<Generator>SettingsSingleFileGenerator</Generator>
131+
<LastGenOutput>OtherSettings.Designer.cs</LastGenOutput>
132+
</None>
133+
<None Include="Properties\Settings.settings">
134+
<Generator>SettingsSingleFileGenerator</Generator>
135+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
136+
</None>
117137
</ItemGroup>
118138
<ItemGroup />
119139
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

‎CSharp Code Samples/CodeSamples/Program.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using CodeSamples.Exceptions;
88
using CodeSamples.MultiThreading;
99
using CodeSamples.Patterns;
10+
using CodeSamples.Settings;
1011
using CodeSamples.SOLID.S01_SingleResponsibilityPrinciple_SRP;
1112
using CodeSamples.SOLID.S04_InversionOfControl_IoC;
1213
using CodeSamples.SyntacticSugars;
@@ -165,6 +166,11 @@ static void Main(string[] args)
165166
exceptionsSample.Execute();
166167
#endregion
167168

169+
#region Settings
170+
var settingsSample = new SettingsSample();
171+
settingsSample.Execute();
172+
#endregion
173+
168174
Console.WriteLine();
169175
Console.WriteLine("End Code Samples");
170176

‎CSharp Code Samples/CodeSamples/Properties/OtherSettings.Designer.cs

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="CodeSamples.Properties" GeneratedClassName="OtherSettings">
3+
<Profiles />
4+
<Settings>
5+
<Setting Name="SomeOtherStringSetting" Type="System.String" Scope="User">
6+
<Value Profile="(Default)" />
7+
</Setting>
8+
<Setting Name="SomeOtherIntSetting" Type="System.Int32" Scope="User">
9+
<Value Profile="(Default)">0</Value>
10+
</Setting>
11+
</Settings>
12+
</SettingsFile>

‎CSharp Code Samples/CodeSamples/Properties/Settings.Designer.cs

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="CodeSamples.Properties" GeneratedClassName="Settings">
3+
<Profiles />
4+
<Settings>
5+
<Setting Name="SettingString" Type="System.String" Scope="User">
6+
<Value Profile="(Default)">StringValue</Value>
7+
</Setting>
8+
<Setting Name="SettingInt" Type="System.Int32" Scope="User">
9+
<Value Profile="(Default)">0</Value>
10+
</Setting>
11+
</Settings>
12+
</SettingsFile>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace CodeSamples.Properties {
2+
3+
4+
// This class allows you to handle specific events on the settings class:
5+
// The SettingChanging event is raised before a setting's value is changed.
6+
// The PropertyChanged event is raised after a setting's value is changed.
7+
// The SettingsLoaded event is raised after the setting values are loaded.
8+
// The SettingsSaving event is raised before the setting values are saved.
9+
internal sealed partial class Settings {
10+
11+
public Settings() {
12+
// // To add event handlers for saving and changing settings, uncomment the lines below:
13+
//
14+
// this.SettingChanging += this.SettingChangingEventHandler;
15+
//
16+
// this.SettingsSaving += this.SettingsSavingEventHandler;
17+
//
18+
}
19+
20+
private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
21+
// Add code to handle the SettingChangingEvent event here.
22+
}
23+
24+
private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
25+
// Add code to handle the SettingsSaving event here.
26+
}
27+
}
28+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CodeSamples.Settings
8+
{
9+
public class SettingsSample : SampleExecute
10+
{
11+
private void LoadMainSettings()
12+
{
13+
Console.WriteLine($"SettingString = {Properties.Settings.Default.SettingString}");
14+
Console.WriteLine($"SettingInt = {Properties.Settings.Default.SettingInt}");
15+
}
16+
17+
private void LoadOtherSettings()
18+
{
19+
Console.WriteLine($"SomeOtherStringSetting = {Properties.OtherSettings.Default.SomeOtherStringSetting}");
20+
Console.WriteLine($"SomeOtherIntSetting = {Properties.OtherSettings.Default.SomeOtherIntSetting}");
21+
}
22+
23+
private void StoreMainSettings()
24+
{
25+
Properties.Settings.Default.SettingString = DateTime.Now.ToString();
26+
Properties.Settings.Default.SettingInt = DateTime.Now.Second;
27+
Properties.Settings.Default.Save();
28+
}
29+
30+
private void StoreOtherSettings()
31+
{
32+
Properties.OtherSettings.Default.SomeOtherStringSetting = DateTime.Now.ToString();
33+
Properties.OtherSettings.Default.SomeOtherIntSetting = DateTime.Now.Second;
34+
Properties.OtherSettings.Default.Save();
35+
}
36+
37+
public override void Execute()
38+
{
39+
Title("SettingsSampleExecute");
40+
41+
StoreMainSettings();
42+
StoreOtherSettings();
43+
44+
LoadMainSettings();
45+
LoadOtherSettings();
46+
47+
Finish();
48+
}
49+
}
50+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /