SoFunction
Updated on 2025-03-07

Example of implementation of C# generating local configuration files

First create a new class named ""

Post code directly

public static ApplyInfo ApplyInfo = new ApplyInfo();
        private static XApplySetting applySetting;

        public static XApplySetting ApplySetting
        {
            get
            {
                if (applySetting == null)
                {
                    string filePath =  + "";
                    if ((filePath))
                    {
                        try
                        {
                            applySetting = <XApplySetting>(filePath, Encoding.UTF8);
                        }
                        catch
                        {
                            (filePath);
                        }
                    }


                    if (applySetting == null)
                    {
                        applySetting = applySetting ?? new XApplySetting();
                        ApplySetting = applySetting;
                    }

                }
                return applySetting;
            }

            set
            {
                string filePath = ;

                //Create a specified folder                if (!(filePath))
                    (filePath);

                filePath += "";

                (value, filePath, Encoding.UTF8);
                applySetting = value;
            }
        }

After this class is completed, create a new class named "

This class contains some variables you want to store.

Just like

public class XApplySetting
    {
        /// <summary>
        /// Program version        /// </summary>
        public int Version { get; set; }}

This is a variable, how to use it next

The value is relatively simple:

Define a variable directly

string username= ;

Next is assignment

var setting = ;
 = “admin”;
 = “123456”;
 = setting;

This is the end of this article about the implementation example of C# generated local configuration files. For more related contents of C# generated local configuration files, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!