Journeyman1234
Journeyman1234

Reputation: 557

How to read Settings.Properties in Visual Studio project

I am creating a local store of semi-persistant data in a VSTO (teams and sprints)

I am using Properties.Settings.Default to dynamically create a series of StringCollection objects

I am now stuck trying to get a handle to any of these objects later when I want to add data

This is where I call TFS and read through the JSON saving the StringCollections

List<TEAMS> teams = JsonConvert.DeserializeObject<List<TEAMS>>(x);
List<TEAMS> TEAM_DATA = new List<TEAMS>();
foreach (TEAMS team in teams)
{
    //System.Diagnostics.Debug.WriteLine(team.name + " : " + team.id);
    StringCollection StringCollectionEntry = new StringCollection();
    Properties.Settings.Default.Reset();
    System.Configuration.SettingsProperty property = new System.Configuration.SettingsProperty("CustomSetting");
    property.DefaultValue = "Default";
    property.IsReadOnly = false;
    property.PropertyType = typeof(StringCollection);
    property.Name = team.name.Replace(" ", String.Empty);
    Properties.Settings.Default.Properties.Add(property);
    System.Diagnostics.Debug.WriteLine("Adding to properties " + property.Name);

    Properties.Settings.Default.Save();

    x = await Call.CallURL(baseURI + "path/teams?api-version=2.0");
    TEAM_DATA.Add(team);
}

Having done that, I can't see how to cast it to a StringCollection so I can use it later, only by this method

foreach (SettingsProperty value in Properties.Settings.Default.Properties) 
// GOING THROUGH THE LIST OF TEAMS TO ADD ITERATIONS
{
   StringCollection handler = (StringCollection)value
}

Using the Attributes.GetType() I can tell that it is a StringCollection, but this code throws an error.

Upvotes: 1

Views: 176

Answers (1)

Ehsan Ullah Nazir
Ehsan Ullah Nazir

Reputation: 1917

You are doing it with a wrong way.Create a StringCollection before foreach and add values one by one in loop.

StringCollection handler = new StringCollection();

foreach (SettingsProperty value in Properties.Settings.Default.Properties) 
{
  handler.Add(value.ToString())
}

Upvotes: 1

Related Questions