namespace Bot.Models
{
public class Dialog
{
internal static string Name { get; set; }
internal static string Culture { get; set; }
//Returns the rsource file name.culture.resx
internal static string ResourceFile { get { return $"{System.AppDomain.CurrentDomain.BaseDirectory}Properties\\{Name}.
{Culture}.resx"; } }
}
}
构造一个从文件中检索资源的方法:
// You can do this in-line, just remember to reset your resex if you change the file
internal static string GetStrRes(string resourceStr)
{
//Gets your resource file
System.Resources.ResXResourceSet resxSet = new System.Resources.ResXResourceSet(Models.Dialog.ResourceFile);
string response = resxSet.GetString(resourceStr);
return response;
}
1 回答
我曾用同样的想法问了一个类似的问题(here.)基本上C#意味着与一个Resources.resx一起使用,你可以将它培养出来 . 根据我从所有狩猎中收集到的内容,您有两种选择:将其全部放在一个文件中(如workersWelcomeText和employeeWelcomeText)或创建多个resx文件并构建模型来处理它们并返回所需的资源文件:
模型(不是必需的,但是很好的做法):
构造一个从文件中检索资源的方法:
设置模型参数:
要使用该模型: