例如,的EntityFramework Microsoft.EntityFrameworkCore.Relational項目在資源文件下面的文字:如何將C#資源文件字符串轉換爲方法而不僅僅是屬性?
...
<data name="FromSqlMissingColumn" xml:space="preserve">
<value>The required column '{column}' was not present in the results of a 'FromSql' operation.</value>
</data>
...
產生下面的C#代碼:
...
/// <summary>
/// The required column '{column}' was not present in the results of a 'FromSql' operation.
/// </summary>
public static string FromSqlMissingColumn([CanBeNull] object column)
{
return string.Format(CultureInfo.CurrentCulture, GetString("FromSqlMissingColumn", "column"), column);
}
...
private static string GetString(string name, params string[] formatterNames)
{
var value = _resourceManager.GetString(name);
Debug.Assert(value != null);
if (formatterNames != null)
{
for (var i = 0; i < formatterNames.Length; i++)
{
value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}");
}
}
return value;
}
...
但是,當我編輯VS文件並保存它,我只得到簡單的屬性生成,如:
...
/// <summary>
/// The required column '{column}' was not present in the results of a 'FromSql' operation.
/// </summary>
public static string FromSqlMissingColumn
{
get { return ResourceManager.GetString("FromSqlMissingColumn"); }
}
...
有問題的文件可以找到他再次:
那麼問題又來了 - 他們是怎麼做到的,我怎麼能得到相同的結果?