我的应用程序上有一个属性网格,我为它创建了以下类:
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
时 - 它呈现如下:
我没有显示我定义为“常规”的类别。它显示为“杂项”。
提示Description
未显示。
是否可以通过课程定义这些字段在我的媒体资源网格中的显示顺序?
此问题现已解决。这是我班级的工作版本:
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";
}
}
答案 0 :(得分:2)
以这种方式定义:
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 _worker_processes = 1;
。