You are previewing Programming Microsoft® Visual C#® 2005: The Base Class Library.
O'Reilly logo
Programming Microsoft® Visual C#® 2005: The Base Class Library

Book Description

An in-depth reference for C# developers, this book goes beyond the basics and covers key, advanced topics of C# programming. An ideal base class library reference, this book provides expert insights, hands-on instruction, and practical code samples.

Table of Contents

  1. Programming Microsoft® Visual C#® 2005: The Base Class Library
    1. Acknowledgments
    2. Introduction
      1. Live Updates and Feedback
      2. Who Is This Book For?
      3. Organization of This Book
      4. System Requirements
      5. Technology Updates
      6. Code Samples
      7. Support for This Book
        1. Questions and Comments
    3. 1. .NET Framework Basic Types
      1. The System.Object Type
        1. Public and Protected Methods
        2. Value Types and Reference Types
        3. Boxing and Unboxing
      2. String Types
        1. Properties and Methods
          1. Comparing and Searching Strings
          2. Modifying and Extracting Strings
          3. Working with String and Char Arrays
        2. The Missing Methods
        3. String Optimizations
        4. The CultureInfo Type
        5. The Encoding Class
        6. Formatting Numeric Values
        7. Formatting Date Values
        8. The Char Type
        9. The StringBuilder Type
        10. The SecureString Type
      3. Numeric Types
        1. Properties and Methods
        2. Formatting Numbers
        3. Parsing Strings into Numbers
        4. The Convert Type
        5. Random Number Generator
      4. The DateTime Type
        1. Adding and Subtracting Dates
        2. Formatting Dates
        3. Parsing Dates
        4. Working with Time Zones
        5. The TimeZone Type
        6. The Guid Type
      5. Enums
        1. Displaying and Parsing Enum Values
        2. Other Enum Methods
        3. Bit-Coded Values
    4. 2. Object Lifetime
      1. Memory Management in the .NET Framework
        1. The Garbage Collection Process
        2. The Finalize Method
        3. The Dispose Method
        4. Combining the Dispose and Finalize Methods
        5. A Better Dispose–Finalize Pattern
        6. Finalizers in Derived Classes
        7. A Simplified Approach to Finalization
      2. Advanced Techniques
        1. Generations
        2. Garbage Collection and Performance
        3. Weak Object References
        4. Object Resurrection
        5. Garbage Collection on Multiple-CPU Computers
    5. 3. Interfaces
      1. Interfaces and Code Reuse
      2. Using .NET Interfaces
        1. The IComparable Interface
        2. The IComparer Interface
        3. The ICloneable Interface
          1. Shallow Copies and Deep Copies
        4. The IDisposable Interface
        5. Writing Collection Classes
          1. Using Abstract Collection Types
          2. Using Generics
          3. Implementing the IEnumerable and IEnumerator Interfaces
          4. Iterators in C# 2.0
        6. Reusable Enumerable Adapters
    6. 4. Generics
      1. The Need for Generics
        1. The Traditional Solution
        2. The Generics-Based Solution
      2. Authoring Generic Types
        1. Generic Parameters
          1. Multiple Generic Parameters
          2. Generic Methods
          3. Setting the Default Value
          4. Generic Interfaces
          5. Generics and Overloading
          6. Generics and Inheritance
          7. Generics and the is Operator
        2. Generic Constraints
          1. The Interface Constraint
          2. The Inheritance Constraint
          3. The Class and Struct Constraints
          4. The New Constraint
          5. Multiple Constraints
          6. Checking a Constraint at Run Time
      3. Advanced Topics
        1. Nullable Types
          1. Math and Comparison Operators
          2. Three-Valued Boolean Logic
        2. Support for Math Operators
        3. Generics and Events
        4. Object Pools
    7. 5. Arrays and Collections
      1. The Array Type
        1. Sorting Elements
        2. Clearing, Copying, and Moving Elements
        3. Searching Values
        4. Jagged Arrays
        5. Generic Methods
      2. The System.Collections Namespace
        1. The ICollection, IList, and IDictionary Interfaces
        2. The ArrayList Type
        3. The Hashtable Type
        4. The SortedList Type
        5. Other Collections
          1. The Stack Type
          2. The Queue Type
          3. The BitArray Type
          4. The BitVector32 Type
        6. Abstract Types for Strong-Typed Collections
          1. The CollectionBase Type
          2. The ReadOnlyCollectionBase Type
          3. The DictionaryBase Type
          4. The NameObjectCollectionBase Type
      3. Generic Collections
        1. The List Generic Type
        2. The Dictionary Generic Type
        3. The LinkedList Generic Type
        4. Other Generic Collections
          1. A Notable Example
        5. The System.Generic.ObjectModel Namespace
    8. 6. Regular Expressions
      1. Regular Expression Overview
        1. The Fundamentals
        2. The Regular Expression Language
        3. Regular Expression Options
      2. Regular Expression Types
        1. The Regex Type
          1. Searching for Substrings
          2. The Replace Method
          3. Static Methods
          4. The CompileToAssembly Method
        2. The MatchCollection and Match Types
        3. The Group Type
        4. The CaptureCollection and Capture Types
      3. Regular Expressions at Work
        1. Common Regex Patterns
        2. Searching for Words and Quoted Strings
        3. Validating Strings, Numbers, and Dates
        4. Searching for Nested Tags
        5. Parsing Data Files
        6. Parsing and Evaluating Expressions
        7. Playing with Regular Expressions (Literally)
    9. 7. Files, Directories, and Streams
      1. The Path Type
      2. The Directory and File Types
        1. Enumerating Directories and Files
        2. Manipulating Directories and Files
        3. Reading and Writing Files
      3. The DirectoryInfo and FileInfo Types
      4. The DriveInfo Type
      5. The FileSystemWatcher Type
        1. Initializing a FileSystemWatcher Component
        2. Getting Notifications
          1. Events
          2. The WaitForChanged Method
          3. Buffer Overflows
        3. Troubleshooting
      6. Working with Access Control Lists
        1. Account Names and Security Identifiers
        2. The DirectorySecurity and FileSecurity Types
        3. Modifying ACLs
      7. The Stream Type
        1. Stream Operations
        2. Stream Readers and Writers
        3. Reading and Writing Text Files
        4. Reading and Writing Binary Files
      8. Other Stream Types
        1. Memory Streams
        2. String-Based Streams
        3. Network Streams
        4. Buffered Streams
        5. Compressed Streams
    10. 8. Assemblies and Resources
      1. Assemblies
        1. Private and Shared Assemblies
        2. Strong Names
        3. Installing in the GAC
        4. Assembly-Level Attributes
        5. The InternalsVisibleTo Attribute
      2. Strong-Typed Settings
        1. The Properties.Settings Object
          1. Properties.Settings Entries in Configuration Files
          2. Properties.Settings Properties and Methods
          3. Properties.Settings Events
      3. Resources and Satellite Assemblies
        1. Strong-Typed Resources
        2. Manifest Resources
        3. Localized Form Resources
        4. Localized Strong-Typed String Resources
        5. Custom Resource Files
        6. Satellite Assemblies
        7. Attributes for Satellite Assemblies
      4. The Binding Process
        1. Version Policy in Application Configuration Files
        2. Previously Loaded Assemblies and GAC Searches
        3. Codebase Hints
        4. Probing
        5. The Assembly Binding Log Viewer Utility (FUSLOGVW)
        6. Setting the Runtime Version
        7. The .NET Framework Configuration Tool
      5. The NGen Tool
        1. Using the NGen Tool
        2. Using the NGen Service
        3. Debugging Native Images
        4. Attributes for NGen
          1. Domain-Neutral Assemblies
          2. Hard Binding
    11. 9. Reflection
      1. Working with Assemblies and Modules
        1. The Assembly Type
          1. Loading an Assembly
          2. AppDomain Events
          3. Properties and Methods
        2. The AssemblyName Type
        3. The Module Type
      2. Working with Types
        1. Retrieving a Type Object
          1. The TypeResolve Event
          2. Exploring Type Properties
          3. Enumerating Members
        2. Exploring Type Members
          1. Exploring Fields
          2. Exploring Methods
          3. Exploring Properties
          4. Exploring Events
          5. Exploring Parameters
          6. Exploring the Method Body
        3. Reflecting on Generics
          1. Exploring Generic Types
          2. Exploring Generic Methods
          3. Exploring Members That Use Generic Types
          4. Binding a Generic Type
        4. Reflecting on Attributes
          1. Exploring Attributes
          2. The CustomAttributeData Type
        5. Creating a Custom Object Browser
      3. Reflection at Run Time
        1. Creating an Object Dynamically
        2. Accessing Members
        3. The InvokeMember Method
        4. The StackTrace Object
        5. Creating a Universal Comparer
        6. Dynamic Registration of Event Handlers
          1. Delegate Covariance and Contravariance in C# 2.0
          2. A Universal Event Handler
        7. Scheduling a Sequence of Actions
        8. On-the-Fly Compilation
        9. Performance Considerations
        10. Security Issues
    12. 10. Custom Attributes
      1. Introducing Custom Attributes
        1. Building a Custom Attribute Class
        2. Reflecting on a Custom Attribute
      2. A Custom Attribute for CSV Serialization
      3. Building a Benchmark Tool
      4. Writing Plug-ins for Windows Forms Applications
        1. The PluginLibrary Project
          1. The FormExtenderAttribute Type
          2. The FormExtenderManager Type
        2. The MainApplication and MainApplicationStartup Projects
          1. The Startup Project
          2. The MainApplication Project
          3. Creating Inheritable Forms
        3. The SamplePlugin Project
          1. Replacing a Form with a Different Form
          2. Extending a Form with User Interface Elements
          3. Replacing a Form with an Inherited Form
          4. Compiling and Testing the SamplePlugin Project
      5. A Framework for n-Tiered Applications
        1. The DataObjectLibrary Project
          1. Interfaces
          2. Custom Attributes
          3. The DataObjectFactory Type
          4. The DataObjectCommand Type
          5. The DataObjectHelper Type
        2. The DataSets Project
        3. The DemoClient Project
        4. The DataObjects Project
          1. The DOCustomers Type
          2. The Tracer Companion Type
          3. The CustomerCache Companion Type
          4. The CustomerFilter Companion Type
          5. The GenericFilter Companion Type
    13. 11. Threads
      1. Threading Fundamentals
        1. When to Use Threads
        2. Creating Threads
        3. Passing Data to and from a Thread
        4. Working with Threads
        5. Thread Properties
        6. Storing and Sharing Data
          1. Variables and Fields
          2. The ThreadStatic Attribute
        7. Threads and Unhandled Exceptions
        8. Debugging Threads
      2. Thread Synchronization
        1. The lock Statement
          1. Performance Considerations and Lazy Instantiation
          2. Volatile Fields
        2. Synchronized Objects
          1. Synchronized .NET Types
          2. The Synchronization Attribute
          3. The MethodImpl Attribute
        3. Volatile Read and Write Operations
        4. The Monitor Type
        5. The Mutex Type
        6. The Semaphore Type
        7. The ReaderWriterLock Type
        8. The Interlocked Type
        9. The ManualResetEvent, AutoResetEvent, and EventWaitHandle Types
      3. Using the Thread Pool
        1. The ThreadPool Type
        2. The Timer Type
      4. Asynchronous Operations
        1. Asynchronous Delegates
          1. Asynchronous Calls
          2. Asynchronous Callback Procedures
          3. More on Asynchronous Method Invocation
        2. Asynchronous File Operations
        3. Adding Asynchronous Support to Your Types
      5. Threading in Windows Forms Applications
        1. The ISynchronizeInvoke Interface
        2. The BackgroundWorker Component
    14. 12. Object Serialization
      1. Basic Serialization
        1. Binary Serialization
        2. SOAP Serialization
        3. Creating Serializable Types
        4. Object Graphs
        5. Serialization and Events
        6. Deep Object Cloning
        7. Version-Tolerant Serialization (VTS)
          1. The OptionalField Attribute
          2. The Binder Property
      2. Custom Serialization
        1. The IDeserializationCallback Interface
        2. The ISerializable Interface
          1. Security Implications
          2. A Practical Example: Compressed Serialization
          3. Custom Serialization and Inheritance
          4. The FormatterServices Helper Type
        3. Serialization and Deserialization Events
        4. The IObjectReference Interface
        5. The ISerializationSurrogate Interface
        6. Inheriting from a Nonserializable Type
    15. 13. PInvoke and COM Interop
      1. Using PInvoke
        1. The DllImport Attribute
        2. Marshaling Data
        3. The MarshalAs Attribute
        4. The StructLayout Attribute
        5. The FieldOffset Attribute
        6. Delegates and Callback Procedures
        7. The In and Out Attributes
        8. The Marshal Class
      2. Calling COM Components from .NET
        1. The Runtime Callable Wrapper
        2. Importing a COM Component with Visual Studio
        3. Using the Imported Interop Assembly
        4. Importing a COM Component with TlbImp
        5. Primary Interop Assemblies
        6. Registration-Free COM Components
        7. Late Binding and Reflection
        8. COM Interop Marshaling
        9. Threading Issues
      3. Calling .NET Objects from COM
        1. The COM Callable Wrapper
        2. Creating a Sample .NET Component
        3. The RegAsm and TlbExp Tools
        4. Conversion Details
        5. Using Attributes to Control the Conversion
          1. The ComVisible, ProgId, and Guid Attributes
          2. The DispId Attribute
          3. The ClassInterface Attribute
          4. The InterfaceType and ComSourceInterfaces Attributes
          5. The ComRegisterFunction and ComUnregisterFunction Attributes
        6. Working with Exceptions
        7. Writing COM-Friendly .NET Framework Components
    16. A. Francesco Balena
    17. Index