当前位置:网站首页>. net type transfer
. net type transfer
2022-04-23 17:04:00 【begeneral】
We all know , General frameworks can achieve downward compatibility , How is this compatibility realized ?
First we use .Net Framework 3.5 Create a console program , The code is as follows :
static void Main(string[] args)
{
Console.WriteLine(typeof(string).Assembly.FullName);
Console.WriteLine(typeof(Func<>).Assembly.FullName);
Console.ReadKey();
}
This code outputs string The type and Func Information about the assembly in which the type resides , The output is as follows :
![]()
You can see string The assembly of type is mscorlib, The version is 2.0;Func The assembly of type is System.Core, The version is 3.5.
We use .Net 3.5 Compilation of , Logically speaking mscorlib The version of should be the same 3.5, Why 2.0 Well ?
because .Net Framework 2.0、3.0、3.5 Runtime (CLR) All are 2.0,.Net Framework from 2.0 Upgrade to 3.5 when , The core library mscorlib There is no upgrade , Still in use 2.0 Version of mscorlib. and Func The type is 3.5 Version introduced , Put in assembly System.Core in .
The output above is in CLR by 2.0 The output result of , Then if I put the program CLR Change it to 4.0, What will happen ?
Create a new one APP.config The configuration file ( If it already exists, there is no need to create ), Modify the configuration as follows :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
By setting supportedRuntime Of version=4.0, Set the runtime of the current program to 4.0. Take another look at the output :
![]()
Both types of assemblies become mscorlib, The versions have become 4.0. Why is this so ?
because .NET When looking for an assembly, it is based on the current runtime , Not based on the current .NET Framework To find the version of .
But there is a problem ,Func Types are indeed defined in System.Core In the assembly , Why when the runtime is set to 4.0 when , The assembly in which it is located becomes mscorlib What about it ? As for how to look at Func Type defines in which assembly , Let's switch to Func The definition of type , Look at the top assembly information to know .
We find .Net Framework 4.0 Below System.Core.dll Assembly , The path of this assembly on my computer is :C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0. open ildasm.exe, This is a .NET Its own decompilation tool software , The path on my computer is :C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools.
Use this software to open 4.0 Version System.Core.dll, double-click MANIFEST, Search for System.Func, You can see the following code :
.class extern forwarder System.Func`1
{
.assembly extern mscorlib
}
This code means , When you want to find System.Func Type , To go to mscorlib Find in the assembly . This is equivalent to a redirect , So when you get its assembly , Go first System.Core Assembly lookup , Then go to mscorlib assembly .
Add here ,.Net Framework 4.x The runtime is CLR4.0.
版权声明
本文为[begeneral]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230554082387.html
边栏推荐
- El cascade and El select click elsewhere to make the drop-down box disappear
- 面试百分百问到的进程,你究竟了解多少
- Camtasia2022软件新增功能介绍
- Getting started with JDBC
- Kingdee Cloud Star API calling practice
- Nifi fast installation and file synchronization
- STM32__ 03 - beginner timer
- TypeError: set_figure_params() got an unexpected keyword argument ‘figsize‘
- Log4j output log information to file
- An essay on the classical "tear down the wall in thinking"
猜你喜欢

详解牛客----手套

Scope and scope chain in JS

批量制造测试数据的思路,附源码

自定义my_strcpy与库strcpy【模拟实现字符串相关函数】

English | day15, 16 x sentence true research daily sentence (clause disconnection, modification)

【WPF绑定3】 ListView基础绑定和数据模板绑定

SQL database

面试百分百问到的进程,你究竟了解多少
![[pimf] openharmony paper Club - what is the experience of wandering in ACM survey](/img/b6/3df53baafb9aad3024d10cf9b56230.png)
[pimf] openharmony paper Club - what is the experience of wandering in ACM survey

Detailed explanation of the penetration of network security in the shooting range
随机推荐
Grpc gateway based on Ocelot
Milvus 2.0 détails du système d'assurance de la qualité
STM32__03—初识定时器
Promise (II)
拷贝构造函数 浅拷贝与深拷贝
Get the column name list of the table quickly in Oracle
New keyword learning and summary
线性代数感悟之2
Nodejs reads the local JSON file through require. Unexpected token / in JSON at position appears
websocket
BUG_ me
ACL 2022 | dialogved: a pre trained implicit variable encoding decoding model for dialogue reply generation
Website_ Collection
Detailed explanation of Milvus 2.0 quality assurance system
Generation of barcode and QR code
Feign report 400 processing
Path environment variable
Kingdee Cloud Star API calling practice
True math problems in 1959 college entrance examination
[markdown notes]