读书笔记: C# 7.0 in a nutshell (第 五 章 Framework Overview)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_30162859/article/details/82717294

内容:

第五章 框架总览

  1. Overview
  2. .NET Standard 2.0
  3. CLR 和核心框架
  4. 应用技术

1. Overview

几乎所有 .NET 框架的作用都通过一系列的 Managed Types暴露出来。 这些 types 组织在一层层的 namespace中,然后别打包进assembly, 连同CLR 一起构成 .NET 平台。

有些.NET 类型是直接被CLR使用的,对管理 hosting environment有重要作用。这些代码都在mscorlib.dll这个程序集中, 包括C#的内置类集合类流处理类序列化反射线程native interoperability

mscorlib 是 Multi-language Standard Common Object Runtime Library

再往上一层,是基于这些类的来提供更多的功能的一些类,包括比如XML, 网络LINQ。 它们在System.dllSystem.Core.dll,System.Xml.dll等等中,连同mscorlib一起提供更丰富的编程环境。 .NET框架其他的功能都是基于这些之上的。

其他的功能主要都是包括一些Apllied API, 这其中大多数包含了下面3方面的功能:

  1. UI技术
  2. 后端技术
  3. 分布式系统技术
C# version CLR version .NET Framework versions
1.0 1.0 1.0
1.2 1.1 1.1
2.0 2.0 2.0, 3.0
3.0 2.0 (SP2) 3.5
4.0 4.0 4.0
5.0 4.5 (Patched CLR 4.0) 4.5
6.0 4.6 (Patched CLR 4.0) 4.6
7.0 4.6/4.7 (Patched CLR 4.0) 4.6/4.7

大部分的核心类型都定义在以下这些程序集中:

  • mscorlib.dll
  • System.dll
  • System.Core.dll

第一个mscorlib.dll包含了运行时环境需求的类型; 而后面2个包含了其他程序员需要的类型。

The reason the latter two are separate is historical: when Microsoft introduced Framework 3.5, they made it
additive insofar as it ran as a layer over the existing CLR 2.0. Therefore, almost all new core types (such as the classes supporting LINQ) went into a new assembly that Microsoft called System.Core.dll.

1.1 What’s New in .NET 4.6

  • The Garbage Collector (GC) offers more control over when (not) to collect via new methods on the GC class. There are also more fine-tuning options when calling GC.Collect.
  • There’s a brand-new faster 64-bit JIT compiler.
  • The System.Numerics namespace now includes hardware-accelerated matrix, vector types, BigInteger and Complex.
  • There’s a new System.AppContext class, designed to give library authors a consistent mechanism for letting consumers switch new API features in or out.
  • Tasks now pick up the current thread’s culture and UI culture when created.
  • More collection types now implement IReadOnlyCollection.
  • WPF has further improvements, including better touch and high-DPI handling.
  • ASP.NET now supports HTTP/2 and the Token Binding Protocol in Windows 10

1.2 What’s New in .NET 4.7

  • The System.ValueTuple struct is part of Framework 4.7, so you can use tuples in C# 7 without referencing the System.ValueTuple.dll assembly.
  • WPF has better touch support.
  • Windows Forms has better support for high-DPI monitors.

2 .NET Standard 2.0

Chap1中,描述了 .NET框架其他的3个为了跨平台开发的 alternatives:

  • UWP for Windows 10 device/desktop
  • .NET Core/ASP.NET Core for Windows, Linux and MacOS
  • Xamarin for mobile devices (iOS, Android, and Windows 10 devices)

好消息是随着 .NET Core 2.0,这些框架包括.NET Framework 4.6.1以及之后的版本, 都已经融合进了它的核心功能中,并且都提供了一个base class library(BCL) ,包含类似的 type 和member。这种共同性被正式称为 .NET Standard 2.0

当使用 VS 2017写library的时候,可以选择目标为 .NET Standard 2.0,而不是指定某个特别的框架。 这样这个library就是 可移植的,这个程序集就可以再各个不同的平台运行。

2.1 老的 .NET Standard

2.0以前也有.NET Standard:

If you target… You also support…
Standard 1.6 .NET Core 1.0
Standard 1.3 Above plus .NET 4.6.0
Standard 1.2 Above plus .NET 4.5.1, Windows Phone 8.1, WinRT for Windows 8.1
Standard 1.1 Above plus .NET 4.5.0, Windows Phone 8.0, WinRT for Windows 8.0

数字更大的标准,是一个更严格的超集。

2.2 Reference Assemblies

写程序的时候,需要在编译的时候,引入程序中用到的assemblies. 但是引入的assemblies, 只需要在编译的时候存在,并不一定要求和运行时的一致。所以可以创建一个空的程序集,里面没有被编译的代码。

