当前位置:网站首页>. 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
边栏推荐
- oracle 中快速获取表的列名列表
- Kunteng full duplex digital wireless transceiver chip kt1605 / kt1606 / kt1607 / kt1608 is suitable for interphone scheme
- 深入了解3D模型相关知识(建模、材质贴图、UV、法线),置换贴图、凹凸贴图与法线贴图的区别
- AIOT产业技术全景结构-数字化架构设计(8)
- Lock lock
- ◰GL-着色器处理程序封装
- Nodejs installation and environment configuration
- Go language, array, string, slice
- True math problems in 1959 college entrance examination
- Solution architect's small bag - 5 types of architecture diagrams
猜你喜欢
随机推荐
Zhimeng dedecms security setup Guide
ByteVCharts可视化图表库,你想要的我都有
Variable length parameter__ VA_ ARGS__ Macro definitions for and logging
Nifi fast installation and file synchronization
Lock锁
On lambda powertools typescript
Multithreaded @ async thread pool
1-3 nodejs installation list configuration and project environment
Grpc gateway based on Ocelot
MySQL master-slave replication
[PROJECT] small hat takeout (8)
◰ GL shadow map core steps
Go language, array, string, slice
Nacos + aspnetcore + Ocelot actual combat code
计算饼状图百分比
PHP高效读大文件处理数据
Feign report 400 processing
手写事件发布订阅框架
PHP efficiently reads large files and processes data
CentOS MySQL multi instance deployment