Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6881225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:04:50+00:00 2026-05-27T05:04:50+00:00

For a game I’m developing on (in C#), we need to be able to

  • 0

For a game I’m developing on (in C#), we need to be able to save and load options files, and for ease of use, we decided to do it as plain text.
I have a problem however when I try to load the text back into their variables as I don’t always know what type of variable it needs to be loaded into.

The following line of code works, except for the fact that I have yet to find functionallity that resembles

f.GetType().Parse()

Heres the actual code

OptionsClass current = new OptionsClass();  
    using(StreamReader reader = new StreamReader(path)){
        string line;
        while((line = reader.ReadLine()) != null){
        foreach(FieldInfo f in typeof(OptionsClass).GetFields()){
            f.SetValue(current, f.GetType().Parse(line.Split(new char[] {'='})[1]));

        }
    }
}

Let me know if anything is unclear, or more information is needed.
Regards,
-Logan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:04:51+00:00Added an answer on May 27, 2026 at 5:04 am

    Rather than trying to do this yourself, I would suggest that you use the builtin XML or JSON serialiation.

    However, if you are going to implement this yourself, then I would suggest that you perform a switch on the type of field and convert the value according to the data type of the field. For example:

            string sValue = line.Split(new char[] {'='})[1]);
            object oValue;
            switch (f.FieldType.Name.ToLower())
            {
                case "system.string":
                   oValue = sValue;
                   break;
    
                case "system.int32":
                    oValue = Convert.ToInt32(sValue);
                    break;
             etc...
    
          f.SetValue(current, oValue);
    

    One additional note: if you are going the self-built route, then you probably want to be a little more robust in the data conversions (i.e. checking to see if the string is not null and is numeric when converting to a number, etc).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Making game of life I need to a have a grid that is 30x20
I am developing a game for android and I save the scores in a
I have a game which I use a flag variable score to keep the
I have a little game written in C#. It uses a database as back-end.
I run a game and the running is done by hand, I have a
For our online game, we have written tons of PHP classes and functions grouped
I have a simple game that is in progress. As of right now all
I have a game server than can take requests from a user. A user
In a game, I'm trying to keep a list of users and have it
I have a game, stripped down for the problem, a GameHandler class, a Game

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.