Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.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#_Winforms_Propertygrid - Fatal编程技术网

C# С;分类和提示不起作用

C# С;分类和提示不起作用,c#,winforms,propertygrid,C#,Winforms,Propertygrid,我在我的应用程序上有一个属性网格,我为它创建了以下类: class NginXConfig { [Browsable(true)] [ReadOnly(true)] [Category("General")] [Description("Defines the number of worker processes. Windows only supports one.")] int _worker_processes

我在我的应用程序上有一个属性网格,我为它创建了以下类:

class NginXConfig
{
    [Browsable(true)]
    [ReadOnly(true)]
    [Category("General")]
    [Description("Defines the number of worker processes. Windows only supports one.")]
    int _worker_processes = 1;
    public int worker_processes
    {
        get { return _worker_processes; }
        set { _worker_processes = value; }
    }

    [Browsable(true)]
    [ReadOnly(false)]
    [Category("General")]
    [Description("Changes the limit on the maximum number of open files (RLIMIT_NOFILE) for worker processes.")]
    int _worker_rlimit_nofile = 100000;
    public int worker_rlimit_nofile
    {
        get { return _worker_rlimit_nofile; }
        set { _worker_rlimit_nofile = value; }
    }

    [Browsable(true)]
    [ReadOnly(false)]
    [Category("General")]
    [Description("Defines the error logging level. Availble options: debug | info | notice | warn | error | crit | alert | emerg")]
    string _error_log_level = "crit";
    public string error_log_level
    {
        get { return _error_log_level; }
        set { _error_log_level = value; }
    }
}
在属性网格上,当我设置
SelectedObject
时,它呈现如下:

  • 我定义为“一般”的类别未显示。它显示为“杂项”

  • 提示
    说明
    未显示

  • 是否可以通过类定义这些字段在我的属性网格上的显示顺序

  • 编辑 这个问题现在已经解决了。这是我班的工作版本:

    class NginXConfig
    {
        [Browsable(true), ReadOnly(true), Category("General"), DefaultValueAttribute(1), Description("Defines the number of worker processes. Windows operating system supports only one.")]
        public int worker_processes { get ; set; }
    
        [Browsable(true), ReadOnly(false), Category("General"), DefaultValueAttribute(10000), Description("Changes the limit on the maximum number of open files (RLIMIT_NOFILE) for worker processes.")]
        public int worker_rlimit_nofile { get; set; }
    
        [Browsable(true), ReadOnly(false), Category("General"), DefaultValueAttribute("crit"), Description("Defines the error logging level. Availble options: debug | info | notice | warn | error | crit | alert | emerg")]
        public string error_log_level { get; set; }
    
        public NginXConfig()
        {
            worker_processes = 1;
            worker_rlimit_nofile = 10000;
            error_log_level = "crit";
        }
    }
    
    以这种方式定义:

    int _worker_processes = 1;
    
    [Browsable(true),ReadOnly(true),Category("General"),Description("Defines the number of worker processes. Windows only supports one.")]
    public int worker_processes
    {
        get { return _worker_processes; }
        set { _worker_processes = value; }
    }
    

    属性用于属性,而不是专用变量。为什么不
    {get;set;}
    而不
    int\u worker\u processes=1

    如果我使用
    {get;set;}
    如何设置默认值?@Latheesan,在C#6.0中很容易:
    public int-worker_-process{get;set;}=…
    ,如果没有它,在构造函数中。@Sinatr我正在使用C#4.5-有解决方案吗?因为,目前我正在设置如下默认值:
    NginXConfig myNginXConfig=new NginXConfig();myNginXConfig.worker_进程=1等。。。在设置
    SelectedObject
    @Latheesan之前,请按F5并查看我之前的注释。@Latheesan:在C#6之前的版本中,您可以在构造函数中设置自动属性的默认值。提示:所有值都以粗体显示,因为您没有设置
    DefaultValueAttribute
    @Sinatr,所以可以通过类定义这些字段在我的属性网格上显示的顺序吗?顺序是字母表,最简单的是给类别/属性指定合适的名称(例如“1.类别”、“2.类别”…)