5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 491

Index

16-bit integers, 26, 27, 325 Abstract record types, 387 16-bit Unicode code, 26, 27 Access methods, 422 32-bit integers, 26, 27, 325 Accessibility, 473 64-bit integers, 26, 27, 325 Accessibility levels, 58–59 Activation record, 141 AboutBox assembly Activator class, 84 Assembly Linker, 162–163 Active Oberon, 441 building second version, 173–174 abstract data types, 454 embedded resources, 158–160 active object types, 441 linked resources, 160–162 active objects, 442–446 revised makefile, 169 agents, 442–446 AboutBox class, 154 aggregation, 441 AboutBox component assemblies, 468–469 developing into assembly, 153–157 assertion-oriented synchronization, 467 version 1, 153–154 AWAIT statement, 445 AboutBoxBase base class, 153, 154 base method calls, 468 AboutBoxBase.cs file, 153 block statement, 442 AboutBox.cs file, 154–155 compiling definitions, 460–461 AboutBox.dll file, 154–155, 156, 163 compiling modules, 459–460 AboutBoxEmbed directory, 158 components produced by foreign AboutBoxGAC directory, 168 languages, 464 AboutBoxGACV2 directory, 173 definitions, 441, 446–454, 458 ..\AboutBox.key file, 168 delegates, 468 AboutBoxLinkedAL subdirectory, 162 elements of module scope, 456 AboutBox.net module, 163 exception handling, 468 AboutBoxSample namespace, 154 fields, 468 Abstract classes, 446 IMPLEMENTS relation, 441, 458 Abstract data types, 454 IMPORTS relation, 441, 458 Abstract execution environment, 105 interoperability, 463–466 491 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 492

492 Programming in the .NET Environment

Active Oberon continued add instruction, 111 intersecting chains of refinement, 452–453 add_EventName method, 37 intrinsic behavior, 442 add_OnClick() function, 338–339 language fitting, 467–469 AddRef method, 314, 315 lightweight object usage, 450 AddressOf expression, 322 mapping active behavior, 466–467 ADO.NET, 223, 254–256 mapping definitions, 461–463 Advanced interoperability and unsafe code, mapping modules, 459–461 340 module class, 459 Agents, 442–446 modules, 455–456, 458 Aggregation, 441 multiple inheritance at compile time, 451 Algol 60, 432 mutual exclusion, 467 Allen, Paul, 297 namespaces, 464–465, 468 AndAlso operator, 326 nesting procedures, 469 ANSI C, 5 OBJECT keyword, 444 API (application program interface), 222, 247 object model, 451 AppDomain class, 121 object type automatically running as Applet base class, 450 thread, 442 Application configuration files, 200, 205, 208, object types, 458 211, 217 overloading methods, 468 Application directory, 131 packages, 455–456 Application Domain policy level, 134 passive objects, 442–445 Application domains, 85, 473 pointer-based object types, 444 assemblies, 120–121 polymorphic declarations, 454 creation of, 188–189 polymorphism, 442 displaying, 121 record types, 468 execution system, 119–121 recursive descent strategy, 457 loading assemblies into, 189–192 REFINES relation, 441, 458 manipulating, 121, 188–189 reusable components, 465 passing object handle between, 191 shared resources, 442–443 versus processes, 186–187 stack engine model, 457–458 threads, 120–121 static modules, 441, 455–456 usage, 187 symmetry, 448 Applications, 147, 457, 473 syntax, 442 concepts and services, 13 type-specific object variable declarations, configuration files, 174–176, 195–205, 454 197–204 USES clause, 442 debugging, 199 value types, 468 deploying, 195 Active object types, 441, 467 existing technologies solving problems, Active objects, 442–446 149–152 ActiveState Perl Dev Kit Web site, 380 installing, 217–226 ActiveX Test Container, 84 internationalization, 176–186 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 493

Glossary 493

Internet protocols to send and receive building applications, 287 data, 261–263 configuration files, 200 locale information, 148 configuration options, 199 localization, 176–186 events using standard HTML and .NET Framework, 12–13 ECMAScript, 213 non-ASCII string technology, 176 functionality of, 287–289 private assemblies, 164 server controls, 213 retrieving current information, 187–188 Web controls, 213–216 reuse, 13 Assemblies, 14, 32, 152–153, 457, 474 search paths, 149–150 acting in type-safe manner, 113 separation of code and user interfaces, Active Oberon, 468–469 177–178 application domains, 120–121 simplifying development, 237–238 Assembly Linker, 162–163 string literals, 177 assembly manifest, 152–153 symbolic names, 150 authenticity, 165 text-based configuration files, 196–197 Authenticode signature, 165 traditional model for building, 147–148 binding to different version, 174–176 Trojan Horse components, 148 building second version, 173–174 Unicode, 176–177 caches, 165–168 version conflicts, 148 checking, 113–114 versioning-related technologies, 150–151 checking types, 114 well-known locations, 149 configuration files, 208 Windows Registry, 151–152 delayed signing, 172 apply methods, 408–410 development of AboutBox component as, Array classes, 48 153–157 Array objects, 49 domain-neutral, 120 Array types, 307 domain-specific, 120 ArrayList class, 250, 253, 335–336 download cache, 166 Arrays, 391, 474 embedded resources, 157–162 bounds for each dimension, 307 GAC (Global Assembly Cache), 165–166 Component Pascal, 386, 391–394 generating from type library, 282 CTS (Common Type System), 392 identities, 172 encoding rank within type, 306 information about, 61, 87 entire assignment, 393 isolating, 212 as fixed-size structure, 435 linked resources, 157–162 lower bounds of each dimension, 307–308 linking files and modules into, 162–163 reference surrogates, 391–394 loading into application domains, 189–192 Visual Basic .NET, 306–309 localization, 178 ASCII character set, 27, 273–278 makefile files, 154, 156–157 ASP (Application Server Pages), 235–237 managing caches, 166–168 ASP pages, HTML generated for, 215–216 metadata, 113–114 ASP.NET, 12, 230 nmake utility, 154–155 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 494

494 Programming in the .NET Environment

Assemblies continued AuthorAttribute class, 79 PerlNET Component Builder, 377 AWAIT statement, 445 permission sets, 133, 134–141 AWT (Abstract Windows Toolkit), 11 permissions, 130–131 policy evaluation, 139 Backing stores, 259–260 private, 163–172, 208 Base classes, 248–250, 304 public, 163–172 implicit inheritance from, 15 public and private key pair, 164, 168 overloaded virtual methods, 360 referencing external, 210 Base Framework, 8, 10, 26, 229, 474 referencing with codeBase element, interface types, 48 208–211 object-oriented design, 232–233 Registry entries, 99 Base methods, 468 self-describing, 88 BaseType property, 68, 70 signed, 161, 165–166 BASIC, 297 strong names, 88, 164–165, 168, 172, 208 Basic type system, 116 trust issues, 165 BASIC-A, 297 type library description, 99 BCL (Base Class Library), 26, 127, 221, 229 verifying for type safety, 113–114 predefined standard attributes, 80–83 version discrimination, 174 BEGIN blocks, 372 version number, 88–89 bin directory, 149 visibility, 391 Binary configuration files, 196 Win32 version information, 172 Binding information, 85 Assembly accessibility level, 58 Binding to different version assemblies, Assembly Linker, 162–163, 168, 172, 184, 209 174–176 Assembly manifests, 86–92, 152–153, bindingRedirect element, 175, 198 161–162, 474 Block statement, 442 assemblyBinding subelement, 198 BOA (Basic Object Adapter), 105 AssemblyBuilder.GetManifestResource- bool type, 27 Stream() function, 160 Boolean class, 252 assemblyIdentity element, 198, 211 Boolean type, 26, 27, 43, 252 AssemblyQualifiedName property, 68, 70 Boolean values, 26, 27 Assert model, 141–142 box instruction, 106 Asserting permissions, 141–142 Boxed types, 39–40, 46, 309–310 Assertion-oriented synchronization, 467 Boxing, 332–333, 474–475 Assertions, 474 Hotdog Scheme, 412 Assignment compatibility, 54–56 Boxing value types, 39 Assignment-compatible types, 40 Browsing support, 263–266 Asynchronous execution pattern, 237 BSD UNIX, 220 Attribute class, 79 PAL (Platform Adaptation Layer), 222 Attributes, 337–338 SSCLI (Shared Source Common Language AttributeSample class, 79, 80 Infrastructure), 224–226 AttributeUsage attribute, 78 Buffering stream, 260 Australian culture, testing, 185 Builder classes, 93 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 495

Index 495

Built-in data types, 475 sets, 139–141 Built-in value types, 25–29 fitting into CLR (Common Language Button class, 334 Runtime), 331 ButtonPenControl abstraction feature, 454 flexibility, 331–332 ButtonSensor abstraction feature, 453 foreach statement, 73, 341–342 ByRef variant behavior, simulating, 310–311 function value returned, 427 Byte class, 251 future, 347–348 byteBuffer instance, 340 general collection classes, 411 header file, 61 generating IL (Intermediate Language), heap allocation, 122 106–112 primitive built-in types, 21 generating user interfaces, 437 standard library, 231 generics, 347–348 user-defined types, 21 GUI executable, 156 HelloWorldCS class, 17–18

