C#C
C#3y ago
ana

❔ ✅ Using a list

I am writing a program in which you can save configurations, which would save if a specific feature is enabled, and if it is, write "whatever=true".

public class ConfigManager
{
    FeatureManager featureManager = new FeatureManager();
    StreamWriter sw = new StreamWriter(ConfigFile);

    public void writeConfig()
    {
         foreach (Feature feature in featureManager.getRegistered())
         {
                sw.WriteLine(feature.getName() + "=" + feature.isEnabled());
         }
     }
}

I am using this code to try and write text to a config file, and ConfigFile variable is a path. FeatureManager code:
    public class FeatureManager
    {
        public List<Feature> registered = new List<Feature>();

        public void init()
        {
            register(new AutoTyper());
            register(new AntiLag());
            register(new AntiMail());
        }

        protected void register(Feature feature)
        {
            registered.Add(feature);
        }

        public List<Feature> getRegistered()
        {
            return registered;
        }
    }


And a feature:

    public class AutoTyper : Feature
    {

        public AutoTyper() : base("AutoTyper", "Automatically type stuff", Category.Casino) { }
                                  // ^ NAME       ^ DESCRIPTION            ^ CATEGORY

        // Here would be the feature's actual feature. For this, unneeded.
    }


This code has no errors, but the items (features) in the registered List aren't recognized in the writeConfig method. (Meaning, when writing config it thinks there is no items, even though they were added)

The output i want into the ConfigFile:
AutoTyper=true
AntiLag=true  //these don't actually have to be true, but an output like this depending whether they are enabled or not
AntiMail=true


Hopefully this is understandable, and someone can help :D
Was this page helpful?