Krell
Krell

Reputation: 55

How to read in multiple .settings files and pass them to a method in C#/XNA .Net

I'm trying to read it multiple settings files that I'm using as player settings. C# and XNA

They all have the exact same setup. AKA Settings1 has player1's Name, ShipType, Weapon, Shield, Color, etc... (about 100 things) Settings2 has player2's Info, Setup identically as player 1.AkA Settings1.settings Settings2.settings etc...
I'm using this because it lets me easily reference everything in VS and I can just click to add stuff and it figures out types and all that good stuff for me.

This is what I want to do

{
    System.Configuration.ApplicationSettingsBase[] playerSettings;

    playerSettings = new System.Configuration.ApplicationSettingsBase[2];

    playerSettings[0] = Settings1.Default;
    playerSettings[1] = Settings2.Default;

    string player1Name = playerSettings[0].Name;
    string player2Name = playerSettings[1].Name;
}

However. if I use this setup playerSettings[0] does not let me access the Name property.

When I go into debug I can see that PlayerSettings[0] Contains the Settings1 and inside it is the Name property. I just cant figure out how to access it in VS so I can read it in.

-       [0] {WindowsGame3.Settings1} System.Configuration.ApplicationSettingsBase {WindowsGame3.Settings1}
-       [WindowsGame3.Settings1]    {WindowsGame3.Settings1} WindowsGame3.Settings1
+       base    {WindowsGame3.Settings1} System.Configuration.ApplicationSettingsBase {WindowsGame3.Settings1} Name "sally" string

I had hoped to be able to use the system.configureation.applicationsettingsbase[] so that I could simply pass it to the method and only have to update the code there 1 time. rather then manually doing it fore each player(right now that's 4 times and its very long)

Again, these need to be the default Settings files that you can add to the project by right clicking and selecting add-new-settings.

TLDR: I need a way to access properties inside an array of System.Configuration.ApplicationSettingsBase, that is full of .settings files. OR Pass each different .settings file to a method even though they are recognized as different types Thanks

Upvotes: 1

Views: 245

Answers (1)

Avinash Singh
Avinash Singh

Reputation: 71

File.Exists sees if a specific file exists.
There are several ways of testing file existence. File.Exists is the easiest. It is the simplest way of checking that the file exists, it returns true or false.

Upvotes: 2

Related Questions