Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 本地化一长串描述_C# - Fatal编程技术网

C# 本地化一长串描述

C# 本地化一长串描述,c#,C#,我有一个班级,有十几行句子1,句子2等等。它们包含我想本地化的描述性部分。我的解决方案是否正确(我的意思不仅是工作,而且您是否看到任何代码气味) [可序列化] 公共类结果类型:ISerializable,IEquatable { public int IDResultType{get;set;} 公共字符串ResultName{get;set;} 公共字符串ResultSymbol{get;set;} 公共bool IsTeam{get;set;} 公共字符串组{get;set;} public

我有一个班级,有十几行句子1,句子2等等。它们包含我想本地化的描述性部分。我的解决方案是否正确(我的意思不仅是工作,而且您是否看到任何代码气味)

[可序列化]
公共类结果类型:ISerializable,IEquatable
{
public int IDResultType{get;set;}
公共字符串ResultName{get;set;}
公共字符串ResultSymbol{get;set;}
公共bool IsTeam{get;set;}
公共字符串组{get;set;}
public static ResultType Sentence1=新的ResultType(1,Resource.Sentence1,“FT1”);
public static ResultType Sentence2=新的ResultType(2,Resource.Sentence2,“FT2”);
public static ResultType Sentence3=新的ResultType(3,Resource.Sentence3,“FT3”);
}
缺点:

  • (如果不可变。)语言在启动时选择,以后不能更改
  • 封装被破坏,任何人都可以更改静态实例及其属性
  • 语言选择是不可预测的。以这种方式构造静态实例时,运行时可以选择在设置语言之前调用静态字段的构造函数。(可以通过添加显式静态构造函数进行修复。)

在一个简单的应用程序中,这可能就足够了。在更复杂的应用程序中,我宁愿添加静态属性。如果垃圾成为问题,可以缓存值。

谢谢你的回答,但我不能完全理解。形容词mutable指的是什么?参见
ResultType
可以通过任何代码进行外部更改,它的静态字段也可以更改。啊,你是说整个类ResultType可以声明为不可变的?如果你不打算更改实例,可以使该类不可变。列出的第二个问题将得到解决。此外,如果只使用静态字段/属性中的实例,可以将构造函数设为私有。
[Serializable]
public class ResultType : ISerializable, IEquatable<ResultType>
{
    public int IDResultType { get; set; }
    public string ResultName { get; set; }
    public string ResultSymbol { get; set; }
    public bool IsTeam { get; set; }
    public string Group { get; set; }

public static ResultType Sentence1 = new ResultType(1, Resource.Sentence1, "FT1");

public static ResultType Sentence2 = new ResultType(2, Resource.Sentence2, "FT2");

public static ResultType Sentence3 = new ResultType(3, Resource.Sentence3, "FT3");
}