This project is read-only.

Note on System.Tuples Compatibility to .NET 4's Tuple

Apr 8, 2012 at 1:35 PM

Note that though this library is excellent in bringing Tuples to .NET 3.5, the API is incompatible,

  • .NET 4 Tuple uses Item1, Item2 while this library uses Element1, Element2. 
  • .NET 4 Tuple class is under System namespace, while this library uses System.Tuples namespace.

Of course, this incompatibility makes it clear that this library is not .NET Tuple, but for any project that depends on Tuples, it is not easy to cross compile for both .NET 3.5 and .NET 4 (use this library for .NET 3.5, while automatically switch to .NET 4 Tuple when compiled against .NET 4).

Therefore, in my open source project #SNMP, I made the following changes,

  1. Move the namespace from System.Tuples to System.
  2. Embed System.Tuples's source files in my own library, and use conditional includes inside csproj to exclude them for .NET 4 compilation.

In this way, #SNMP compiles fine for both .NET 3.5 and .NET 4 with the same copy of source files (no conditional compilation in C# file like #if). You may refer to the source code of #SNMP for more details if you hit the same compatibility issues,

https://github.com/lextm/sharpsnmplib/tree/master/SharpSnmpLib/System.Tuples

Regards,

Lex