Chapter 7 namespaces and classes in expert. NET 2.0 il Explorer (4)

Source: Internet
Author: User
Tags alphabetic character mscorlib

Returned directory

Class Expansion

InIlasm, AndVisual BasicAndC #All the members, features, and embedded classes of a class are declared within the lexical scope of the class. However,IlasmYou can reopen a closed class range and define additional items:

. Class   Public X Extends Y implements IX, Iy {

}

// Later in the source, possibly in another source file
. Class X {
  // More items defined
}

This type of re-opening of the class range is called the extension of the class. A class can be used throughoutSource codeExtended multiple times, and the extended module can be located in different source files. The following simple security rules manage class expansion:

The class must be fully defined in the module-in other words, you cannot expand a class defined elsewhere. (Isn't that good? Goodbye, security-Perfect !)

ClassMark,ExtendsClause, andImplementsThe clause must be completely defined in the lexical scope of the first open class, because these features are ignored in the extended section.

The expansion part cannot include the declaration of repeated items. If you declareInt32FieldXIn one piece, and then declare it in another piece,IlasmThe compiler will not be grateful that you may intentionally have two identical fields and read it as an attempt to define two identical fields in the same class, which is not allowed.

to 1.0 version and 1.1 Version write a ilasm Program , A good policy is to use the Forward Declaration ( forwarder class declaration ), which is explained in Chapter 1. This policy allows you to declare all classes of the current module, including embedded classes, without any members or features, and define members and features in the extended section. In this way, the IL compiler fully understands the type declaration structure of the module before any type is referenced. When the types declared locally are referenced, they are all defined and have corresponding typedef metadata records.

HoweverIlasmOf2.0Versions do not need to be declared to the class. In2.0Version in progress,IThe compiler implicitly declares a class whenever it is mentioned as a declaration or reference. Of course, this implicit Declaration on a reference class is just a dummy -- placeholder. When this class is declared{. Class... {... }}SourceCodeWhen it is encountered, a class declaration with a dummy element to "real" is passed. If all the edits are analyzed and there is still a "dumb dollar", the edits will fail.

The extended part is not displayed digitalized, and this class is expanded based on the sequence of the Extended Part in the source code. This means that if you switch the extended part, it will affect the layout of the class in sequence, and the Declaration Order of the class items will change.

However, if you want to retain the class declaration sequence or you want to release the class declaration in a specific order, you can use the command. Typelist:

. Typelist {firstclass secondclass thirdclass ...}

. TypelistIt is best to place the command on the top of the first source file, if it exists, even before the list Declaration. MscorlibCommand. The reason for such placement is obvious:IlThe compiler needs to know immediately whether you are compilingMscorlib. dllOr something else, and the list declaration may have custom features, or reference of other classes, which may mix the original sequence of class declaration.

List declaration, in6Chapter description, add the Forward Declaration (1.0And1.1Version) or. TypelistCommand (2.0Version), it looks like a program header, so I won't blame you if you put them in a separate source file. Just don't forget that when you compile a program set, this file must take precedence over the source files.

 

 

Summary of metadata verification rules

Recall the type-related metadata table (excluding the involved generic data, this will11Chapter) includesTypedef,Typeref,Interfaceimpl,NestedclassAndClasslayout. These table records include the following items:

TypedefThe table includesFlags,Name,Namespace,Extends,FieldlistAndMethodlist.

TyperefThe table includesResolutionscope,NameAndNamespace.

InterfaceimplThe table includesClassAndInterface.

NestedclassThe table includesNestedclassAndEnclosingclass.

ClasslayoutThe table includesPackingsize,ClasssizeAndParent.

 

TypedefTable verification rules

FlagsItems can only have those definitions inCorhdr. hInCortypeattrEnumeration bit settings. BesidesTdfowarderThis is the export type (Verification mark:0x00173dbf.

[Runtime] flagsItem cannot haveSequentialAndExplicitBit settings.

[Runtime] flagsItem cannot haveUnicodeAndAutocharBit settings.

IfFlagsTheRtspecialnameMark,NameThe field must be set_ Deteled *And vice versa.

[Runtime]IfFlagsTheZero X 00040000Bit,DeclsecurityRecord or nameSuppressunmanagedcodesecurityattributeThe custom features of must beTypedefUnion, and vice versa.

[Runtime]IfFlagsTheInterfaceMark, you must setAbstract.

[Runtime]IfFlagsTheInterfaceMark, you must setSealed.

[Runtime]IfFlagsTheInterfaceMark,TypedefNo instance field is required.

[Runtime]IfFlagsTheInterfaceMark,TypedefAll instance methods must be abstract.

[Runtime]IfTypedefIs setNested private,Nested family,Nested assembly,Nested famorassemOrNested famandassem,TypedefMust be inNestedclassA record of a metadatabaseNestedclassAnd vice versa.

NameThe field must reference# StringsA non-empty string in the stream.

ByNameAndNamespaceThe Union length of the referenced string cannot exceed1023Bytes.

TypedefA table cannot contain duplicate records with the same full name (namespace plus name), unlessTypedefIs embedded or deleted.

[Runtime]ForInterfaceMarkTypedefAndMscorlibAssemblySystem. Object,ExtendsItem must be zero. (This sentence seems to have been written incorrectly)

[Runtime]All othersTypedefOfExtendsYou must saveTypedef,TyperefOrTypespecTable, and the reference must point to a non-closed class.

[Runtime] extendsItem cannot point to the type itself or its child (inheritance loop ).

[Runtime] fieldlistItem must be zero or saveFieldA valid reference to a table.

[Runtime] methodlistItem must be zero or saveMethodA valid reference to a table.

 

Enumeration-specificVerification rules

IfTypedefIs an enumeration -- that is, ifExtendsItem to save[Mscorlib] system. Enum-Applies to the following additional rules:

[Runtime] Interface,Abstract,Sequential, AndExplicitThe tag cannot be inFlag.

SealedThe tag must be inFlag.

TypedefMethods, events, or properties are not allowed.

TypedefThe interface cannot be implemented-that is, it cannotInterfaceimplIn any record of the tableClassItem is referenced.

[Runtime] typedefThere must be at least one instance field of integer, Boolean, or character type.

[Runtime] typedefAll static fields must be normalized.

TypedefThe static field type of must be currentTypedefItself.

 

TyperefTable verification rules

[Runtime] resolutionscopeItem must be saved0Or a pointAssemblyref,Moduleref,ModuleOrTyperefValid Table reference. In the last scenario,TyperefPoint to a type embedded in another type (an embeddedTyperef).

IfResolutionscopeItem is0, The main module of this AssemblyExportedtypeA table must contain a record. ItsTypenameAndTypenamespaceItems correspondTyperefRecordNameAndNamespaceItem match.

[Runtime] NameItem must be referenced# StringsA non-empty string in the stream.

 

InterfaceimptTable verification rules

SetClassItem0Indicates that a deletedInterfaceimptRecord. However, ifClassItem is not0Then the following rules apply:

[Runtime] classItem must beTypedefA valid reference to a table.

[Runtime] InterfaceItem must beTypedefOrTyperefA valid reference to a table.

IfInterfaceField referencedTypedefTable, correspondingTypedefThe record must be inFlagsItem settingsInterfaceMark.

This table cannot contain the sameClassAndInterfaceItem Repeated Records

 

NestedclassTable verification rules

[Runtime] nestedclassItem must beTypedefA valid reference to a table.

[Runtime] enclosingclassItem must beTypedefA valid reference to a table, which is different fromNestedclassReference of item persistence.

This table cannot contain the sameEnclosingclassAndNestedclassItem records that referenceTypedefRecord-in other words, an embedded class must have a unique name in its outsourcing class.

This table cannot contain a group of records that form the nested loop mode-for example,AEmbedded inBMedium,BEmbedded inCMedium,CEmbedded inA.

 

ClasslayoutTable verification rules

SetParentItem0Indicates that a deletedClasslayoutRecord. However, ifParentItem is not0Then the following rules apply:

ParentItem must beTypedefA valid reference of the table, and the referencedTypedefThe record mustFlagsBitExplicitOrSequentialAnd cannot be set.InterfaceBit.

[Runtime] packingsizeMust be set0Or1To128Within the scope2The exponential power.

This table cannot contain the sameParentItem.

 

 

TerminologyTerms

InherentlyEssentially

All of a suddenSuddenly

In a general senseIn general

Engage inEngage in,Participate

MetadataEntryGood translation items

Resolution ScopeResolution Range

Lookup TableSearch tables

Alphabetic characterText symbols

EconomySave

MarshalMail

At willCasual

GranularityGranularity

Under construction

Bear in mindRemember

Stem from the factSource

NamelyThat is

TrivialOrdinary

Forward slash --->/
Back slash ------>"

In this regardAt this point

One thatOne type

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.