显示自定义对象的常量,类似于MessageBoxButtons
本文关键字:类似于 MessageBoxButtons 常量 自定义 对象 显示 | 更新日期: 2023-09-27 18:14:16
好的,所以我有一个奇怪的问题-我不确定我的措辞是否正确,这可能就是为什么我在搜索中没有找到任何关于这方面的信息。
我有一个类定义了一个Host对象,该对象表示一台记录了关于该计算机的各种信息的计算机。
public sealed class Host
{
public Host(string sName, IPAddress sAddress, string sType, string osName, bool sFirewall)
{
Name = sName;
Address = sAddress;
Type = sType;
FirewallActive = sFirewall;
OperatingSystem = osName;
}
public Host()
{
Name = "New Host";
Address = IPAddress.Parse("127.0.0.1");
Type = HostType.Desktop;
OperatingSystem = HostOS.Win7;
FirewallActive = true;
}
/// <summary>
/// The name of the host
/// </summary>
public string Name { get; private set; }
/// <summary>
/// The ip address of the host
/// </summary>
public IPAddress Address { get; private set; }
/// <summary>
/// The type of the host
/// </summary>
public string Type { get; private set; }
/// <summary>
/// The operating system the system uses
/// </summary>
public string OperatingSystem { get; private set; }
/// <summary>
/// Whether the system has a firewall enabled
/// </summary>
public bool FirewallActive { get; private set; }
}
然后我有一对具有恒定值的一对对象用于一对设置。
public sealed class HostType
{
public static string Desktop
{
get { return "Desktop"; }
}
}
public sealed class HostOS
{
public static string Win7
{
get { return "Windows 7"; }
}
}
当我创建一个新的Host对象时,我希望智能感知在构造一个新的Hosts([parameters])对象时自动提示一个"HostOS"变量,类似于当你使用MessageBox.Show(…)时,它会自动建议一个各种MessageBoxButtons选项的列表,当你到达参数列表的那一部分。
同样,我不想修改列表——我只想让智能感知显示一个选项列表,这些选项是各种HostOS常量字符串。
您应该将其定义为枚举而不是类。
例如:public enum HostType
{
Desktop,
Server,
Laptop
}
在host类中,必须将属性Type定义为HostType
public HostType Type { get; private set }