This is how .NET Standard works: you add a reference assembly called netstandard.dll, which contains all of the allowable types and members in .NET Standard 2.0 (but no actual compiled code). Then, through assembly redirection attributes, the “real” assemblies are loaded at runtime. (The choice of “real” assemblies will depend on which framework the assembly eventually runs on.)

3. The CLR and Core Framework

3.1 System Types

System命名空间包含大多数基本类型,包括了

  • C# built-in types
  • Exception基类
  • Enum
  • Array
  • Delegate基类
  • Nullable
  • Type
  • DateTime
  • TimeSpan
  • Guid
  • Math
  • Random
  • Convert
  • BItConverter
  • IDisposable

3.2 Text Processing

System.Text命名空间包括

  • StringBuilder (string类型的 mutable cousin)
  • Encoding 及其子类

System.Text.RegularExpression包含正则

3.3 Collections

System.Collections // Nongeneric collections
System.Collections.Generic // Generic collections
System.Collections.Specialized // Strongly typed collections
System.Collections.ObjectModel // Bases for your own collections
System.Collections.Concurrent // Thread-safe collection (Chapter 23)

3.4 Queries

LINQ:

System.Linq// LINQ to Objects and PLINQ
System.Linq.Expressions // For building expressions manually
System.Xml.Linq// LINQ to XML
System.Data.Linq // LINQ to SQL
System.Data.Entity // LINQ to Entities (Entity Framework)

3.5 XML

Linq to XML, XMLReader, 老DOM, XSD, XML schema, stylesheet, XPATH

System.Xml// XmlReader, XmlWriter + the old W3C DOM
System.Xml.Linq// The LINQ to XML DOM
System.Xml.Schema // Support for XSD
System.Xml.Serialization // Declarative XML serialization for .NET types
System.Xml.XPath// XPath query language
System.Xml.Xsl // Stylesheet support

3.6 Diagnostics

logging and assertion 功能, 描述了:

  • 和其他进程交互
  • 写到Windows event log
  • use performance counters for monitoring

System.Diag nostics

3.7 Concurrency and Asynchrony

multithreading, task, async.

System.Threading
System.Threading.Tasks

3.8 Streams and I/O

基于流的输入输出

System.IO .NET IO和Stream
Windows.Storage WinRT file IO

3.9 Networking

System.Net
System.Net.Http // HttpClient
System.Net.Mail // For sending mail via SMTP
System.Net.Sockets // TCP, UDP, and IP

上面的后2个对于Win8平台没法使用

Windows.Networking.Sockets WinRT的socket交互

3.10 Serialization

从二进制存取, 对于分布式的技术非常有用,比如WCF, Web Services, and Remoting

  • data contract serializer
  • binary serializer
  • XML serializer
  • JSON serializer

System.Runtime.Serialization
System.Xml.Serialization

3.11 Assemblies, Reflection, and Attributes

System
System.Reflection
System.Reflection.Emit // .NET Framework only

3.12 Dynamic Programming

System.Dynamic

3.13 Security

System.Security
System.Security.Permissions
System.Security.Policy
System.Security.Cryptography

3.14 Advanced Threading

signaling constructs, thread-local storage, reader/writer locks, and so on

System.Threading

3.15 Parallel Programming

3.16 Application Domains

The CLR provides an additional level of isolation within a process, called an application domain

Creating separate application domains is not part of .NET Standard 2.0, although you can interact with the current domain via the AppDomain class in the System namespace.

3.17 Native and COM Interoperability

System.Runtime.InteropServices

4. Applied Technologies

User-Interface API

  • 瘦客户端:
    • ASP.NET and ASP.NET Core
  • 胖客户端:
    • WPF+Winform for Windows7/8/10
    • UWP for Windows desktop and device
    • Xamarin for mobile phone


* ASP.NET: System.Web.UI及其子命名空间,包含在System.Web.dll
* ASP.NET Core: 轻量,不用System.Web.dll
* WPF (Windows Presentation Foundation): System.Windows及其子命名空间,除了System.Windows.Forms命名空间
* WinForm: System.Windows.FormsSystem.Drawing命名空间,包含在System.Windows.Forms.dllSystem.Drawing.dll
* Xamarin:
* UWP (Universal Windows Platform):Windows.UI and Windows.UI.Xaml

Backend Technologies

  • ADO.NET
  • Entity Framework (.NET Framework only)
  • Entity Framework Core (.NET Framework and .NET Core)
  • LINQ to SQL (.NET Framework only)

后面3个基于 ADO.NET的Provider layer

  • Windows Workflow (.NET Framework only) : System.WorkFlowSystem.Activities
  • COM+ and MSMQ (.NET Framework only)

Distributed System Technologies

  • WCF (Windows Communication Foundation) : 用于替代Remoting和 (.ASMX) Web Service
  • Web API : 基于ASP.NET/ ASP.NET Core
  • Remoting and .ASMX Web Services (.NET Framework only)

猜你喜欢

转载自blog.csdn.net/qq_30162859/article/details/82717294