-
-
Save MKGAURAB/b0ce03030363930e1ba4aeafe6f6032e to your computer and use it in GitHub Desktop.
How .NET Standard relates to .NET Platforms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| namespace Analogy | |
| { | |
| // Each interface represents a target framework and methods represents groups of APIs available on that target framework. | |
| // The goal is to show the relationship between .NET Standard API surface and other .NET platforms | |
| // .NET Standard | |
| interface INetStandard10 | |
| { | |
| void Primitives(); | |
| void Reflection(); | |
| void Tasks(); | |
| void Xml(); | |
| void Collections(); | |
| void Linq(); | |
| } | |
| interface INetStandard11 : INetStandard10 | |
| { | |
| void ConcurrentCollections(); | |
| void LinqParallel(); | |
| void Compression(); | |
| void HttpClient(); | |
| } | |
| interface INetStandard12 : INetStandard11 | |
| { | |
| void ThreadingTimer(); | |
| } | |
| interface INetStandard13 : INetStandard12 | |
| { | |
| void FileSystem(); | |
| void Console(); | |
| void ThreadPool(); | |
| void Crypto(); | |
| void WebSockets(); | |
| void Process(); | |
| void Sockets(); | |
| void AsyncLocal(); | |
| } | |
| interface INetStandard14 : INetStandard13 | |
| { | |
| void IsolatedStorage(); | |
| } | |
| interface INetStandard15 : INetStandard14 | |
| { | |
| void AssemblyLoadContext(); | |
| } | |
| // .NET Framework | |
| interface INetFramework45 : INetStandard11 | |
| { | |
| void FileSystem(); | |
| void Console(); | |
| void ThreadPool(); | |
| void Crypto(); | |
| void WebSockets(); | |
| void Process(); | |
| void Drawing(); | |
| void SystemWeb(); | |
| void WPF(); | |
| void WindowsForms(); | |
| void WCF(); | |
| } | |
| interface INetFramework451 : INetFramework45, INetStandard12 | |
| { | |
| // TODO: .NET Framework 4.5.1 specific APIs | |
| } | |
| interface INetFramework452 : INetFramework451, INetStandard12 | |
| { | |
| // TODO: .NET Framework 4.5.2 specific APIs | |
| } | |
| interface INetFramework46 : INetFramework452, INetStandard13 | |
| { | |
| // TODO: .NET Framework 4.6 specific APIs | |
| } | |
| interface INetFramework461 : INetFramework46, INetStandard14 | |
| { | |
| // TODO: .NET Framework 4.6.1 specific APIs | |
| } | |
| interface INetFramework462 : INetFramework461, INetStandard15 | |
| { | |
| // TODO: .NET Framework 4.6 specific APIs | |
| } | |
| // Windows Universal Platform | |
| interface IWindowsUniversalPlatform : INetStandard13 | |
| { | |
| void GPS(); | |
| void Xaml(); | |
| } | |
| // Xamarin | |
| interface IXamarinIOS : INetStandard15 | |
| { | |
| void AppleAPIs(); | |
| } | |
| interface IXamarinAndroid : INetStandard15 | |
| { | |
| void GoogleAPIs(); | |
| } | |
| // .NET Core | |
| interface INetCore10 : INetStandard15 | |
| { | |
| } | |
| // Future platform | |
| interface ISomeFuturePlatform : INetStandard13 | |
| { | |
| // A future platform chooses to implement a specific .NET Standard version. | |
| // All libraries that target that version are instantly compatible with this new | |
| // platform | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Analogy | |
| { | |
| /// <summary> | |
| /// In these examples, each method represents a project. Calling a method is like using | |
| /// that reference | |
| /// </summary> | |
| class Example1 | |
| { | |
| public void Net45Application(INetFramework45 project) | |
| { | |
| // .NET Framework 4.5 has access to all APIs | |
| project.FileSystem(); | |
| // This fails because .NET Framework 4.5 does not implement .NET Standard 1.3 | |
| // Argument 1: cannot convert from 'Analogy.INetFramework45' to 'Analogy.INetStandard13' | |
| NetStandardLibrary13(project); | |
| } | |
| public void NetStandardLibrary13(INetStandard13 project) | |
| { | |
| project.FileSystem(); | |
| } | |
| } | |
| class Example2 | |
| { | |
| /// <summary> | |
| /// This future platform implements .NET Standard 1.3 | |
| /// </summary> | |
| public void FuturePlatformApplication(ISomeFuturePlatform project) | |
| { | |
| // You are able to use JSON.NET with the future platform without recompiling JSON.NET | |
| JsonNet(project); | |
| } | |
| /// <summary> | |
| /// This method represents the implementation of JSON.NET. JSON.NET supports .NET Standard 1.0. | |
| /// </summary> | |
| public void JsonNet(INetStandard10 project) | |
| { | |
| project.Linq(); | |
| project.Reflection(); | |
| project.Collections(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment