Why is the interface called at the IL level as an "abstract interface"?

I am trying to learn more about the CLR and at the same time noticed that the next interface in C # will be compiled into IL, which contains some kind of "abstract interface".

Given that declaring an interface as abstract in C # is unacceptable, does this mean that allowing an abstract interface at the IL level? Initially, I wondered if this was how the runtime is an interface, declaring an abstract class, thereby preventing its appearance.

This seems to follow this idea as shown by .class . However, after that interface . Thus, the idea of ​​creating an abstract class seems controversial when the runtime already supports the concept of an interface.

This leads me to two questions:

  • What is the purpose of an abstract interface and why is an abstract interface valid at the IL level?
  • Why are .class and interface needed, and why is it really at the IL level?
  • If the runtime supports the concept of an interface, why .class or abstract is required?

WITH#:

 public interface IExample { void SomeMethod(int number); } 

IL:

 .class interface public auto ansi abstract IExample { // Methods .method public hidebysig newslot abstract virtual instance void SomeMethod ( int32 number ) cil managed { } // end of method IExample::SomeMethod } 
+5
source share
1 answer

If you look at how metadata (PDF) is defined at the IL level, all types are entered with a .class header (even value types).

interface described as a “semantic type attribute” (10.1.3) and is used to determine whether what is defined is really an interface, as opposed to an abstract class in which all members are abstract.

abstract described as an “inheritance attribute” (10.1.4) and specifically means that a type cannot be created.

This covers the intended values. Regarding why they are needed (i.e., why the interface does not automatically mean abstract ), I believe that this was done to make everything explicit at this level. Since you do not often have to write IL yourself, some matches between some of these flags are not harmful.

+11
source

Source: https://habr.com/ru/post/1268661/


All Articles