Let's talk about the implementation of the Object Class Terminator!

Source: Internet
Author: User
Tags reflector
After loading mscorlib. dll with Reflector, we can see that the Finalize method in the System. Object Class is modified with override.
The Object is the root class and it is obviously impossible to rewrite other methods. Here the results generated by the decompilation tool are incorrect. Let's verify this:

Everyone knows that in order to reduce the burden on developers, C # provides a special syntax for the Finalize method definition. This syntax is used to define the Finalize method, the compiler can automatically generate appropriate exception handling code and call the Finalize method of the base class!

The source code of the Finalize method of the Object class is as follows:
~ Object ()
{
}
We can see that this method has nothing to do!

We use the ILDasm tool to view the IL code:
. Method family hidebysig virtual instance void
Finalize () cel managed
{
. Custom instance void System. Runtime. ConstrainedExecution. ReliabilityContractAttribute:. ctor (valuetype System. Runtime. ConstrainedExecution. Consistency,
Valuetype System. Runtime. ConstrainedExecution. Cer) = (01 00 03 00 00 02 00 00 00 00 00)
// Code size 1 (0x1)
. Maxstack 8
IL_0000: ret
} // End of method Object: Finalize

This is actually a Virtual method, not an override method.
In general classes (if needed), this method is rewritten to add the terminator implementation.

Reflector may not parse the Object class correctly. Therefore, the decompilation result of Reflector is incorrect here, which is not another override method.

Please kindly advise!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.