我目前正在使用...
public static class KeyValuePairFactory {
public static KeyValuePair<TKey, TValue> Create<TKey, TValue>(
TKey key,
TValue value
) {
return new KeyValuePair<TKey, TValue>(key, value);
}
}
......所以而不是......
var pair = new KeyValuePair<MyVeryUnwieldyType1, MyVeryUnwieldyType2>(
new MyVeryUnwieldyType1(),
new MyVeryUnwieldyType2()
);
...我可以避免重复类型,并且简单地说:
var pair = KeyValuePairFactory.Create(
new MyVeryUnwieldyType1(),
new MyVeryUnwieldyType2()
);
我是在重新发明轮子并重新实现 .NET Framework 中已有的东西吗?