C#, 404 history, 329–330 += operator, 338 indexers, 335–336 -= operator, 338 /linkresource: option, 160 abstract classes, 446 makefile file, 156 attributes, 337–338 operator overloading, 336–337 boxing, 56, 332–333 parameterized property, 336 building assembly, 156 parameterized types, 347 code references types, 156 params arrays, 343–344 combining delegates, 338 params keyword, 43 combining with Mondrian in Sieve of pointers, 339–340 Eratosthenes, 435–437 properties, 333–335 comfortable for C++ programmers, 331 properties as virtual fields, 335 , 158 reference types, 332–333 component-oriented development, remove function, 339 333–339 removing delegates, 338 defining default indexed property, 242–243 Sieve of Eratosthenes, 435 defining interfaces, 333 simplifying C++ model, 331 definition and use of events in value types, sorting example, 426 37–38 stack component example, 344–347 definition of function with params standardization, 348 keyword, 343–344 strings, 46 delegates, 338 struct, 34 design goals, 330–332 supertype, 424 destructor, 41 supporting component-centric divide-by-zero exception, 431 development, 332 entry point for program, 33 switch statement based on string values, enumerators, 341 342–343 events, 338–339 type system, 332–333 examining policy levels and permission typeof keyword, 70–71 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 496

496 Programming in the .NET Environment

C# continued Characters, 27 unsafe code, 339–341 CIL (Common Intermediate Language), 25, usage, 316 106, 384, 476 user-defined types, 333 classifying verification status, 114–115 using construct, 261–262 executing un-type-safe, 113 value types, 332–333 illegal, 115 XML comments, 344 lack of optimization, 112 C++, 234 legal, 115 abstract classes, 446 not type-safe, 114 applications running in semi-trusted type-safe, 114–115 environments, 232 verifiable, 115 classes, 21 cil keyword, 109 header file, 61 CIL/IL (Common Intermediate heap allocation, 122 Language/Intermediate Language), 103 HelloWorldCPP class, 15–16 Circle type, 387, 399, 400 history, 329–330 Circular references, 314–315 iostream library, 231 class keyword, 31, 333 libraries, 21 Class libraries, 221–222, 236, 480–481 multiple inheritance at runtime, 451 consistent, 239 object-oriented design, 232–233 indexed properties, 242–243 RTTI (run-time type information), 3 member usage, 241–248 supporting .NET run-time environment, method usage, 243–245 330 multilanguage, 239 CalculateValue method, 299 naming guidelines, 239–241 call instruction, 109–110 object-oriented design, 232–233 Call-by-name, 432 predictable, 239 Calling properties versus methods, 241–242 .NET objects, 279–282 secure, 239 other CLR-hosted languages, 433–434 type usage, 245–248 callvirt instruction, 106 class method, 427 Camel casing, 240 Classes, 13, 40–47, 50, 104 Canonical language, 462 base for, 10 CAS (Code Access Security, aka Evidence C++, 21 Based Security), 476 constructors, 74 Case-insensitive languages, 240 defining cultures, 256–257 Case-lambda special form, 410–411 dotted names, 390 Case-sensitive languages, 240 identity, 127 Casing, 239–241 inheritance, 15, 236 Catch handler, 319 in-memory data storage and .cctor constructor, 74 manipulation, 250, 253–254 char array overload, 244 versus interfaces, 246 Char class, 252 late binding, 319 CHAR type, 388 methods, 66 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 497

Index 497

naming, 241 array types with fixed lower bounds of private, 390 zero, 308 public, 390 CLS Consumers, 476 reflection, 65–69 CLS Extenders, 476 as reusable components, 465 CLS Frameworkers, 476 runtime, 390 CLS-compliant, 475 use as array, 335–336 COBOL Visual Basic, 298–299 conversion from string to char array, Visual Basic .NET, 298–301 244 Clear method, 49 HelloWorldCOB class, 16–17 CLI (Common Language Infrastructure), 8, Code 477 reusing, 236 assembly boundary, 389 separation from user interfaces, 177–178 configuration files, 197–204 specifying location, 49–50 non-Windows platforms, 220 Code Access security (aka Evidence Based Closure, 407–411, 429, 432 Security), 273 environments, 409 Code groups, 135–138 general implementation, 408–409 codeBase element, 208–211, 218 Hotdog Scheme compiler, 414 CodeBase property, 207 multiple entry points, 410–411 Code-based security, 143–144 variable argument lists, 409–410 Coercion, 476 Closure class, 408–409, 414 Collection classes, concrete implementations, 250 case-lambda form, 411 CollectionBase class, 253 CLR (Common Language Runtime), 2, 8, 404, 406, 477 COM (Component Object Model), 1, 6–7, 104–105, 297 automatic memory management, 121–126 aggregation, 451 delegates, 428 attributes, 34 execution system, 9, 14 components, 223 field-only class, 422 concepts mapped to .NET concepts, 300 functional languages, 418 Currency type, 312 mapping Component Pascal to, 389–396 Date variable, 312 metadata system, 9 Decimal type, 312 parametric types, 424, 425 delegation, 451 primitive types, 421 dynamic type discovery, 84 interaction, 22–23 event interfaces, 321 subtyping through class inheritance, 423 events, 37 surrogate array, 393 IDL files, 63–64 type system, 9, 13–14 implementation inheritance, 451 Windows PE (Portable Executable) file layout, 95 interoperating with, 281–282 CLR programs, 116 IUnknown interface, 39 CLS (Common Language Specification), 9, late binding, 317, 319 233, 477 limitations, 7 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 498

498 Programming in the .NET Environment

COM (Component Object Model) continued enhancing table mechanisms, 400 multiple programming languages support, exception-handling facilities, 399 233 extensible records, 394 objects deterministically finalized, 314 final methods, 387 one-dimensional arrays, 307 fixed-length arrays, 388 proxy objects and implementation code hello world program, 385 generation at IDL compile time, 105 inherited methods, 387 reference counting mechanism, 314 invoking constructors with arguments, 400 Safearrays, 306–307 library methods throwing exceptions, 399 transferring dates from, 313 mapping program structure, 389 type library, 6, 64, 282 mapping to CLR, 389–396 unit of identity changes, 299–300 mapping type system, 391–394 COM Interop (COM Interoperability), methods, 387 99–102, 280, 281–282, 476 methods associated with record types, 396 altering assembly name, 282 module structure, 389 generating assembly from type library, 282 modules, 390 mechanisms, 226 nested procedures, 388, 390 pointers, 340 nonlocal addressing, 397–398 COM objects object-oriented language, 385 accessing from .NET objects, 280 open array construct, 386 instance of, 84 optional language extensions, 385 Command object, 255 performance, 400–401 Common functionality, 236 pointers, 386 Compact Framework, 220–223 polymorphism, 386 _com_params_ variable, 360 procedure variable types, 398 Comparing strings, 44 record type definitions, 386 Compiler-controlled accessibility level record types implementing defined directly generating metadata, 64 interfaces, 399 Compiling for the .NET Common Language records, 386 Runtime, 401 reference class, 395 Component Pascal, 383 reference surrogates, 391–394 8-bit formal parameters, 391 sealed types, 387 Ada-like annotations, 386 semantic challenges, 397–398 alias reference, 388 single implementation inheritance, 385 arrays, 386, 391–394 statements, 388 box instruction, 395 static procedures, 391 built-in types, 386, 387–388 static record types, 394–395 choice statements, 388 static variables, 391 compatibility extensions, 399 static variables and local variables of array controlling visibility, 390–391 or record types, 387 covariant function types, 398 structural compatibility of delegates, 398 dispatched methods, 396 synthetic static class, 390, 391 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 499

Index 499

type case statement, 388 format, 197–198 type system, 386–388 GAC, 211 type-bound procedures, 387, 396 machine, 199–200 as type-safe language, 384 schema, 198–199 value classes, 395 security, 200 value semantics, 388 testing, 176 verifiable code, 384 text-based, 196–197 XHR (explicit heap-allocated records), XML files, 197 397–398 Connection object, 255 Component Pascal Web site, 401 Connection point, 321 Component-oriented development, 333–339 const string, 271 Components ConstructorInfo class, 66, 73 consumers and producers of, 458 ConstructorName type, 66 internationalization, 176–186 Constructors, 50, 66, 74 local representation of, 99 arguments, 85 localization, 176–186 strings, 44 packaging for other programs, 86–92 Content hosted on slow resource, 166 reusing, 31 Contracts, 114, 477 Trojan Horse, 148 Control object type, 448 version conflicts, 148 Conversion method, 45 Compound operators, 326 Copying files to computer, 217 _com_return_type_ variable, 15, 360 COR namespace, 359 Concatenate method, 45 CORBA (Common Object Request Broker Concatenating strings, 45 Architecture), 1 Concrete classes, 446 attributes, 34 Concurrency support, 419–420 dynamic type discovery, 84 Concurrent Hope+C, 420 Event Service, 37 Conditional expressions, 135 events, 37 .config file extension, 175, 200 IDL files, 63–64 /configSections element, 201 interface repository, 6, 64 configuration element, 198 interoperability, 105 Configuration files limitations, 7 application, 200 multiple programming languages support, applying different versioning policies, 233 174–176 Object interface, 39 ASP.NET, 200 platform independence, 105 assemblies, 208 POA (Portable Object Adapter), 5 binary, 196 proxy objects and implementation code choosing, 204–205 generation at IDL compile time, 105 CLI, 197–204 CORBA specification, 99 codeBase element, 208, 218 cordbg, 116–119, 121, 191 custom configuration sections, 200–204 Core DOM Level 2, 293 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 500

