我有兩種方法幾乎可以做同樣的事情。他們根據州OR狀態和schoolType獲得List<XmlNode>
,然後返回一個明確的,有序的IEnumerable<KeyValuePair<string,string>>
。我知道它們可以被重構,但我正努力確定該方法返回時linq語句的參數應該是什麼類型(每個方法的最後一行)。將兩種方法重構爲一個
我感謝您的幫助提前。
private IEnumerable<KeyValuePair<string, string>> getAreaDropDownDataSource() {
StateInfoXmlDocument stateInfoXmlDocument = new StateInfoXmlDocument();
string schoolTypeXmlPath = string.Format(STATE_AND_SCHOOL_TYPE_XML_PATH, StateOfInterest, ConnectionsLearningSchoolType);
var schoolNodes = new List<XmlNode>(stateInfoXmlDocument.SelectNodes(schoolTypeXmlPath).Cast<XmlNode>());
return schoolNodes.Select(x => new KeyValuePair<string, string>(x.Attributes["idLocation"].Value, x.Value)).OrderBy(x => x.Key).Distinct();
}
private IEnumerable<KeyValuePair<string, string>> getStateOfInterestDropDownDataSource() {
StateInfoXmlDocument stateInfoXmlDocument = new StateInfoXmlDocument();
string schoolTypeXmlPath = string.Format(SCHOOL_TYPE_XML_PATH, ConnectionsLearningSchoolType);
var schoolNodes = new List<XmlNode>(stateInfoXmlDocument.SelectNodes(schoolTypeXmlPath).Cast<XmlNode>());
return schoolNodes.Select(x => new KeyValuePair<string, string>(x.Attributes["stateCode"].Value, x.Attributes["stateName"].Value)).OrderBy(x => x.Key).Distinct();
}
'schoolTypeXmlPath'是每個兩種方法在OP ... –
@lc的不同。謝謝,沒有注意到。從屬性更改爲方法 –
謝謝,這裏有一些非常棒的點子:) – bflemi3