当前位置:网站首页>. 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
边栏推荐
- Regular filtering of Intranet addresses and segments
- Idea of batch manufacturing test data, with source code
- 深入了解3D模型相关知识(建模、材质贴图、UV、法线),置换贴图、凹凸贴图与法线贴图的区别
- Milvus 2.0 质量保障系统详解
- The new MySQL table has a self increasing ID of 20 bits. The reason is
- [registration] tf54: engineer growth map and excellent R & D organization building
- Bytevcharts visual chart library, I have everything you want
- PyMySQL
- 计算饼状图百分比
- 【解决报错】Error in v-on handler: “TypeError: Cannot read property ‘resetFields’ of undefined”
猜你喜欢
[pimf] openharmony paper Club - what is the experience of wandering in ACM survey
ACL 2022 | dialogved: a pre trained implicit variable encoding decoding model for dialogue reply generation
【PIMF】OpenHarmony啃论文俱乐部—在ACM Survey闲逛是什么体验
On lambda powertools typescript
Use between nodejs modules
Idea of batch manufacturing test data, with source code
Document operation II (5000 word summary)
扫码登录的原理你真的了解吗?
TypeError: set_ figure_ params() got an unexpected keyword argument ‘figsize‘
CentOS MySQL multi instance deployment
随机推荐
SQL: How to parse Microsoft Transact-SQL Statements in C# and to match the column aliases of a view
Feign report 400 processing
BUG_ me
SQL database
Log4j output log information to file
Copy constructor shallow copy and deep copy
freeCodeCamp----prob_ Calculator exercise
How to build tiktok user trust and drive fan growth
拷贝构造函数 浅拷贝与深拷贝
【题解】[SHOI2012] 随机树
Milvus 2.0 質量保障系統詳解
Introduction to how to set up LAN
VLAN高级技术,VLAN聚合,超级Super VLAN ,Sub VLAN
深入了解3D模型相关知识(建模、材质贴图、UV、法线),置换贴图、凹凸贴图与法线贴图的区别
Variable length parameter__ VA_ ARGS__ Macro definitions for and logging
How much do you know about the process of the interview
Derivation of Σ GL perspective projection matrix
org. apache. parquet. schema. InvalidSchemaException: A group type can not be empty. Parquet does not su
博士申请 | 厦门大学信息学院郭诗辉老师团队招收全奖博士/博后/实习生
Calculate pie chart percentage