500 Programming in the .NET Environment

corhdr.h header file, 96 CurrentUICulture, 258 Covariant function types, 398 Custom attributes, 19, 67, 104, 477 CPAN (Comprehensive Perl Archive as classes, 77 Network), 371 compilers not understanding, 77 CPython, 353, 358 definition and use of, 77–80 extension modules, 357 inheritance, 77 parser, 355, 359 Custom configuration sections, 200–204 python modules, 357 Custom protocols, 289 type object, 356 Customizing CPython API, 357 encryption providers, 199 create construct, 434 virtual methods, 248 CreateChildControls method, 213 CreateComInstanceFrom method, 84 Data, separate and distinct from data stores, CreateFontIndirect method, 280 255 CreateInstance method, 84, 85, 190 DataAdapter class, 255 CreateInstanceFrom method, 84 DataReader class, 255 CreateNewInstance method, 301 DataSet class, 255, 293 Cross-language Date data type, 313 compatibility, 18 Date variable, 312 inheritance, 236 Dates, 312–313 method invocation, 4 DateTime class, 313 cryptographySettings element, 199 DCE (Distributed Computing C-style APIs, 234 Environment’s) RPC (Remote Procedure C-style enumerations, 247 Call), 6 .ctor instance constructor, 74 DCOM (Distributed Component Object Model), 6 CTS (Common Type System), 389, 391, 457 Debugging, 116–119, 199, 477 arrays, 392 Decimal class, 252 value classes, 392, 394 Decimal type, 312 Culture tags, 178 Declarative security check, 477–478 CultureInfo class, 182, 185, 256 Declarative security constraints, 144–145 Culture-neutral resources, 180, 185 Deep copy, 42 Culture-neutral strings, 182 Def statements, 325 Cultures Default constructor, 32 classes defining, 256–257 Default indexed properties, 243 country/region code, 178 Definitions, 96–97, 441 information, 85 Active Oberon, 458 language code, 178 compiling, 460–461 printing out date, 256–257 derived from foreign classes, 465 valid and invalid strings, 185 implementing, 447 Culture-specific data, 257–259 mapping, 461–463 Currency type, 312 refining, 447–448 Current method, 48 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 501

Index 501

units of service, 447 Dotted names and classes, 390 Delayed signing, 172 Double class, 252 Delegates, 37, 49, 468 Downcasting, 56 C#, 338 Download cache, 166 declaration, 52 downloaded assemblies, 218 multicast, 321 listing contents, 212 returning of void, 52 managing, 166–168 structured compatibility of, 398 Downloading Visual Basic .NET, 321–324 files to computer, 217–218 Delphi, 234 Web content, 205–216 Demand method, 144 DTD schema validation, 293 Demand set, 478 dx7vb.dll assembly, 282 Demands, 478 DxVBLib namespace, 282 Denial of permission, 478 Dynamic discovery of types, 84–86 Deny operation, 141 Dynamic function, 427 Denying permissions, 142 Dynamic invocation, 266 dependentAssembly element, 175, 198 Dynamic language support, 364–365 Deploying applications, 195, 205–207 Dynamic type checking, 20, 412–413 Derived class, 304 Dynamic types, 92–95 Design guidelines, 238–248 Dynamically emitting new types at runtime, Destructor, 41 269–271 Deterministic finalization, 314–316 Dynamically type-checked language, 21 DHTML (Dynamic Hypertext Markup Language), 235 ECMA CLI standards, 220–222 DII (Dynamic Invocation Interface), 84 ECMA Web site, xxvi – xxvii Directories, symbolic names for, 150 Eiffel DirectXWrapper assembly, 282 multiple inheritance at runtime, 451 Dispatched methods, 396 object-oriented design, 232–233 DISPLAY keyword, 17 Embedded resources, 157–162 Dispose method, 287, 315–316 Embedded strings, replacing with string Divide-by-zero exception, 431 resources, 177 .DLL file extension, 22 EmployeeCollection class, 253 DLL hell, 87, 148, 164 EmptyTypes field, 69 DllImportAttribute standard attribute, 83 en-AU directory, 184 DLLs (dynamically linked libraries), 61, 87, en-AU.resources.dll assembly, 184 280 Encapsulation of privileged operations, 229 /DOC compiler, 344 Encrypting stream, 260 DOM (Document Object Model)-level XML Encryption providers, customizing, 199 reader and writer, 237 Enforced asymmetry, 450 DOM node subtree, 293 Enqueue method, 359 Domain-neutral assemblies, 120 Enterprise policy, 137 Domain-specific assemblies, 120 configuration files, 200 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 502

502 Programming in the .NET Environment

Enterprise policy continued Exception handling levels, 134 Active Oberon, 468 enterprisesec.config file, 200 Mondrian, 419 EntryPoint class, 36, 52 PerlNET, 379 EntryPoint object type, 53 Exceptions, 5, 115, 248, 478 enum keyword, 31 .EXE file extension, 22 Enumerating over objects, 341–342 exec method, 409, 410 Enumeration namespace, 31 Executable files, 62, 478 Enumerations, 21, 233, 246 Execution engine, 63 base class, 248 Execution environments, 105–106, 113 defining, 31 Execution issues, 4 usage, 247–248 Execution permission set, 139 user-defined, 30–31 Execution system, 9, 14, 116, 479 EnumerationSample value type, 31 application domains, 119–121 Equality, 24 erroneous or destructive behavior, 113 Equals method, 41 layout of objects in memory, 28 Error handling, 4 making decisions about run-time values, structured, 319–321 28 ETH programming languages history, 442 versus other component models, 104–106 eval statement, 375 platform independence, 103 Event interfaces, 321 security, 19 EventClass class, 38 versioning on types, 19 EventClass value type, 37 export statement, 389 EventInfo class, 66 Extensible records, 394 EventInfo object, 67 Extension modules, 357 Events, 14, 22, 50, 66, 233, 238, 478 adding and removing handler, 322 Family accessibility level, 58 C#, 338–339 Family and Assembly accessibility level, 58 declaring, 322 Family or Assembly accessibility level, 58 defining methods, 37 FCL (Framework Class Library), 29, 229–230 delegate types, 322 garbage collection, 232 delegates, 321–324 namespaces, 248–295 interface types, 47 object-oriented design concepts, 236 Visual Basic .NET, 321–324 simplifying application development, Evidence, 131 237–238 passing to security system, 132–133 FieldInfo class, 66 permission sets based on, 134–141 Field-only class, 422 Evidence-based security (aka Code Access Fields, 14, 50, 66 Security) Active Oberon, 468 evidence, 131–132 instance, 33 permissions, 130–131 interface types, 47 Exact type, 40, 478 properties synonymous with, 241 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 503

Index 503

static, 33 configuration files, 211 WithEvents modifier, 322 fully signed assemblies, 166 FieldType property, 66 managing, 166–168 Figure abstract base type, 399 modifying message.txt file, 170–171 Figure abstraction, 448 gacutil, 168–170 Figure type, 387, 396, 445 /l option, 173 File handles, 236 /ldl option, 212 File system Garbage, 232 reference types, 24–25 Garbage collector, 40, 123–124, 226 value types, 24–25 Gardens Point Component Pascal compiler, FileIOPermission, 273 383–385 Files Gates, Bill, 297 copying to computer, 217 GC (Garbage Collection), 14, 479 downloading, 217–218 generation-based, 125–126 symbolic links, 150 long-lived objects, 124 FileStream class, 259, 260, 273 object's generations, 124 filter function, 436 Visual Basic .NET, 314–316 Finalization methods, 124 __gc keyword, 15 Finalize method, 41, 42 gdi32.dll, 280 FindInterfaces method, 70 General-purpose configuration handlers, 201 FindMembers method, 70 Generation-based garbage collection, fixed statement, 340 125–126 Fixup, 479 Generic C#, 419 Floating-point types, 28–29 GenericIdentity class, 127 for loop, 388 GenericPrincipal class, 127 foreach statement, 48, 341–342 get method, 34, 45, 52, 68 Format method, 45 Get procedure, 458 Format strings, 45 GetAboutText() method, 153, 154 Form_Load method, 287 GetAddMethod method, 66 from function, 436 GetAverage Web service, 291–292 FullName property, 68 GetBaseDefinition method, 66 FullTrust permission set, 139 GetConstructors method, 70 Fully qualified string names, 263, 264 GetCustomAttributes method, 67, 77, 80 Function pointers, unmanaged, 49 GetEnumerator() function, 341 Functional languages, 417–418, 433 GetHashCode method, 41 Functions GetLength method, 48, 49 compiled into class with well-known GetManifestResourceStream() function, 162 method, 426–427 GetMembers method, 67, 71 Mondrian, 426–433 GetMethod method, 68 get_methods, 35 GAC (Global Assembly Cache), 113–114, 165, GetMethods method, 70 168 GetNestedTypes method, 70 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 504

