I have a static class:
public static class ConfigurationDetails
{
public static string SharepointServer { get; set; }
public static string Username { get; set; }
public static string Password { get; set; }
public static string SharepointDomain { get; set; }
public static string ServiceLibrary { get; set; }
public static string SqlServer { get; set; }
public static string SQLUsername { get; set; }
public static string SQLPassword { get; set; }
public static string SQLDomain { get; set; }
}
which needs to be updated from the values of a dictionary.
Using if the code is below:
var configValues = ReadConfiguration();
if (configValues.ContainsKey("SharepointServer"))
{
ConfigurationDetails.SharepointServer = configValues["SharepointServer"];
}
if (configValues.ContainsKey("ServiceLibrary"))
{
ConfigurationDetails.ServiceLibrary = configValues["ServiceLibrary"];
}
if (configValues.ContainsKey("Username"))
{
ConfigurationDetails.Username = configValues["Username"];
}
if (configValues.ContainsKey("Password"))
{
ConfigurationDetails.Password= configValues["Password"];
}
Now this will do the job, but there would be a lot of if
s. I've tried with LINQ, but this is the closest I've gotten:
configValues.Where(kv => kv.Key == "SharepointServer").ToList().ForEach(kv => ConfigurationDetails.SharepointServer = kv.Value);
and it's not doing any good. Any other ideas, please?