我有这样的代码
if(Data.ResourcePolicy == null)
SubItems.Add(ResourcePolicyAvailSystemsLVI.m_nullString);
else
SubItems.Add(Data.ResourcePolicy.Name);
if (Data.AgentVersion == null || Data.AgentVersion.Equals("0.0.0.0"))
SubItems.Add(ResourcePolicySystemsControl.m_nullVersion);
else
SubItems.Add(Data.AgentVersion);
SubItems.Add(Data.AgentState.ToString());
我只需要在Data.ResourcePolicy == null,if(Data.ResourcePolicy == null)和Data.AgentVersion!= null时显示ResourcePolicyAvailSystemsLVI.m_nullString然后我应该显示ResourcePolicyAvailSystemsLVI.unknown 我将如何实现这一目标,
答案 0 :(得分:1)
如果这是你的意思?
bool isNullVersion=(Data.AgentVersion ?? "0.0.0.0") == "0.0.0.0";
string policy= isNullVersion ?
ResourcePolicyAvailSystemsLVI.m_nullString :
ResourcePolicyAvailSystemsLVI.unknown;
if (Data.ResourcePolicy !=null) policy=Data.ResourcePolicy.Name;
SubItems.Add(policy);
SubItems.Add(isNullVersion ?
ResourcePolicySystemsControl.m_nullVersion :
Data.AgentVersion
);
SubItems.Add(Data.AgentState.ToString());
答案 1 :(得分:1)
数据类的范围:
public class DataClass
{
//....
public string ResourcePolicyName
{
get { return ResourcePolicy != null ? ResourcePolicy.Name : ResourcePolicyAvailSystemsLVI.m_nullString; }
}
public string AgentVersionString
{
get
{
if (AgentVersion == null || AgentVersion.Equals("0.0.0.0"))
{
return ResourcePolicySystemsControl.m_nullVersion;
}
return AgentVersion;
}
}
}