504 Programming in the .NET Environment

GetObject method, 84, 258 HelloWorldForm class, 380 GetParameters method, 66 HelloWorldPY class, 15 GetRaiseMethod method, 66 HelloWorldVB class, 16 GetRemoveMethod method, 66 Heterogeneous generic types, 424 GetString method, 258 Hide by name, 302 GetType method, 41–42, 64, 65, 70, 71, 74, 263 hidebysig keyword, 108 GetValue method, 66 Homogeneous list, 424 get_X method, 36 Hotdog Scheme compiler, 403–404, 406, 415 GIOP (General Inter-ORB Protocol), 105 boxing, 412 GJ [8] for Java, 419 call/cc, 413 Glasgow Haskell Compiler, 439 case-lambda special form, 410–411 Got Dot Net Web site, 349 closure, 414 Grades class, 292 closure arguments, 408 grades class, 291 implementations, 407–413 Grades Web service, 292 interactive environments, 414 Grades.asmx file, 290 JIT compiler, 407 Grant set, 479 performance improvements, 414–415 Grouping related types, 87 type checks, 414–415 GUI (graphical user interface) applications, HTML (Hypertext Markup Language), 235, 11 236 GUIDs (globally unique identifiers), 5 HTML generated for ASP pages, 215–216 GW-BASIC for DOS, 297 httpHandlers section, 201 Hungarian notation, 240 Hammond, Mark, 353 Handles clause, 322 IChanged interface, 52 Hashes, 131 ICloneable interface, 42 Hashtable class, 250 ICollection interface, 253, 344 Haskell IComparable interface, 49, 55 function declaration, 426 Identifiers, 240 homogeneous list, 424 Identities, 24, 126–128 list of integers, 422–423 Identity object, 127 type for coordinate, 421 IDictionary interface, 202 Header file, 61 IDispatch interface, 84, 317, 318 Heap-allocated memory, 122–123 IDisposable interface, 315 Heaps, 95–96, 232 IDL (Interface Definition Language), 6–7, Hello World program, 14–18 63–64, 105 HelloATL component, 99–101 extensions, 76 hello.exe file, 359 interfaces, 7 hello.py file, 358 IDL (Interface Definition Language) files, HelloWorldCOB class, 16–17 63–64 HelloWorldCPP class, 15–16 IDL-based systems, 6–7 HelloWorldCS class, 17–18 IDL-to-language mappings, 105 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 505

Index 505

ID-to-strong mapping, 177 value types, 39 IEEE floating-point standard, 28 Visual Basic .NET, 301–304 IEnumerable contract, 250, 253 Inheritance demand, 480 IEnumerable design pattern, 341 Inherits keyword, 16 IEnumerable interface, 341–342 __init__ constructor method, 15 IEnumerator interface, 48 Initializers, 326 IIdentity interface, 127 Inner type, 56 IIOP (Internet Inter-ORB Protocol), 105 Insert method, 45, 85 IL (Intermediate Language), 480 Installing applications generating, 106–112 copying files to computer, 217 machine independence, 106 downloading files to computer, 217–218 object-oriented, 106 installation programs, 218–219 verification, 112–116 Installing .NET Framework, 219–220 viewing code, 271 InstallShield, 219 ilasm, 384 Instance fields, 14, 33, 480 ILDASM (Intermediate Language instance method, 427 Disassembler), 75, 94, 271 Instance methods, 32–33, 47–48, 480 IList interface, 344 Instances, 14 Illegal CIL, 115 int type, 110 Imperative security check, 479 Int16 type, 26, 27, 251 Imperative style security constraints, Int32 type, 26, 27, 29, 43, 251 144–145 Int64 type, 26, 27, 251 Implementation repositories, 63 Integer array type, 307–308 IMPLEMENTS relation, 441, 446, 454, 458, INTEGER type, 396 461 Integer type, 325 import statement, 357, 389 Integer variables, storage locations, 109 Importing types, 22–23 Integers, 3 IMPORTS relation, 441, 458 native, 28 INamingContainer interface, 213 signed, 9, 28 Indexed properties, 242–243 size, 27 Indexers, 335–336 unsigned, 9, 28 IndexOf method, 45 interface keyword, 333 IndexOfAny method, 244 Interface reference, 53 inetd process, 196 Interface repositories, 63 inetd.conf file, 196 Interface types, 13, 39, 47–49, 48, 480 Info classes, 67 Interfaces, 7 Inheritance versus classes, 246 classes, 15 contracts for collections, 250, 253 cross-language, 236 immutability, 5 custom attributes, 77 in-memory data storage and interface types, 47 manipulation, 250, 253–254 name hiding, 302 instance methods, 47–48 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 506

506 Programming in the .NET Environment

Interfaces continued IsPublic method, 70 late binding, 319 IsSealed method, 70 as reusable components, 465 IsSynchronized method, 49 use on value types, 53–54 IsValueType method, 70 Internationalization, 176–186 IUnknown interface, 298 Internet Explorer Java, 2 deploying applications, 205–207 abstract classes, 446 security system, 207–208 building on abstraction, 448 Internet permission set, 137 class library, 233 Internet protocols to send and receive data, general collection classes, 411 261–263 inheritance of interfaces, 21 Internet zone, 132 object-oriented language, 233 Interoperability, 2, 99–102, 456–458, 463–466, object-oriented type system, 21 480 primitive built-in types, 21 Intersect method, 130 sand-box, 233 Interworking Specification, 99 semi-trusted execution, 232 IntList class, 423 single-implementation inheritance model, IntPtr class, 26, 252 22 invo construct, 434 supertype, 424 Invocation off subclasses, 268–269 JIT (just-in-time) compilation, 105 Invocation support, 266–269 optimization, 112 Invoke method, 66, 266 verification and, 115 InvokeEvent method, 38 JIT (just-in-time) compiler, 385, 406–407, 480 InvokeMember method, 70 JIT (just-in-time) evaluation, 418, 430–433, I/O (input/output), 259–261 436 IPermission interface, 130, 273 JPython, 352, 353 IPoint interface, 52, 53 JSP (Java Server Pages), 235–237 IPrincipal interface, 127 JVM (Java Virtual Machine), 105, 113, 404, IPyType interface, 356–357, 367–368 406 Is methods, 68 Is properties, 68 Kernel profile, 221 IsAbstract property, 66, 70 IsAutoLay property, 68 Language IsAutoLayout property, 68 implementers, 418 IsConstructor property, 66 interoperability, 6 IsDefined property, 67 Language-specific metadata facilities, 61 IsExplicitLayout property, 68 Late binding, 317–319 IsIn property, 67 Late-bound invocation, 267–268 IsInRole method, 129 Launcher type, 465 IsInterface method, 70 ldstr instruction, 110 IsLayoutSequential property, 68 Legal CIL, 115 IsMatch method, 276 length function, 423 IsOut property, 67 Length method, 45 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 507

Index 507

Length property, 46 Managed Extensions for C++, 15 Let assignment, 316–317 Managed heap, 123 lfFaceName string, 280 managed keyword, 109 Lifetime, 481 Managed pointers, 49, 481–482 Link type, 444 Managed types, 229 Linked resources, 157–162 Match objects, 277 Link-time demand, 481 MatchCollection object, 277 LISP, 232 .maxstack value, 109 List value, 425 Mechanics, 239 Load instructions, 481 MemberInfo class, 65, 66, 67, 266, 268 Local Intranet zone, 131 MemberInfo-derived classes, 71 Local variable array, 109 Members, 14, 482 Local variables, 109, 122 accessibility attributes, 391 Locale, 256 accessibility levels, 58–59 Localization annotating, 67, 76–80 assemblies, 178 usage, 241–248 concepts, 178–180 MemberwiseClone method, 42 cultures, 178–179 Memory resource fallback process, 179–180 allocation algorithm, 123–126 Windows, 178 forgetting to free, 122 Localized application, 181–182 garbage collection, 123–126 Locals, 481 heap-allocated, 122–123 .locals directive, 109 managed heap, 123 Locations, 40, 481 management, 121–126 LOGFONT type, 280 reclaiming, 122–123 Logical backing store, 241 reference types, 121–123 Logical fields, 34 unreachable objects, 123 Long type, 325 value types, 121–123 Long-lived objects, 124–125 MemoryStream class, 259 Message instance member, 15 Machine configuration files, 199–200, 205, MessageBox method, 83 208 MessageBoxA method, 83 Machine Policy configuration files, 200 message.txt file, 158–159, 162–163, 169 Machine policy level, 134 modifying, 170–171 machine.config file, 199, 201 renaming or removing, 160 Main method, 18, 33, 80, 106–110 Metadata, 22, 61, 482 make tool, 154 assemblies, 113–114 makefile files, 154, 156–157, 173, 214 custom attributes, 76–80 Managed APIs, 95 description, 99 Managed code, 14, 481 executable files, 62 calling unmanaged functions, 279–281 execution engine, 63 COM objects, 281–282 extensibility, 76–83 Managed data, 14 file format, 95–98 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 508

