1:下面我们先来看看这个代码:
2:private static void OldMethod(BusinessObjectInfo parentBOInfo)
{
IList bosPropertyInfo = parentBOInfo.BOsPropertyInfos;
if ((bosPropertyInfo.Count == 1) && (null !=
parentBOInfo.TreeChildPropertyInfo))
{
//action one
}
else if (((bosPropertyInfo.Count > 1) && (null !=
parentBOInfo.TreeChildPropertyInfo))
|| ((bosPropertyInfo.Count > 0) && (null ==
parentBOInfo.TreeChildPropertyInfo))
)
{
//action two
}
}
private static void NewMethod(BusinessObjectInfo parentBOInfo)
{
IList childrenProperties =
parentBOInfo.BOsPropertyInfos;
var childrenPropertiesCount = childrenProperties.Count;
if (childrenPropertiesCount <= 0)
{
return;
}
var hasTreeChild = null != parentBOInfo.TreeChildPropertyInfo;
if (hasTreeChild)
{
if (childrenPropertiesCount == 1)
{
//action one
}
}
else
{ //action two
}
}
2:这样从业务角上来说是没错,但是写法还是有问题。下面来修改一下
3:private static void NewMethod2(BusinessObjectInfo parentBOInfo)
{
IList childrenProperties = parentBOInfo.BOsPropertyInfos;
parentBOInfo.BOsPropertyInfos;
var childrenPropertiesCount = childrenProperties.Count;
if (childrenPropertiesCount <= 0)
{
return;
}
var hasTreeChild = null != parentBOInfo.TreeChildPropertyInfo;
if (hasTreeChild && childrenPropertiesCount == 1)
{
//action one
}
else
{
//action two
}
}