我有以下方法:
protected static void updateExistingSection(XmlDocument doc,
XmlNode rootNode, string sectionTag, CreateSection createSection,
Func<XmlNode[]> createChildNodes, Action<XmlNode> firstSection)
{
IEnumerable<XmlNode> sections =
getChildNodesByName(rootNode, sectionTag);
if (sections.Count() < 1)
{
rootNode.AppendChild(createSection(doc, createChildNodes()));
return;
}
removeSubsequentNodes(sections, rootNode, firstSection);
}
private static void updateExistingCredentialsSection(XmlDocument doc,
XmlNode rootNode, string newUser, string newPassword, string newHost)
{
updateExistingSection(doc, rootNode, CREDENTIALS_SECTION_TAG,
createCredentialsSection,
() => new[] {
createNode(USER_TAG, doc, newUser),
createNode(PASSWORD_TAG, doc, newPassword),
createNode(HOST_TAG, doc, newHost)
},
credentialsNode =>
{
updateExistingLeafNode(USER_TAG, doc, credentialsNode, newUser);
updateExistingLeafNode(PASSWORD_TAG, doc, credentialsNode,
newPassword);
updateExistingLeafNode(HOST_TAG, doc, credentialsNode, newHost);
});
}
我的问题是关于传入的第五个参数
updateExistingCredentialsSection
到
updateExistingSection
, the
() => new[] { createNode(USER_TAG, doc, newUser), ... }
一个。这是我的理解
createNode
除非在中调用lambda表达式,否则不会发生调用
更新现有节
对吧?同样适用于
updateExistingLeafNode
调用最后一个给定的参数
更新现有节
.
另外,从设计的角度来看,这两种方法看起来都很荒谬吗?您是否看到了一种方法,我可以使方法变小,或者需要更少的参数?我一直想把东西弄干,这就是导致写作的原因。
更新现有节
首先,因为我有几个方法做相同的功能。