我们可以在IDictionary或其他方面的帮助下将这两种方法结合起来吗?
private static void WriteSourceCredential(XmlWriter pXmlWriter, string key, IDictionary<string, int> resultCountBySources, string value)
{
int tempKeyValue;
pXmlWriter.WriteStartElement("SourceCredentials"); //Start HotelCredential
pXmlWriter.WriteElementString("Key", key);
resultCountBySources.TryGetValue(value, out tempKeyValue);
pXmlWriter.WriteElementString("Value", tempKeyValue.ToString(CultureInfo.InvariantCulture)); // API Key
pXmlWriter.WriteEndElement(); //End HotelCredential
}
private static void WriteSourceCredential(XmlWriter pXmlWriter, string key, IDictionary<string, string> sourceCredentials, string value)
{
string tempKeyValue;
pXmlWriter.WriteStartElement("SourceCredentials"); //Start HotelCredential
pXmlWriter.WriteElementString("Key", key);
sourceCredentials.TryGetValue(value, out tempKeyValue);
pXmlWriter.WriteElementString("Value", tempKeyValue); // API Key
pXmlWriter.WriteEndElement(); //End HotelCredential
}
答案 0 :(得分:0)
这是你在找什么?
private static void WriteSourceCredential<TValue>(XmlWriter pXmlWriter, string key, IDictionary<string, TValue> sourceCredentials, string value)
{
TValue tempKeyValue;
pXmlWriter.WriteStartElement("SourceCredentials"); //Start HotelCredential
pXmlWriter.WriteElementString("Key", key);
sourceCredentials.TryGetValue(value, out tempKeyValue);
pXmlWriter.WriteElementString("Value", tempKeyValue.ToString()); // API Key
pXmlWriter.WriteEndElement(); //End HotelCredential
}