【问题标题】:Asp.net From dictionary to constAsp.net 从字典到常量
【发布时间】:2018-10-28 13:16:20
【问题描述】:

我有简单的Dictionary<string, string>,其中包含 1400 多个项目。我所需要的只是生成具有> 1400个常量的新.cs文件,例如public const string KEY = Value(来自我的字典)。我该怎么做?

【问题讨论】:

  • 也许我应该使用 T4 模板?

标签: c# dictionary constants


【解决方案1】:

您可以尝试使用linq select 写入public const string {key}= {value} 值。

然后使用File.AppendAllLines 写入文件。

Dictionary<string, string> dict = new Dictionary<string, string>();
dict.Add("key1", "value1");
dict.Add("key2", "value2");
var result = dict.Select(x => $"public const string {x.Key} = {x.Value}");
File.AppendAllLines("<your file path>", result)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-05
    • 2010-10-25
    • 2011-04-20
    • 2014-06-07
    • 2011-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多