508 Programming in the .NET Environment

Metadata continued overloading, 244 files, 7 parameter list, 109 header file, 61 private, 108 identifying, 96 properties, 34 information about assemblies, 61 versus properties, 241–242 information about types, 61–62 return value, 110 inspecting, 64–75 static, 32–33, 108 issues, 3, 62–63 usage, 243–245 language-specific files, 62 variable numbers of parameters, 245 locating, 96 MFCs (Microsoft Foundation Classes), 11, managed APIs, 95 234 multi-language types, 63 Microsoft Web site, xxvii, 220, 349 primitive facilities, 63 Middle type, 56 reading and writing, 63, 75 MMC (Microsoft Management Console) saving, 63–64 snap-in, 138, 168 standard attributes, 80–83 Mobile devices, 221, 222–223 storing, 62–63 Modula-2, 385, 442 tokens, 96 module class, 459 tools and extensions, 75–83 Module construct, 455 unmanaged APIs, 95 Modules, 87, 152, 457, 482 verification, 113–114 Active Oberon, 455–456, 458 Metadata system, 9, 14, 61–62 compiling, 459–460 accessing, 10 mapping, 459–461 custom attributes, 19, 104 Monadic I/O, 433–434 Meta-programming, 92–95 Mondrian, 417, 418 .method keyword, 108 access methods, 422 Method variables, 468 calling other CLR-hosted languages, 433–434 MethodBase class, 66 class construct, 422 MethodInfo object, 66, 68, 85 class method, 427 Methods, 14, 32–33, 50, 66, 238, 482 class/subclass formulation, 423 body, 109–110 combining with C# in Sieve of calling, 109–110 Eratosthenes, 435–437 Component Pascal, 387 concurrency support, 419–420 default values, 244–245 create construct, 434 .entrypoint annotation, 108 dynamic function, 427 formatting and parsing enumeration exception handling, 419 values, 248 functions, 426–433 hiding methods, 108 instance method, 427 instance, 32–33 invo construct, 434 interface types, 47 JIT evaluation, 430–433, 436 managed, 109 minimalist language, 420 name of, 108 monadic I/O, 433–434 not returning value, 108 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 509

Index 509

monomorphic functions, 426–428 Named constants, 247 parametric polymorphism, 419 Named delegate types, 322 parametric types, 424–425 Named permission sets, 139 partial applications of functions, 429–430 Namespaces, 5, 248–295, 457 pattern matching, 420, 423 Active Oberon, 464–465, 468 polymorphic functions, 428 naming, 241 primitive types, 421 root, 248–250 product type, 421–422 runtime, 389–390 semantics, 418–419 System namespace, 248–250 statically defined function, 427 System.Collections namespace, 250, syntax, 420 253–254 type casts, 425 System.Data namespace, 254–256 type system, 419 System.Globalization namespace, 256–257 types, 421–425 System.IO namespace, 259–261 union types, 422–423 System.Net namespace, 261–263 Mondrian, Pieter Cornelis, 420 System.Reflection namespace, 263–271 Monomorphic functions, 426–428 System.Resources namespace, 257–259 Month enumeration, 31 System.Runtime.InteropServices MoveNext method, 48 namespaces, 279–282 Movie type, 445 System.Security namespace, 272–273 mscorcfg.msc, 168 System.Text namespace, 273–278 mscorlib assembly, 89, 110, 132, 190, 469 System.Threading namespace, 278–279 mscorlib.dll assembly, 116, 121 System.Web namespace, 287–289 mscorwks.dll, 116 System.Web.Services namespace, 289–292 MSIL, 457–457 System.Windows.Forms namespace, 283–287 Multi-language types, 63 System.Xml namespace, 292–295 Multiple inheritance, 362 Visual Basic .NET, 306 Multiple programming languages support, 233 NameValueSectionHandler sections, 203 Multiple-implementation inheritance, 22 Naming, 4 Multithreaded code, 278–279 Naming guidelines, 239–241 Mutual exclusion, 467 Native code, 296, 482 mxcorsvr.dll, 116 native int type, 29 My Computer zone, 131 Native integers, 28 MyControl class, 213 NDR (Network Data Representation), 5 MyDomain application domain, 188 Nested types, 56–57 MyMethod() method, 94, 373 Nesting procedures, 469 .NET

Name hiding COM concepts mapped to .NET concepts, 300 hide by name, 302 compile-time determination of attributes, hide by name and signature, 303–304 365 shadow by name, 302 runtime behavior, 198–199 Name property, 66, 73 unit of identity changes, 299–300 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 510

510 Programming in the .NET Environment

.NET Framework, 1–2 .netmodule file extension, 162 applications, 12–13 new() function, 400 Base Framework, 8, 10 newobj instruction, 106 CLI (Common Language Infrastructure), 8 nmake utility, 154–155, 209 CLR (Common Language Runtime), 8, Nondefault indexed properties, 243 9–10 Nonlocal addressing, 397–398 CLS (Common Language Specification), Non-object-oriented languages and type 233 systems, 22 compared with IDL-based systems, 6–7 Nonstrict evaluation, 430 compile-time naming hierarchy, 457 Nonvirtual methods, 243–244 component packaging model, 457 Non-Windows platforms and CLI, 220 consumers and producers of components, Nothing permission set, 137, 139 458 N.T. type, 32 cross-language compatibility, 18 Number type, 405 CTS (Common Type System), 457 elements, 8–10 Oberon, 385, 441, 468 enumerations, 233 Oberon Microsystems Web site, 401 events, 233 Object class, 10, 15, 39, 40–44, 52, 70, 89 exposing, 10–11 Object files, 61 factored and extensible, 235–236 OBJECT keyword, 444 goals, 234–238 Object references, 55, 483 infrastructure for building applications, Object types, 13, 40–47, 57–58, 132, 245, 409, 295 425, 483 installing, 219–220 active, 441 integrating with Web standards and Active Oberon, 458 practices, 236–237 API (application programming interface), interoperability, 456–458 447 language implementer tasks, 458 ByRef parameters, 310–311 library design guidelines, 238–248 deterministically finalized, 315 operator overloading, 233 facets, 447 properties, 233 functionally equivalent to variant, 310 protecting resources, 233 garbage collected, 315 run-time deployment hierarchy, 457 implementing definitions, 447 stack engine model, 457–458 interface types, 47 standard I/O functions, 231 roles, 447 structures, 233 Visual Basic .NET, 309–312 unified type system, 232 Object variable, assigning value to, 310 unifying programming models, 234–235 ObjectHandle class, 191 .NET objects Object-oriented design, 232–233 accessing unmanaged code, 279–282 Object-oriented languages, 426, 433 Python for .NET, 359 Java, 233 using .NET objects, 359 versus semi-trusted languages, 232–233 .NET SDK, 358 type hierarchy, 413 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 511

Index 511

Object-oriented prime generator, 438 /out:UseAboutBox.exe file, 157 Object-oriented programming, 482 Overloaded methods, 343 Object-oriented VMs (virtual machines), 406 Overloading methods, 244, 363 Objects Active Oberon, 468 accessing metadata, 41–42 PerlNET Component Builder, 378–379 allocating on heap, 122 Visual Basic .NET, 304–305 deep copy, 42 Overloads keyword, 303, 304 destroying, 41 Overriding, 43, 483 deterministic finalization, 314–316 deterministically finalized, 314 Pad method, 45 equal, 41 Paint() method, 334 exact type, 42 Pair type, 405 hash code, 41 PAL (Platform Adaptation Layer), 222 instance of, 84 Parameter areas, 483 lifetime, 122 ParameterInfo class, 67, 73 long-lived, 124–125 Parameters managing, 63 allocating and freeing memory, 122 pinned in memory, 49 Hungarian notation, 240 referring to same, 42 Parametric polymorphism, 418, 419 returning handle to, 84 Parametric types, 424–425 returning reference to, 84 params arrays, 343–344 returning type, 263 Partial applications of functions, 429–430 shallow copy, 42 partialTimes class, 430 string representing, 42 Pascal, 385, 442 type object for, 41–42 Pascal casing, 240 values as, 39 PATH variables, 149–150, 151 Obsolete attribute, 81 Pattern matching, 422–423 ObsoleteAttribute attribute, 80–81 PE (Portable Execution) files, 479, 483 ODL (Object Definition Language), 63 PenSensor abstraction feature, 453 On Error statement, 319 Perl On Error-style error handling, 319–321 annotating source code with C#-like OnClick delegate, 338 interface declaration, 373 OnClick event, 338 B module, 372 open array construct, 386 B::CC module, 372–373 Operand procedure, 458 CPAN (Comprehensive Perl Archive Operating systems Network), 371 processes, 186 modules, 376 well-known directories, 149 scope stack, 379 Operator overloading, 336–337 syntax, 372 Operator procedure, 458 typed variables, 374 OrElse operator, 326 untyped language, 373 os module, 357 Windows Forms application, 380–382 Outer type, 56 XS code, 376 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 512

