添加引用
using System.Threading;
using System.Xml.Serialization;
using System.IO;
using System.Reflection;
#region 通过反序列化和反射将xml配置文档加载到类实例的公共属性 反射测试类 + 单例模式
public class SystemConfig
{
private static readonly string defaultFileName = "Test.xml";
private string _ip;
private string _port;
private static readonly object _lockobj = new object();
private static SystemConfig _instance;
public string Ip
{
get => _ip;
set => _ip = value;
}
public string Port
{
get => _port;
set => _port = value;
}
private SystemConfig()
{
}
public static SystemConfig Instance
{
get
{
lock(_lockobj)
{
if (