//依赖于 Microsoft.Extensions.Configuration;
// Microsoft.Extensions.Configuration.json
// Microsoft.Extensions.Configuration.ConfigurationBinder
//如果较新则复制
//字符串中不能有空格
//ssh @root 192.168.85.102
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
namespace ConnTestDemon
{
internal class Program
{
static void Main(string[] args)
{
ConfigurationBuilder cfgBuilder = new ConfigurationBuilder();
cfgBuilder.AddJsonFile("Variable.json", optional: true, reloadOnChange: true);
IConfigurationRoot configRoot = cfgBuilder.Build();
List<Variable> variables = new List<Variable>();
for (int i = 0; i < 49; i++)
{
Variable variable = configRoot.GetSection($"Variable:{i}").Get<Variable>();
variables.Add(variable);
}
foreach (var item in variables)
{
Console.WriteLine(item.VarName);
Console.WriteLine(item.VarName);
}
ConfigurationBuilder connBuilder = new ConfigurationBuilder();
connBuilder.AddJsonFile("ConnString.json", optional: true, reloadOnChange: true);
IConfigurationRoot connRoot = connBuilder.Build();
string connString = connRoot.GetSection("DbContext:MySQLConnectionString").Value;
Console.WriteLine(connString);
Console.ReadKey();
}
}
public class Variable
{
public string VarName { get; set; }
public string StoreArea { get; set; }
public string Address { get; set; }
public string DataType { get; set; }
public string IsFiling { get; set; }
public string IsAlarm { get; set; }
public string IsReport { get; set; }
public string Note { get; set; }
public string AbsoluteAddress { get; set; }
}
}
{
"DbContext": {
"ConnectionString": "server=localhost; Database=FakeXiechengDb; User Id=sa; Password=PAssword12!;",
"MySQLConnectionString": "server=192.168.85.102; database=OneToMany; uid=root; pwd=123456;"
}
}
|