一个属性参数必须是恒定的前pression,的属性参数类型枚举描述的typeof EX pression或数组创建EX pression属性、参数、数组、类型

2023-09-04 23:52:00 作者:弯月

我想有一个枚举的描述从RESX文件拉升,但我得到上述错误。

下面是我的code:

 公开枚举FinalStatus
{
    [说明(StringResources.MyStrings.Status_0)
    错误= 0,
    [说明(StringResources.MyStrings.Status_1)
    OK = 1,
    [说明(StringResources.MyStrings.Status_5)
    警告= 2,
    [说明(StringResources.MyStrings.Status_4)
    未知= 3
}
 

解决方案

该错误是正确的;这些值需要是常数。你需要改变你的 Status_n 定义,以更多的东西是这样的:

 命名空间StringResources {
    公共类MyStrings {
        公共常量字符串Status_0 =0;
        公共常量字符串Status_1 =1;
        公共常量字符串Status_4 =4;
        公共常量字符串Status_5 =5;
    }
}
 
在VB中如何操作把SQL数据表中的一条记录值的某几个属性值 数据类型相同 组合成一个数组

I am trying to have the Description of an enum pulled from the resx file, but I get the above error.

Here is my code:

public enum FinalStatus
{
    [Description(StringResources.MyStrings.Status_0)]
    Error = 0,
    [Description(StringResources.MyStrings.Status_1)]
    Ok = 1,
    [Description(StringResources.MyStrings.Status_5)]
    Warning = 2,
    [Description(StringResources.MyStrings.Status_4)]
    Unknown = 3
}

解决方案

The error is correct; these values need to be constants. You'll need to change your Status_n definitions to something more like this:

namespace StringResources{
    public class MyStrings{
        public const string Status_0 = "0";
        public const string Status_1 = "1";
        public const string Status_4 = "4";
        public const string Status_5 = "5";
    }
}

 
精彩推荐
图片推荐