512 Programming in the .NET Environment

Perl for .NET Research compiler Pointer-based object types, 444 code generator, 372–374 Pointers compatibility with existing extensions, 376 C#, 339–340 execution speed, 375 COM Interop, 340 full language support, 375 Component Pascal, 386 interface specification, 373 to user-defined types, 25 parser, 372 Policy assemblies, 139 problems, 375–376 Policy levels run-time library, 374 code groups, 135–138 status, 374 named permission sets, 139 typed variables, 374 policy assemblies, 139 Perl Reference Manual, 330 Policy Manager PerlNET, 378–380 code groups, 135–138 PerlNET Component Builder, 376–379 policy levels, 134–135 Permission class, 483 Polymorphic declarations, 454 Permission demand, 130 Polymorphic functions, 428 Permission grant, 130 Polymorphism Permission objects, 144, 483 Active Oberon, 442 Permission sets, 133 Component Pascal, 386 based on evidence, 134–141 Pop instructions, 106 code groups, 135 Port type, 405 named, 139 POST event, 216 Permissions PowerBuilder, 234 assemblies, 130–131 pred function, 436 asserting, 141–142 Prime numbers, 434–438 collection of, 130–131 primes function, 437 denying, 142 Primitive types, 25, 246, 421 security check, 141 Principal objects, 127 Permissions-based security system, 272–273 PrincipalIdentity object, 127 PermissionSet, 141 PrincipalPermissionAttribute attribute, PermitOnly, 141 128–129 Permit-only restriction, 483–484 PrintAssemblies function, 189 PInvoke (Platform Invoke), 279–281, 378, 484 PrintItems method, 253 Pizza, 419 PrintPrimes method, 437 Platform invocation services, 484 PrintValue method, 299 Plug-and-play components, 236 Private accessibility level POA (Portable Object Adapter), 5, 105 Private assemblies, 163–172, 217 Pocket PCs, 220 Private assembly, 208 Point class, 33, 52 Private classes, 390 Point value type, 34, 35, 50, 53 private keyword, 108 Pointer types, 13, 25, 49–50, 484 Private methods, 108 reference surrogates, 393–394 Privileges, 484 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 513

Index 513

Procedure type, 405 returning arrays, 242 Processes Property design pattern, 334 application domains, 119–121 PropertyInfo class, 66 versus application domains, 186–187 Proxy objects, 7, 84, 92–93, 99 isolation, 186 Public accessibility level, 58, 391 Profiles, 221–222, 484 Public assemblies, 163–172 Profiling, 484 Public classes, 390 Program IDs, 151–152 public key token, 88, 211 Programmer's Introduction to C#, A, 349 PUBLIC modifier, 456 Programming, 3–6 Public static constants, 247 Programming in the large, 4–5 Publisher certificates, 131, 132 Programming in the small, 2–4 Push instructions, 106 Programming issues, 2–5 Puzzle module, 465 Programming languages PuzzleForm type, 465 combining to solve problem, 434–438 .py files, 358 consumer perspective, 463 PyObject structure, 357, 367 importing types, 22–23 Python interaction with CLR, 22–23 code not verifiable, 366 passing types between, 3 dynamic features, 356 producer perspective, 463 extensibility, 352 producing verifiable code, 384 extension modules, 358, 361 support for multiple, 13 HelloWorldPY class, 15 type systems, 20–23 implementations, 352–353 Programming language-specific type library, 357 systems, 21 modules, 357 Programs .NET tools not supported, 366 controlled execution, 103 overview, 351–353 debugging, 116–119 standard library, 361, 362 execution environments, 113 type declarations, 362, 363 forgetting to free memory, 122 type interference, 363 performing multiple tasks at same time, unable to inherit from objects, 366 278–279 Python for .NET, 353 Properties, 14, 22, 50, 66, 68, 233, 238, alternative implementation strategy, 484–485 365–368 C#, 333–335 API for use by compiler, 357 definition of, 35 architecture, 355–358 hints to JIT (just-in-time) compiler, 36 class and instance semantics, 362 indexed, 242–243 closed world syndrome, 361–362 interface types, 47 compiler, 355–356, 358–361, 366–367 logical backing store, 241 contractual obligations, 354 methods, 34 current status, 354–355 versus methods, 241–242 different intermediate language, 366–367 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 514

514 Programming in the .NET Environment

Python for .NET continued Reference surrogates, 391–394 dynamic language support, 364–365 Reference types, 13, 23, 485 full integration with .NET, 354 accessing, 40 Hello World program, 358–359 allocated on garbage collected heap, 25 -help option, 358 allocating and freeing memory, 121–123 leveraging of existing Python code, 362 allocating on garbage-collected heap, 40 library, 357–358, 368 assignment compatibility, 54–56 limitations, 361–364 C#, 332–333, 333 method overloading, 363 directly inherit from, 24 method signatures and overloads, 359–360 interface types, 47–49 .NET interface, 356 lifetimes, 122 no support for some features of .NET, 354 object types, 40–47 no support for some Python features, 355 pointer types, 49–50 performance, 361 prohibiting subtyping, 39 runtime, 356–357, 367–368 sealed, 39 speed penalty, 355–356 , 231–232 speed problem, 354 String type, 44–47 type declarations for semantics, 363–364 strongly typed references, 25 unmanaged emit API, 367 ReferenceEquals method, 42 usage, 358–361 References, 96, 97 Python for Win32 extensions, 358 REFINES relation, 441, 446, 458 Python Web site, 351, 358 Reflection, 64–75, 485 Python2C project, 355 class hierarchy, 93 classes, 65–69 Queue class, 250, 359 invocation support, 266–269 late binding, 317–318 /R:AboutBox.dll file, 156 late-bound helper, 318 RAD (rapid application development) late-bound nature, 264 paradigm, 234 PerlNET, 379 Reachable objects and garbage collector, usage, 69–74 123–124 Reflection APIs browsing support, 263–266 ReadCustomData2.cs file, 203–204 Reflection elements, reading custom ReadCustomData2.exe.config file, 203 attributes, 249 ReadCustomData.cs file, 202–203 Reflection Emit, 269–271, 276 ReadCustomData.exe file, 201 Reflection.Emit, 92, 223 ReadCustomData.exe.config file, 202 Reflection/Emit API, 373 Reader class, 260 Reflection::Emit library, 355–356, 366–367 REAL type, 387 regedit, 196 Record types, 468 Regex object, 277 Records, 386 RegionInfo class, 256 Recordsets, 255 @Register directive, 215 RefAny type, 311 Registry, 63, 105, 151–152, 196–197 Reference classes, 391, 395 Registry Assembly, 99 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 515

Index 515

Regular expression engine, 269, 275 RevertPermitOnly, 142 Regular expressions, 276, 277 RIL (Runtime Infrastructure Library), 221 Release method, 314, 315 Role-based security, 126–130 Remote assemblies Roles, 126–128 public key token, 211 Root namespaces, 248–250 security settings, 218 RTTI (run-time type information), 3 Remote objects, managing, 199 Run method, 278 RemoteAssembly assembly, 210, 213 runat=server directives, 215 RemoteAssembly.cs file, 208–209 run() method, 466 RemoteAssembly.dll file, 209 Runnable interface, 450 RemoteAssemblyfile, 209, 210 Runtime RemoteAssembly.netmodule file, 209 classes, 390 RemoteHelloWorld, 213 creation of types, 92–95 RemoteHelloWorld.cs source code, 206 namespaces, 389–390 RemoteHelloWorld.exe file, 206 Runtime checks, 428–429 Remoting services, 223 runtime element, 198–199 Remove method, 253 Runtime environment remove_EventName method, 37 Python language semantics faithfully remove_OnClick() function, 338–339 implemented, 356–357 Replace method, 278 reference types unioned with other types, require, 375 309 requiredRuntime, 198 version, 116, 198 Reset method, 48 versioning policy, 172–173 Resource constrained, 222 Runtime libraries, historical perspective, 231–233 Resource fallback process, 179–180 runtime subelement, 198 Resource Generator, 182, 184 Runtime systems, 413 Resource manager, 258–259 Runtime type libraries, 229–230 ResourceManager class, 179, 182, 258 Runtime type system as single-root type Resources, 152, 257 system, 309 accessing and controlling, 258 authentication, 199 Safearrays, 306–307 culture-neutral, 180, 185 Sample value type, 33 defining, 182 SampleIL.EntryPoint class, 110 embedded, 157–162 SampleIL.EntryPoint type, 112 linked, 157–162 SampleIL.exe application domain, 121 usage, 199 SampleIL.exe assembly, 121 ResourceSet class, 179 Satellite assemblies, 179–180 Resume Next statement, 321 defining, 183–185 Resume statement, 321 Satellite data files, 257 ReturnType property, 66 Saving metadata, 63–64 Reusable components, 465 SayHello method, 15, 16, 17 Reusing components, 31 SayHelloClass method, 33 RevertAll, 142 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 516

