Opdracht 4a
This commit is contained in:
parent
bb30997ece
commit
3ee4691a14
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.1" />
|
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.1" />
|
||||||
|
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -12,6 +12,7 @@ namespace OOP_Opdracht_CSharp_Alfa_2022
|
|||||||
Opdracht2();
|
Opdracht2();
|
||||||
Opdracht3();
|
Opdracht3();
|
||||||
Opdracht3c();
|
Opdracht3c();
|
||||||
|
Opdracht4();
|
||||||
}
|
}
|
||||||
static void Opdracht2()
|
static void Opdracht2()
|
||||||
{
|
{
|
||||||
@ -43,7 +44,6 @@ namespace OOP_Opdracht_CSharp_Alfa_2022
|
|||||||
Console.WriteLine($"Trying to fetch KeyValue with invalid id 5 {publisher.find(7)}"); // Attempt to find invalid record and output to Console
|
Console.WriteLine($"Trying to fetch KeyValue with invalid id 5 {publisher.find(7)}"); // Attempt to find invalid record and output to Console
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void Opdracht3c()
|
static void Opdracht3c()
|
||||||
{
|
{
|
||||||
Publisher publisher = new Publisher("publisher"); // Init publisher class instance
|
Publisher publisher = new Publisher("publisher"); // Init publisher class instance
|
||||||
@ -74,5 +74,8 @@ namespace OOP_Opdracht_CSharp_Alfa_2022
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static void Opdracht4(){
|
||||||
|
Config config = Config.getInstance();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,47 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Configuration;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
|
||||||
|
class Config{
|
||||||
|
|
||||||
|
private static Config instance = null;
|
||||||
|
private Dictionary<string,string> contents;
|
||||||
|
private Config(){
|
||||||
|
contents = GetSettings();
|
||||||
|
}
|
||||||
|
public static Config getInstance(){
|
||||||
|
if ( instance == null ) instance = new Config();
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
Dictionary <string,string> GetSettings()
|
||||||
|
{
|
||||||
|
Dictionary<string,string> settings = new Dictionary<string, string>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var appSettings = ConfigurationManager.AppSettings;
|
||||||
|
if (appSettings.Count == 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("AppSettings is empty.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var keys = appSettings.AllKeys;
|
||||||
|
foreach(string key in keys){
|
||||||
|
String value = appSettings.GetValues(key).GetValue(0).ToString();
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine($"Debug: key {key} has value {value}");
|
||||||
|
#endif
|
||||||
|
settings.Add(key,value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (ConfigurationErrorsException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error reading app settings");
|
||||||
|
}
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user