这是一段从XML文件中提取内容填充到configObject类成员变量的代码,大概有近100个else if比较分支
请问如何优化一下,减少代码量
using (XmlReader xr = XmlReader.Create(configXMLReader, settings))
{
Log.Debug("OpHostCIDConfigure.xml contents ");
while (xr.Read())
{
if (xr.MoveToContent() != XmlNodeType.Element)
continue;
if (String.Equals(xr.Name, "agency"))
{
configObject.Agency = long.Parse(xr.ReadString());
Log.Debug("Agency Content {0} ", configObject.Agency);
}
###
<中间省略大量else if比较分支>
###
else if (String.Equals(xr.Name, "csc-parameters"))
{
tmpLong = long.Parse(xr.ReadString());
lCscParamList.Add(tmpLong);
Log.Debug("CscParameters {0}", tmpLong);
}
else if (String.Equals(xr.Name, "cid-parameters"))
{
tmpLong = long.Parse(xr.ReadString());
lCidParamList.Add(tmpLong);
Log.Debug("CidParameters {0}", tmpLong);
}
}
}
--
FROM 14.203.253.*