516 Programming in the .NET Environment

SayHelloInstance method, 33 overriding, 483 SByte class, 251 permissions-based system, 272–273 Scalability, 5 requirements, 85 Scheme role-based, 126–130 call/cc (call-with-current-continuation), strong names, 164–165, 170–172 405 Security configuration files, 200 closures, 407–411, 413 Security constraints, 144–145 CLR and JVM runtimes, 406 Security hole, 485 continuations, 405 Security manager, 485 dynamic type checking, 412–413 Security model for Windows, 128–129 essential primitives, 404–405 Security objects, 485 first-class continuations, 413–414 Security policies, 485–486 global names, 407 Security systems, 486 latently typed language, 405 Internet Explorer, 207–208 limitations, 413–414 passing evidence to, 132–133 number type, 405 stack walks, 141–144 objects wrapped in special class, 415 XML (eXtended Markup Language), 133 pair type, 405 security.config file, 200 port type, 405 SecurityException exception, 273 primitive value types, 405 SecurityPermission.Assertion permission, procedure type, 405 474 run-time systems, 413 Select statement, 321 run-time tricks, 409 Semi-trusted code, 229 simple model for computation, 404 Sensor abstraction, 448, 453–454 small values for pointers, 411–412 Server-side HTML (Hypertext Markup special optimizations, 409 Language) generation, 235 symbol type, 405 Set assignment, 316–317 type checking, 405 Set functions, 334 variable argument lists, 409–410 set methods, 34, 35, 52 vector type, 405 SetCaption() function, 334 Schwartz, Randal, 372 set_X method, 36 Screen scrapping, 289 Shadow by name, 302 SDE (Smart Device Extensions), 223–224 Shadows keyword, 302, 304 Sealed reference types, 39 Shallow copy, 42 Sealed types, 44 Shared resources, 442–443 Sealed value types, 39 SHORTREAL type, 387 Search paths, 149–150 side-by-side component sharing, 150 sectionGroup element, 201 Sieve of Eratosthenes, 434 Security, 4, 19 C#, 435 code-based, 143–144 combining Mondrian and C#, 435–437 evidence-based, 130–133 Signed assemblies, 165–166, 170 Framework Class Library, 229–230 Signed integers, 9, 27, 28 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 517

Index 517

Simonyi, Charles, 240 startup element, 198 Simple types, 25 Stateless programming model, 237 sin() function, 372 Static fields, 33, 68, 69, 486 Single class, 252 static keyword, 108 Single type system for multiple languages, Static methods, 32–33, 108, 486 21–22 Static module construct, 441 SingleTabSectionHandler class, 202 Static modules, 455–456 Sites, 131 Static procedures, 391 SkipVerification permission set, 139 Static record types, 394–395 SmallTalk Static variables, 391 common base type, 231 Statically defined function, 427 library, 231–232 Stein, Greg, 353, 355 object-oriented design, 232–233 STL (Standard Template Library), 21 reference types, 231–232 Store instructions, 109, 486 single-implementation inheritance model, Stream classes, 260 22 Streams, 260–261 type system, 21 String[] args keyword, 109 unified type system, 231 String class, 10, 39, 42, 43, 44–47, 74, 89, 90 Smart clients, 11 string interning, 342–343 sn.exe, 168, 172 String literals, 177 SOAP, 236, 237, 290 String objects, 48, 110, 273 SOAP-based Web services, 290–292 String pattern, replacing with string, 275 Sort method, 49 String reference, 55 source interface, 37 String replacement functions, 277–278 SSCLI (Shared Source Common Language String resource, 177 Infrastructure), 220, 224–226 String type, 40, 43, 57–58, 132 STA (Single Threaded Apartment) model, String.Append() method, 244 104–105 StringBuilder class, 44 Stack String.IndexOf() method, 244 activation record, 141 String.IsInterned() function, 343 importance of size, 111 Strings, 10, 44–47 maximum depth, 109 adding to strings, 46 rules for use, 111 comparing, 44 underflow/overflow, 109 comparing to pattern, 275–276 Stack class, 250, 253 concatenating, 45 stack engine model, 457–458 constructors, 44 Stack frames, 486 converting to uppercase or lowercase, 45 Stack walks, 141–144, 486 fully qualified names, 263 Stacktrace property, 379 immutable, 44 Standard attributes, 80–83 inserting strings in, 45 standard C++, 15 length, 45 Standard execution environment, 105 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 518

518 Programming in the .NET Environment

Strings continued System.Collections namespace, 250, 253–254, location of character or string within, 45 359 padding characters inserted or removed, System.Collections.Specialized.Name.Value 45 Collection, 203 representing objects, 42 System.Configuration class library, 197 retrieving portions of formatted, 275 System.Configuration.ConfigurationSettings temporary, 44, 46–47 class, 202 Strings class, 253 System.Configuration.NameValueSection- Handler class, 201, 203 strings.en.AU.resources module, 184 System.Configuration.SingleTagSection- strings.resources file, 183 Handler class, 201 strings.txt file, 184 System.Console::WriteLine method, 110 Strong names, 88, 131–132, 164–165, 167–168, System.Data namespace, 254–256 208 System.DateTime type, 29 Strongly typed collections, 253 System.Decimal type, 29 struct keyword, 31, 33, 333 system.diagnostics element, 199 structs, 394 System.Drawing namespace, 230 Structural compatibility of delegates, 398 System.EnterpriseServices namespace, 280 Structured exception handling, 319–321 System.Enum base class, 24, 248 Structures, 21, 233 System.Exception base class, 248 events, 36–38 System.Globalization namespace, 256–257 fields, 33 System.Guid type, 29 methods, 32–33 System.Int32 type, 55 Visual Basic .NET, 312 System.IO namespace, 259–261 Subclasses System.IO.StreamReader object, 158 exact signatures, 360 system.net element, 199 invocation off, 268–269 System.Net namespace, 261–263 Subprocesses, 119 System.Object base class, 40–44, 64, 69, 117, Subsystems, 236 248 Subtypes, 236 System.Random, 434 Subtyping, 234, 423 System.Reflection namespace, 263–271 Swap-stack-top instruction, 458 System.Reflection.Assembly.GetManifest- switch expression, 423 ResourceStream() function, 158 Symbol type, 405 System.Resources namespace, 257–259 Symbolic links, 150, 151 System.Runtime.InteropServices Symbolic names, 150 namespaces, 279–282 SyncRoot method, 49 System.Runtime.InteropServices.GCHandle Synthetic static class, 390, 391 type, 378 syslogd process, 196 system.runtime.remoting, 199 System namespace, 248–252, 469 System.Security namespace, 272–273 System32 directory, 149 System.Security.PermissionSet class, 130–131 system32 directory, 164 System.Stream base class, 259 System.Attribute base class, 77, 80, 249, 337 System.String object, 378 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 519

Index 519

System.String type, 110, 421 time() function, 372 System.Text namespace, 273–278 TINAC, 63 System.Text.RegularExpressions namespace, /t:library option, 156 275 Tokens, 96–97 System.Threading namespace, 278–279 ToLower method, 46 System.TimeSpan type, 29 ToString method, 42, 43, 79, 191 System.Type class, 263–266, 312 ToUpper method, 47 System.ValueType base class, 24, 248 Trim Strings method, 45 system.web element, 199 Trojan Horse components, 148 System.Web namespace, 201, 230, 287–289 Trusted Sites zone, 132 System.Web.Configuration.HttpHandlers- Try statement, 319 SectionHandler, 201 try-finally block, 340 System.Web.Services namespace, 12, 289–292 /t:winexe option, 156 System.Web.Services.WebServiceAttribute Type checks, 414–415 attribute, 290 Type class, 10, 41–42, 65–70, 74–75 System.Web.UI.Control class, 213 Type coercion, 409 System.Web.UI.Page class, 12 Type declarations, 364 System.Windows.Forms namespace, 11–12, Type erasure, 398, 412 230, 283–287 Type fields, 14 System.Windows.Forms.Form base class, 11, 380 Type interference, 363 System.Winforms.Form, 465 Type keyword, 312 System.Xml namespace, 283, 292–295 Type libraries, 63, 99 Type Library Exporter, 99, 282 Tables, 95–96 Type Library Importer, 99, 101, 281, 282 TCB (trusted computing base), 486 Type loader, 487 Temporary strings, 44, 46–47 Type object, 43, 67, 69, 90, 271 Text-based configuration files, 196–197 Type safety, 113, 114, 487 TextReader class, 260 Type systems, 9, 13–14, 487 TextWriter class, 260 C#, 332–333 this object, 396 Component Pascal, 386–388 this pointer, 486 elements, 23–25 Thread class, 450 events, 22 Thread pool implementation, 237 evolution, 20 Threads, 278–279 incompatibility, 22 application domains, 120–121 issues, 3 Principal objects, 127 Mondrian, 419 ThreadStartDelegate method, 278 for multiple languages, 21–22 THROWEXCEPTION procedure, 468 non-object-oriented languages, 22 Thunks, 429 programming languages, 20–23 Time, 29, 313 programming language-specific, 21 Time spans, 29 programming styles and languages, 19 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 520

