Guest User

Untitled

a guest
Aug 24th, 2016
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. namespace Analogy
  2. {
  3. /// <summary>
  4. /// This example shows that a library that needs access to target .NET Standard 1.3
  5. /// can only access APIs available in that .NET Standard. Even though similar the APIs exist on .NET
  6. /// Framework 4.5, it implements a version of .NET Standard that isn't compatible with the library.
  7. /// </summary>INetCoreApp10
  8. class Example1
  9. {
  10. public void Net45Application(INetFramework45 platform)
  11. {
  12. // .NET Framework 4.5 has access to all .NET Framework APIs
  13. platform.FileSystem();
  14.  
  15. platform.Console();
  16.  
  17.  
  18. // This fails because .NET Framework 4.5 does not implement .NET Standard 1.3
  19. // Argument 1: cannot convert from 'Analogy.INetFramework45' to 'Analogy.INetStandard13'
  20. NetStandardLibrary13(platform);
  21. }
  22.  
  23. public void NetStandardLibrary13(INetStandard13 platform)
  24. {
  25. platform.FileSystem();
  26.  
  27. platform.Console();
  28. }
  29. }
  30.  
  31.  
  32. /// <summary>
  33. /// This example shows a library targeting multiple frameworks and 2 different applications
  34. /// using that library. MultipleTargetsLibrary needs access to the FileSystem, that API was only available
  35. /// in .NET Standard 1.3. .NET Standard 1.3 only works with .NET Framework 4.6. Because of this
  36. /// MultipleTargetsLibrary needs to add support for .NET Framework 4.5 explicitly.
  37. /// </summary>
  38. class Example2
  39. {
  40. public void Net45Application(INetFramework451 platform)
  41. {
  42. // On the .NET 4.5.1 application, the INetFramework45 implementation is choson
  43. MultipleTargetsLibrary(platform);
  44. }
  45.  
  46. public void NetCoreApplication(INetCoreApp10 platform)
  47. {
  48. // On the .NET Core 1.0 application, the INetStandard13 implementation is choson
  49. MultipleTargetsLibrary(platform);
  50. }
  51.  
  52. public void MultipleTargetsLibrary(INetFramework45 platform)
  53. {
  54. platform.FileSystem();
  55. }
  56.  
  57. public void MultipleTargetsLibrary(INetStandard13 platform)
  58. {
  59. platform.FileSystem();
  60. }
  61. }
  62.  
  63. /// <summary>
  64. /// This example shows how future platforms can be added without the need to change libraries that
  65. /// target the .NET Standard. JSON.NET targets .NET Standard 1.0 and can run on *ANY* platform that implements
  66. /// the standard.
  67. /// </summary>
  68. class Example3
  69. {
  70. /// <summary>
  71. /// This future platform implements .NET Standard 1.3
  72. /// </summary>
  73. public void FuturePlatformApplication(ISomeFuturePlatform platform)
  74. {
  75. // You are able to use JSON.NET with the future platform without recompiling JSON.NET
  76. JsonNet(platform);
  77. }
  78.  
  79. /// <summary>
  80. /// This method represents the implementation of JSON.NET. JSON.NET supports .NET Standard 1.0.
  81. /// </summary>
  82. public void JsonNet(INetStandard10 platform)
  83. {
  84. platform.Linq();
  85.  
  86. platform.Reflection();
  87.  
  88. platform.Collections();
  89. }
  90. }
  91. }
Add Comment
Please, Sign In to add comment