1、 Reference number ISO/IEC 23271:2012(E) ISO/IEC 2012INTERNATIONAL STANDARD ISO/IEC 23271 Third edition 2012-02-15 Information technology Common Language Infrastructure (CLI) Technologies de linformation Infrastructure commune de langage (ICL) ISO/IEC 23271:2012(E) COPYRIGHT PROTECTED DOCUMENT ISO/IE
2、C 2012 All rights reserved. Unless otherwise specified, no part of this publication may be reproduced or utilized in any form or by any means, electronic or mechanical, including photocopying and microfilm, without permission in writing from either ISO at the address below or ISOs member body in the
3、 country of the requester. ISO copyright office Case postale 56 CH-1211 Geneva 20 Tel. + 41 22 749 01 11 Fax + 41 22 749 09 47 E-mail copyrightiso.org Web www.iso.org Published in Switzerland ii ISO/IEC 2012 All rights reservedISO/IEC 23271:2012(E) ISO/IEC 2012 All rights reserved. iii Table of Cont
4、ents Foreword xxi I.1 Scope 1 I.2 Conformance 2 I.3 Normative references 3 I.4 Conventions 5 I.4.1 Organization 5 I.4.2 Informative text 5 I.5 Terms and definitions 6 I.6 Overview of the Co mmon Language Infrastructure 9 I.6.1 Relationship to type safety 9 I.6.2 Relationship to managed metadata -dri
5、ven execution 10 I.6.2.1 Managed code 10 I.6.2.2 Managed data 11 I.6.2.3 Summary 11 I.7 Common Language Specification 12 I.7.1 Introduction 12 I.7.2 Views of CLS co mpliance 12 I.7.2.1 CLS framework 12 I.7.2.2 CLS consumer 13 I.7.2.3 CLS extender 13 I.7.3 CLS co mpliance 14 I.7.3.1 Marking items as
6、CLS -compliant 14 I.8 Common Type System 16 I.8.1 Relationship to object -oriented programming 19 I.8.2 Values and types 19 I.8.2.1 Value types and reference types 19 I.8.2.2 Built-in value and reference types 20 I.8.2.3 Classes, interfaces, and objects 21 I.8.2.4 Boxing and unboxing of values 21 I.
7、8.2.5 Identity and equality of values 22 I.8.3 Locations 23 I.8.3.1 Assignment-compatible locations 23 I.8.3.2 Coercion 23 I.8.3.3 Casting 24 ISO/IEC 23271:2012(E) iv ISO/IEC 2012 All rights reserved. I.8.4 Type members 24 I.8.4.1 Fields, array elements, and values 24 I.8.4.2 Methods 24 I.8.4.3 Stat
8、ic fields and static methods 25 I.8.4.4 Virtual methods 25 I.8.5 Naming 25 I.8.5.1 Valid names 25 I.8.5.2 Assemblies and scoping 26 I.8.5.3 Visibility, accessibility, and security 27 I.8.6 Contracts 30 I.8.6.1 Signatures 30 I.8.7 Assignment compatibility 34 I.8.7.1 Assignment compatibility for signa
9、ture types 37 I.8.7.2 Assignment compatibility for location types 38 I.8.7.3 General assignment compatibility 39 I.8.8 Type safety and verification 39 I.8.9 Type definers 39 I.8.9.1 Array types 40 I.8.9.2 Unmanaged pointer types 41 I.8.9.3 Delegates 41 I.8.9.4 Interface type definition 42 I.8.9.5 Cl
10、ass type definition 43 I.8.9.6 Object type definitions 44 I.8.9.7 Value type definition 47 I.8.9.8 Type inheritance 47 I.8.9.9 Object type inheritance 47 I.8.9.10 Value type inheritance 48 I.8.9.11 Interface type derivation 48 I.8.10 Member inheritance 48 I.8.10.1 Field inheritance 48 I.8.10.2 Metho
11、d inheritance 48 I.8.10.3 Property and event inheritance 49 I.8.10.4 Hiding, overriding, and layout 49 I.8.11 Member definitions 50 I.8.11.1 Method definitions 50 I.8.11.2 Field definitions 51 I.8.11.3 Property definitions 51 I.8.11.4 Event definitions 52 I.8.11.5 Nested type definitions 52 ISO/IEC
12、23271:2012(E) ISO/IEC 2012 All rights reserved. v I.9 Metadata 53 I.9.1 Components and assemblies 53 I.9.2 Accessing metadata 53 I.9.2.1 Metadata tokens 54 I.9.2.2 Member signatures in metadata 54 I.9.3 Unmanaged code 54 I.9.4 Method implementation metadata 54 I.9.5 Class layout 55 I.9.6 Assemblies:
13、 name scopes for types 55 I.9.7 Metadata extensibility 56 I.9.8 Globals, imports, and exports 57 I.9.9 Scoped statics 58 I.10 Name and type rules for the Co mmon Language Specification 59 I.10.1 Identifiers 59 I.10.2 Overloading 59 I.10.3 Operator overloading 60 I.10.3.1 Unary operators 60 I.10.3.2
14、Binary operators 61 I.10.3.3 Conversion operators 62 I.10.4 Naming patterns 62 I.10.5 Exceptions 63 I.10.6 Custom attributes 63 I.10.7 Generic types and methods 64 I.10.7.1 Nested type parameter re -declaration 64 I.10.7.2 Type names and arity encoding 65 I.10.7.3 Type constraint re -declaration 66
15、I.10.7.4 Constraint type restrictions 67 I.10.7.5 Frameworks and accessibility of nested types 67 I.10.7.6 Frameworks and abstract or virtual methods 68 I.11 Collected Co mmon Language Specification rules 69 I.12 Virtual Execution System 72 I.12.1 Supported data types 72 I.12.1.1 Native size: native
16、 int, native unsigned int, O and & 73 I.12.1.2 Handling of short integer data types 74 I.12.1.3 Handling of floating -point data types 75 I.12.1.4 CIL instructions and numeric types 76 I.12.1.5 CIL instructions and pointer types 77 I.12.1.6 Aggregate data 78 ISO/IEC 23271:2012(E) vi ISO/IEC 2012 All
17、 rights reserved. I.12.2 Module information 81 I.12.3 Machine state 81 I.12.3.1 The global state 81 I.12.3.2 Method state 82 I.12.4 Control flow 85 I.12.4.1 Method calls 86 I.12.4.2 Exception handling 89 I.12.5 Proxies and remoting 99 I.12.6 Memory model and optimizations 100 I.12.6.1 The memory sto
18、re 100 I.12.6.2 Alignment 100 I.12.6.3 Byte ordering 100 I.12.6.4 Optimization 100 I.12.6.5 Locks and threads 101 I.12.6.6 Atomic reads and writes 102 I.12.6.7 Volatile reads and writes 102 I.12.6.8 Other memory model issues 103 II.1 Introduction 105 II.2 Overview 106 II.3 Validation and verificatio
19、n 107 II.4 Introductory exa mples 108 II.4.1 108 II.4.2 Other examples 108 II.5 General syntax 109 II.5.1 General syntax notation 109 II.5.2 Basic syntax categories 109 II.5.3 Identifiers 110 II.5.4 Labels and lists of labels 111 II.5.5 Lists of hex bytes 111 II.5.6 Floating-point numbers 111 II.5.7
20、 Source line information 112 II.5.8 File names 112 II.5.9 Attributes and metadata 112 II.5.10 ilasm source files 112 II.6 Assemblies, manifests and modules 114 II.6.1 Overview of modules, assemblies, and files 114 II.6.2 Defining an assembly 115 II.6.2.1 Information about the assembly ( AsmDecl) 115
21、 ISO/IEC 23271:2012(E) ISO/IEC 2012 All rights reserved. vii II.6.2.2 Manifest resources 118 II.6.2.3 Associating files with an assembly 118 II.6.3 Referencing assemblies 118 II.6.4 Declaring modules 119 II.6.5 Referencing modules 120 II.6.6 Declarations inside a module or assembly 120 II.6.7 Export
22、ed type definitions 120 II.6.8 Type forwarders 121 II.7 Types and signatures 122 II.7.1 Types 122 II.7.1.1 modreq and modopt 123 II.7.1.2 pinned 123 II.7.2 Built-in types 124 II.7.3 References to user -defined types ( TypeReference ) 124 II.7.4 Native data types 125 II.8 Visibility, accessibility an
23、d hiding 127 II.8.1 Visibility of top -level types and accessibility of nested types 127 II.8.2 Accessibility 127 II.8.3 Hiding 127 II.9 Generics 128 II.9.1 Generic type definitions 128 II.9.2 Generics and recursive inheritance graphs 129 II.9.3 Generic method definitions 130 II.9.4 Instantiating ge
24、neric types 131 II.9.5 Generics variance 132 II.9.6 Assignment compatibility of instantiated types 132 II.9.7 Validity of member signatures 133 II.9.8 Signatures and binding 134 II.9.9 Inheritance and overriding 135 II.9.10 Explicit method overrides 136 II.9.11 Constraints on generic parameters 137
25、II.9.12 References to members of generic types 138 II.10 Defining types 139 II.10.1 Type header ( ClassHeader) 139 II.10.1.1 Visibility and accessibility attributes 140 II.10.1.2 Type layout attributes 141 II.10.1.3 Type semantics attributes 141 II.10.1.4 Inheritance attributes 142 ISO/IEC 23271:201
26、2(E) viii ISO/IEC 2012 All rights reserved. II.10.1.5 Interoperation attributes 142 II.10.1.6 Special handling attributes 142 II.10.1.7 Generic parameters ( GenPars) 143 II.10.2 Body of a type definition 146 II.10.3 Introducing and overriding virtual methods 147 II.10.3.1 Introducing a virtual metho
27、d 147 II.10.3.2 The .override directive 147 II.10.3.3 Accessibility and overriding 148 II.10.3.4 Impact of overrides on derived classes 149 II.10.4 Method implementation requirements 150 II.10.5 Special members 150 II.10.5.1 Instance constructor 150 II.10.5.2 Instance finalizer 151 II.10.5.3 Type in
28、itializer 151 II.10.6 Nested types 153 II.10.7 Controlling instance layout 153 II.10.8 Global fields and methods 154 II.11 Semantics of classes 156 II.12 Semantics of interfaces 157 II.12.1 Implementing interfaces 157 II.12.2 Implementing virtual methods on interfaces 157 II.12.2.1 Interface Impleme
29、ntation Examples 159 II.13 Semantics of value types 162 II.13.1 Referencing value types 163 II.13.2 Initializing value types 163 II.13.3 Methods of value types 164 II.14 Semantics of special types 166 II.14.1 Vectors 166 II.14.2 Arrays 166 II.14.3 Enums 168 II.14.4 Pointer types 169 II.14.4.1 Unmana
30、ged pointers 170 II.14.4.2 Managed pointers 171 II.14.5 Method pointers 171 II.14.6 Delegates 172 II.14.6.1 Delegate signature compatibility 173 II.14.6.2 Synchronous calls to delegates 174 II.14.6.3 Asynchronous calls to delegates 175 ISO/IEC 23271:2012(E) ISO/IEC 2012 All rights reserved. ix II.15
31、 Defining, referencing, and calling methods 177 II.15.1 Method descriptors 177 II.15.1.1 Method declarations 177 II.15.1.2 Method definitions 177 II.15.1.3 Method references 177 II.15.1.4 Method implementations 177 II.15.2 Static, instance, and virtual methods 177 II.15.3 Calling convention 178 II.1
32、5.4 Defining methods 179 II.15.4.1 Method body 180 II.15.4.2 Predefined attributes on methods 182 II.15.4.3 Implementation attributes of methods 184 II.15.4.4 Scope blocks 186 II.15.4.5 vararg methods 186 II.15.5 Unmanaged methods 187 II.15.5.1 Method transition thunks 187 II.15.5.2 Platform invoke
33、188 II.15.5.3 Method calls via function pointers 189 II.15.5.4 Data type marshaling 189 II.16 Defining and referencing fields 190 II.16.1 Attributes of fields 190 II.16.1.1 Accessibility information 191 II.16.1.2 Field contract attributes 191 II.16.1.3 Interoperation attributes 191 II.16.1.4 Other a
34、ttributes 192 II.16.2 Field init metadata 192 II.16.3 Embedding data in a PE file 193 II.16.3.1 Data declaration 193 II.16.3.2 Accessing data from the PE file 194 II.16.4 Initialization of non -literal static data 194 II.16.4.1 Data known at link time 194 II.16.5 Data known at load time 195 II.16.5.
35、1 Data known at run time 195 II.17 Defining properties 196 II.18 Defining events 198 II.19 Exception handling 201 II.19.1 Protected blocks 201 II.19.2 Handler blocks 201 ISO/IEC 23271:2012(E) x ISO/IEC 2012 All rights reserved. II.19.3 Catch blocks 202 II.19.4 Filter blocks 202 II.19.5 Finally block
36、s 203 II.19.6 Fault handlers 203 II.20 Declarative security 204 II.21 Custo m attributes 205 II.21.1 CLS conventions: custom attribute usage 205 II.21.2 Attributes used by the CLI 205 II.21.2.1 Pseudo custom attributes 206 II.21.2.2 Custom attributes defined by the CLS 207 II.21.2.3 Custom attribute
37、s for security 207 II.21.2.4 Custom attributes for TLS 207 II.21.2.5 Custom attributes, various 208 II.22 Metadata logical forma t: tables 209 II.22.1 Metadata validation rules 210 II.22.2 Assembly : 0x20 211 II.22.3 AssemblyOS : 0x22 212 II.22.4 AssemblyProcessor : 0x21 212 II.22.5 AssemblyRef : 0x
38、23 212 II.22.6 AssemblyRefOS : 0x25 213 II.22.7 AssemblyRefProcessor : 0x24 213 II.22.8 ClassLayout : 0x0F 214 II.22.9 Constant : 0x0B 216 II.22.10 CustomAttribute : 0x0C 216 II.22.11 DeclSecurity : 0x0E 218 II.22.12 EventMap : 0x12 220 II.22.13 Event : 0x14 220 II.22.14 ExportedType : 0x27 222 II.2
39、2.15 Field : 0x04 223 II.22.16 FieldLayout : 0x10 225 II.22.17 FieldMarshal : 0x0D 226 II.22.18 FieldRVA : 0x1D 227 II.22.19 File : 0x26 227 II.22.20 GenericParam : 0x2A 228 II.22.21 GenericParamConstraint : 0x2C 229 II.22.22 ImplMap : 0x1C 230 II.22.23 InterfaceImpl : 0x09 231 II.22.24 ManifestReso
40、urce : 0x28 231 II.22.25 MemberRef : 0x0A 232 ISO/IEC 23271:2012(E) ISO/IEC 2012 All rights reserved. xi II.22.26 MethodDef : 0x06 233 II.22.27 MethodImpl : 0x19 236 II.22.28 MethodSemantics : 0x18 237 II.22.29 MethodSpec : 0x2B 238 II.22.30 Module : 0x00 239 II.22.31 ModuleRef : 0x1A 239 II.22.32 N
41、estedClass : 0x29 240 II.22.33 Param : 0x08 240 II.22.34 Property : 0x17 241 II.22.35 PropertyMap : 0x15 242 II.22.36 StandAloneSig : 0x11 243 II.22.37 TypeDef : 0x02 243 II.22.38 TypeRef : 0x01 247 II.22.39 TypeSpec : 0x1B 248 II.23 Metadata logical forma t: other structures 249 II.23.1 Bitmasks an
42、d flags 249 II.23.1.1 Values for AssemblyHashAlgorithm 249 II.23.1.2 Values for AssemblyFlags 249 II.23.1.3 Values for Culture 249 II.23.1.4 Flags for events EventAttributes 250 II.23.1.5 Flags for fields FieldAttributes 250 II.23.1.6 Flags for files FileAttributes 251 II.23.1.7 Flags for Generic Pa
43、rameters GenericParamAttributes 251 II.23.1.8 Flags for ImplMap PInvokeAttributes 251 II.23.1.9 Flags for ManifestResource ManifestResourceAttributes 252 II.23.1.10 Flags for methods MethodAttributes 252 II.23.1.11 Flags for methods MethodImplAttributes 253 II.23.1.12 Flags for MethodSemantics Metho
44、dSemanticsAttributes 253 II.23.1.13 Flags for params ParamAttributes 253 II.23.1.14 Flags for properties PropertyAttributes 254 II.23.1.15 Flags for types TypeAttributes 254 II.23.1.16 Element types used in signatures 255 II.23.2 Blobs and signatures 257 II.23.2.1 MethodDefSig 259 II.23.2.2 MethodRe
45、fSig 260 II.23.2.3 StandAloneMethodSig 261 II.23.2.4 FieldSig 262 II.23.2.5 PropertySig 262 II.23.2.6 LocalVarSig 263 ISO/IEC 23271:2012(E) xii ISO/IEC 2012 All rights reserved. II.23.2.7 CustomMod 263 II.23.2.8 TypeDefOrRefOrSpecEncoded 264 II.23.2.9 Constraint 264 II.23.2.10 Param 264 II.23.2.11 R
46、etType 265 II.23.2.12 Type 265 II.23.2.13 ArrayShape 265 II.23.2.14 TypeSpec 266 II.23.2.15 MethodSpec 266 II.23.2.16 Short form signatures 267 II.23.3 Custom attributes 267 II.23.4 Marshalling descriptors 269 II.24 Metadata physical layout 271 II.24.1 Fixed fields 271 II.24.2 File headers 271 II.24
47、.2.1 Metadata root 271 II.24.2.2 Stream header 272 II.24.2.3 #Strings heap 272 II.24.2.4 #US and #Blob heaps 272 II.24.2.5 #GUID heap 272 II.24.2.6 # stream 273 II.25 File format extensions to PE 277 II.25.1 Structure of the runtime file format 277 II.25.2 PE headers 277 II.25.2.1 MS-DOS header 278
48、II.25.2.2 PE file header 278 II.25.2.3 PE optional header 279 II.25.3 Section headers 281 II.25.3.1 Import Table and Import Address Table (IAT) 282 II.25.3.2 Relocations 282 II.25.3.3 CLI header 283 II.25.4 Common Intermediate Language physical layout 284 II.25.4.1 Method header type values 285 II.25.4.2 Tiny format 285 II.25.4.3 Fat format 285 II.25.4.4 Flags for method headers 285 II.25.4.5 Method data section 286 II.25.4.6 Exception