520 Programming in the .NET Environment

Type systems continued subtyping from, 7 properties, 22 uniquely identifying, 32 reference types, 23 usage, 245–248 union of, 22 user-defined, 29 value types, 23 visibility, 57 Visual Basic.NET additions, 298–306 Type-safe, 111 Type type, 64–65 Type-safe CIL, 115 Type-bound procedures, 396 Type-safe code, 44 TypeConstructorName type, 66 Typed references, 487 UInt16 class, 26, 251 Typed variables, 374 UInt32 class, 26, 251 Type.GetType() static method, 264 UInt64 class, 26, 251 Type.InvokeMember function, 267 UIntPtr class, 26, 252 Type.InvokeMember() method, 266 Unamed delegate types, 322 typeof() operator, 263–264 unbox instruction, 106 TYPEOF() primitive, 395 Unboxing, 487 Types, 13, 14, 487 Unboxing value types, 39 annotating, 76–80 Unicode, 176–177, 273–278 base class, 248 converting string to byte array, 273–275 ComVisible() attribute, 282 strings, 10 constructors, 66 Unifying programming models, 234–235 contracts, 114 Union, 109 describing, 14 Union construct, 386 as documentation, 20 Union method, 130 dynamic, 92–95 Union types, 422–423 dynamic checking, 20 UNIX dynamic discovery of, 84–86 bin directory, 149 dynamically emitting at runtime, 269–271 make tool, 154 events, 36–38, 66 text-based configuration files, 196–197 fields, 33, 66 well-known directories, 149 fully qualified string name, 264 Unmanaged APIs, 95 grouping related, 87 Unmanaged code, 14, 279, 488 importing, 22–23 Unmanaged function pointers, 49 information about, 10, 61–62 Unmanaged pointers, 49 instances, 25 Unreachable objects, 123 logical fields, 34 Unsafe code, 339–341 Mondrian, 421–425 Unsigned integers, 9, 27, 28 nested, 56–57 Untrusted Sites zone, 132 printing members of, 264–266 Updating Registry, 152 properties, 66 URLs, 131 runtime creation of, 92–95 use statement, 372 sealed, 44 UseAboutBox.exe file, 153, 154–155, 170, 176 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 521

Index 521

UseAboutBox.exe.config file, 175, 176 characters, 27 UseCulture.cs file, 181, 183 default constructor, 32 UseCulture.exe assembly, 183, 184 directly inheriting from, 24 UseCulture.resources.dll assembly, 184 fields, 34–36 User interfaces, separation of code from, floating-point types, 28–29 177–178 inheritance, 39 User Policy configuration files, 200 integers, 27–28 User policy level, 134 properties, 34–36 user32.dll, 83 sealed, 39 User-defined signed integers, 27 attribute class, 80 unboxed form, 309 enumerations, 30–31 unboxed value types, 309 methods, 47–48 unboxing, 39 object types example, 50–53 unsigned integers, 27 objects exposed to COM, 282 usage, 246 User-defined types, 29, 312 use of interfaces, 53–54 C#, 333 user-defined, 29–38 pointers to, 25 Values, 13, 25, 488 User-defined value types as classes, 39 boxed types, 39 specifying location, 49–50 enumerations, 30–31 Variable argument lists, 409–410 structures, 31–38 Variables UseRemoteAssembly.cs file, 210 Hungarian notation, 240 UseRemoteAssembly.exe.config file, 211 read-only export, 391 USES clause, 442 Variant data type, 309–312 using directives, 32, 77 Variant variables, assigning value to, 310 using System directive, 30, 35 Variants, 309 UTF-7 character set, 273–278 Vector type, 405 UTF-8 character set, 273–278 Verifiable CIL, 115 UTF-16 character set, 27 Verifiable code, 44 Verification, 488 Value classes, 391–392, 394 Versioning, 5 Value types, 13, 23, 24, 245, 488 Versioning policy, 172–173 Active Oberon, 468 Versioning-related technologies, 150–151 allocated on garbage-collected heap, 25 Virtual machines, 105 allocated on stack, 25, 36, 121–122 Virtual methods, 243–244, 248, 488 allocating and freeing memory, 121–123 Viruses, 113 base class, 248 Visibility, 57, 488 boolean values, 27 Visual Basic, 234 boxed form, 309–310 classes, 298–299 boxing, 39, 332–333 COM (Common Object Model), 297 built-in, 25–28 COM coclass, 298 C#, 332–333 default interfaces, 298 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 522

522 Programming in the .NET Environment

Visual Basic continued overloading resolution rules, 305 excluding inheritance, 301 parameterized property, 336 HelloWorld VB class, 16 platform changes, 313–324 language extensions, 2 programming model changes, 324 namespaces, 306 strongly typed language, 305 Obsolete method, 82 structured exception handling, 319–321 optional parameters, 304 structures, 312 reference assignment, 316–317 type system additions, 298–306 time, 313 type system modifications, 306–313 typeless language, 309 typeless ability, 305 user-defined types, 312 user-defined value types, 312 value assignment, 316–317 variant data type, 309–312 Win32 APIs, 297 Wend, 325 Visual Basic .NET, 297–298 Visual Perl plug-in, 380 AndAlso operator, 326 Visual Studio, 223–224 array types, 308 VMs (virtual machines), 6, 403, 406 array types with fixed lower bounds of void keyword, 108 zero, 308 arrays, 306–309 W3C DOM Level 1 Core, 293 classes, 298–301 W3C XPath 1.0 data model, 293 compound operators, 326 W3C XSD specification, 293 Def statements, 325 W3C XSLT 1.0-compliant XSLT processor, delegates, 321–324 293 deterministic finalization, 314–316 Wall, Larry, 371 End While, 325 Web application services, 287 On Error-style error handling, 319–321 Web content, downloading, 205–216 events, 321–324 Web controls, 213–216 future, 327 Web Forms, 230, 287 garbage collection, 314–316 Web pages, displaying Web controls, 215 Gosub, 325 Web servers, uploading application to, 206 inheritance, 301–304 Web services, 12, 230, 290–292 initializers, 326 Web standards and practices, 236–237 Integer type, 325 Web-based applications, 12 keywords, 301 web.config file, 200 language cleanup, 324–326 WebRequest class, 261 late binding, 317–319 WebService class, 12 Long type, 325 Well-known directories, 149 namespaces, 306 Well-known locations, 149 new features, 326 while loop, 48 nonzero-lower-bound arrays, 308 Win32 APIs, 280, 297 Object types, 309–312 Win32API class, 280 OrElse operator, 326 %windir%/assemblies directory, 167 overloading methods, 304–305 Windows 5298 EM_473-523.qxd 10/10/2002 6:10 PM Page 523

Index 523

clients, 11–12 viewing and manipulating, 293 COM, 104–105 XML namespace, 293 localization, 178 XML serialization, 237 Registry, 151–152 XmlDataDocument class, 293 security model, 128–129 XmlDocument class, 293 System32 directory, 149 XmlNodeReader class, 293 Windows 98 SE, 150 XmlReader, 293 Windows 2000, 150 XmlSchema object model classes, 293 Windows applications XmlSchemaCollection class, 293 developing, 283–287 XmlTextReader class, 293 traditional model for building, 147–148 XmlTextWriter class, 293 Windows Explorer, 167 XmlValidatingReader class, 293 Windows Forms, 226, 230, 238, 283–287 XPathDocument class, 293 Windows Forms library, 223 XPathNavigator class, 293 Windows handles, 236 XS code, 376 Windows Installer, 219 XSD schema validation, 293 Windows XP, 220, 224–226 XSLT, 293 Windows-based platforms and PAL XslTransform class, 293 (Platform Adaptation Layer), 222 Wise, 219 Zones, 131 WithEvents modifier, 322 Word choice, 239 Wrapper classes, 438 WriteLine method, 52, 54, 271 Writer class, 260 WSDL tool, 292

X Windows, 150 xcopy, 205 XDR (eXternal Data Representation), 5 XDR schema validation, 293 XHR (explicit heap-allocated records), 397–398 XML (eXtended Markup Language), 223, 236, 237 built-in support, 255–256 C# and comments, 344 data support services, 229 forward-only way of generating, 293 processing functionality, 292–295 reading data, 293 security system, 133 transforming documents, 293