如何立即将所有节的值上课?

时间:2019-03-14 11:04:45

标签: c# asp.net asp.net-core

我以前是这样获取配置值的:

public Startup(IConfiguration Configuration)
  {
   GraphDBL.Config.Uri = Configuration.GetSection("neo4j:host").Value;
   GraphDBL.Config.UserName = Configuration.GetSection("neo4j:user_name").Value;
   GraphDBL.Config.Password = Configuration.GetSection("neo4j:password").Value;
  }

我的Config类`

public class Config
{
    public static string Uri { get; set; }
    public static string UserName { get; set; }
    public static string Password { get; set; }
}

如何在一个过程中获得此结果?不会呢?

2 个答案:

答案 0 :(得分:0)

如果您检查IConfigurationSection,则会看到它具有Value属性,可用于获取值。

您必须使用如下冒号将完整路径指定为GetSection的参数:

GetSection("neo4j:host").Value

答案 1 :(得分:0)

您需要添加SELECT * FROM ( SELECT [Order], Dept, Area, [Final Week], Total FROM dbo.DeptSummary10Weeks ) AS SourceTable PIVOT (Sum(Total) FOR [Final Week] IN (SELECT WeekNum FROM dbo.[10Weeks]) AS PivotTable; 软件包才能使用Microsoft.Extensions.Configuration.Binder扩展方法。

要将部分映射到类,您需要具有与配置名称相同的属性

GetValue

并获得这样的配置

public class Conf
{
    public string Host { get; set; }

    public string User_Name { get; set; }

    public string Password { get; set; }
}

或者,如果您不想更改属性名称,可以使用this trick

GraphDBL.Config = Configuration.GetSection("neo4j").Get<Config>();

并获取配置

public class Config
{
    private string host { get; set; }
    private string user_name { get; set; }

    public string Uri
    {
        get
        {
            return host;
        }
        set
        {
            host = value;
        }
    }


    public string UserName
    {
        get { return user_name; }
        set
        {
            user_name = value;
        }
    }

    public string Password { get; set; }
}