You are previewing Practical Guidelines and Best Practices for Microsoft® Visual Basic® and Visual C#® Developers.
O'Reilly logo
Practical Guidelines and Best Practices for Microsoft® Visual Basic® and Visual C#® Developers

Book Description

Written by respected developers Francesco Balena and Giuseppe Dimauro, this practical, timesaving reference describes 700+ best programming practices—including when and how to use them—to improve your Microsoft .NET development projects.

Table of Contents

  1. Copyright
  2. Foreword
  3. Introduction
    1. P2.1. Mission (Almost) Impossible: Writing Quality Software
    2. P2.2. Guideline Priority
    3. P2.3. Who Should Read This Book
    4. P2.4. Where to Look for More Information
    5. P2.5. Acknowledgments
  4. 1. Coding Guidelines and Best Practices
    1. 1. Projects and Solutions
      1. 1.1. Solution name
      2. 1.2. Location of files in single-project solutions
      3. 1.3. Location of files in multiple-project solutions
      4. 1.4. Location of files in ASP.NET projects
      5. 1.5. Project folders
      6. 1.6. Source file name
      7. 1.7. Executable EXE files
      8. 1.8. Executable DLL files
      9. 1.9. Source files shared among multiple projects
      10. 1.10. Configuration files
      11. 1.11. Compiler warnings [Visual Basic]
      12. 1.12. Compiler warnings [C#]
      13. 1.13. Compiler optimizations
      14. 1.14. Debugging information
      15. 1.15. Base address for DLLs
      16. 1.16. Option Strict setting for new projects [Visual Basic]
      17. 1.17. Option Strict setting for the current project [Visual Basic]
      18. 1.18. The Option Strict directive [Visual Basic]
      19. 1.19. Project-level custom constants
      20. 1.20. VERSIONxyy custom compilation constant
      21. 1.21. VERSION custom compilation constant [Visual Basic]
      22. 1.22. Microsoft.VisualBasic project-wide imports [Visual Basic]
      23. 1.23. Incremental builds [C#]
    2. 2. Spaces and Indentation
      1. 2.1. Indent by tabs
      2. 2.2. Indentation width
      3. 2.3. Consecutive blank lines
      4. 2.4. Line length
      5. 2.5. Line wrapping
      6. 2.6. Curly braces [C#]
      7. 2.7. Spaces and operators [C#]
      8. 2.8. Spaces and parentheses [C#]
    3. 3. Comments
      1. 3.1. Spell checking and comments
      2. 3.2. Language used for comments
      3. 3.3. Consistent comment style
      4. 3.4. Comment position and indentation
      5. 3.5. XML comments [C#]
      6. 3.6. XML comments in separate files [C#]
      7. 3.7. Producing technical documentation
      8. 3.8. The VBCommenter add-in [Visual Basic]
      9. 3.9. Class- and method-level comments
      10. 3.10. Block comments [C#]
      11. 3.11. File header comments
      12. 3.12. Block-level comments
      13. 3.13. Statement-level comments
      14. 3.14. Comments at the end of long blocks
      15. 3.15. Comments for overloaded methods
      16. 3.16. Comments for autogenerated code
      17. 3.17. Remarks for commenting out code [C#]
      18. 3.18. TODO and HACK comment tokens
      19. 3.19. Custom policy comment tokens
    4. 4. Assemblies and Resources
      1. 4.1. The AssemblyInfo file
      2. 4.2. Strong names
      3. 4.3. Assembly size
      4. 4.4. Multimodule assemblies
      5. 4.5. CLS-compliant assemblies
      6. 4.6. Assembly versioning
      7. 4.7. Manifest resources vs. stand-alone files
      8. 4.8. Resources vs. hard-coded string
      9. 4.9. Resource names
      10. 4.10. Satellite assemblies with localized resources
      11. 4.11. Culture for main assembly
      12. 4.12. Configuration settings
      13. 4.13. GAC registration
      14. 4.14. The Ngen utility
    5. 5. Namespaces
      1. 5.1. Primary namespace name
      2. 5.2. Second-level namespace
      3. 5.3. Logical organization of types inside namespace
      4. 5.4. Number of types in each namespace
      5. 5.5. Reduce namespace block nesting
      6. 5.6. Types belong to namespaces
      7. 5.7. One namespace for each source file
      8. 5.8. .NET Framework namespace naming conventions
      9. 5.9. Type dependency in nested namespaces
      10. 5.10. Nested namespaces for special types
      11. 5.11. Namespace-qualified member types
      12. 5.12. Namespace aliasing
    6. 6. Types
      1. 6.1. Type names
      2. 6.2. U.S. English for identifiers
      3. 6.3. Abbreviations and acronyms
      4. 6.4. Words to avoid
      5. 6.5. One type per source file
      6. 6.6. Type complexity
      7. 6.7. Dependency on external variables
      8. 6.8. Module names [Visual Basic]
      9. 6.9. App type or module
      10. 6.10. Globals class
      11. 6.11. Member names from common interfaces
      12. 6.12. Case sensitivity in member names [C#]
      13. 6.13. Member ordering and grouping
      14. 6.14. Language-specific member types
      15. 6.15. Nested types
      16. 6.16. Member scope
      17. 6.17. Explicit scope qualifier
      18. 6.18. Shadowed members
      19. 6.19. Non-CLS-compliant types [C#]
      20. 6.20. The Me/this keyword
      21. 6.21. "New" member [C#]
      22. 6.22. The Conditional attribute
      23. 6.23. The Serializable attribute
      24. 6.24. The Obsolete attribute
    7. 7. Inheritance
      1. 7.1. Object hierarchies
      2. 7.2. Abstract classes
      3. 7.3. Derived class names
      4. 7.4. Base classes vs. interfaces
      5. 7.5. Mandatory features in base classes
      6. 7.6. Optional features in base classes
      7. 7.7. Sealed classes
      8. 7.8. Static classes
      9. 7.9. Constructors in abstract types
      10. 7.10. Protected members in sealed classes [Visual Basic]
      11. 7.11. Virtual members
      12. 7.12. Split long tasks in overridable methods
      13. 7.13. Overloaded virtual methods
      14. 7.14. ToString method overriding
      15. 7.15. Equals method overriding
      16. 7.16. GetHashCode method overriding
      17. 7.17. GetHashCode method immutability
      18. 7.18. GetHashCode method and equality
      19. 7.19. MyClass keyword [Visual Basic]
      20. 7.20. Equals and Compare strong-typed static methods
      21. 7.21. Inheriting from MarshalByRefObject
    8. 8. Interfaces
      1. 8.1. Interface names
      2. 8.2. Interface types in one source file
      3. 8.3. Number of members in interface types
      4. 8.4. Events in interface types
      5. 8.5. Interface immutability
      6. 8.6. Name of classes implementing an interface
      7. 8.7. Interface implementation in #region blocks
      8. 8.8. Public vs. private members in interface implementation
      9. 8.9. Private interface implementation in inheritable types
      10. 8.10. ICloneable interface
      11. 8.11. Strong-typed cloning
      12. 8.12. Shallow and deep cloning
      13. 8.13. Cloning immutable objects
      14. 8.14. IComparable interface
      15. 8.15. Leverage IComparable fields and properties
      16. 8.16. IComparer interface
      17. 8.17. IEnumerable and IEnumerator types
      18. 8.18. Strong-typed members in interface implementation
      19. 8.19. ISerializable interface
    9. 9. Structures
      1. 9.1. Value types vs. reference types
      2. 9.2. Structures instead of classes with value type members
      3. 9.3. Structure size
      4. 9.4. Default state of structure members
      5. 9.5. Equals overload in value types
      6. 9.6. Interface implementation in structures
      7. 9.7. IDisposable structures [C#]
    10. 10. Enum Types
      1. 10.1. Enum types in one source file
      2. 10.2. Enum types nested in another type
      3. 10.3. Enum type names
      4. 10.4. Flags attribute for bit-coded enum types
      5. 10.5. Base type for enum types
      6. 10.6. Member names in enum types
      7. 10.7. Values in non-bit-coded enum types
      8. 10.8. Values in bit-coded enum types
      9. 10.9. Default value for enum types
      10. 10.10. Default value for bit-coded enum types
      11. 10.11. Reserved enum values
      12. 10.12. Validation of enum values
      13. 10.13. Validation of bit-coded enum values
    11. 11. Attribute Types and Reflection
      1. 11.1. Applying attributes
      2. 11.2. Applying multiple attributes to the same member [C#]
      3. 11.3. Custom attribute type names
      4. 11.4. Sealed custom attribute types
      5. 11.5. Constructors in custom attribute types
      6. 11.6. Overloaded constructors in custom attribute types
      7. 11.7. The AttributeUsage attribute
      8. 11.8. Attribute vs. marker interfaces
      9. 11.9. Checking for a custom attribute
      10. 11.10. Loading an assembly for reflection purposes
      11. 11.11. Using the StackTrace object
      12. 11.12. Invoking a method through reflection
    12. 12. Fields and Variables
      1. 12.1. Field and variable names
      2. 12.2. Constant names
      3. 12.3. Hungarian notation
      4. 12.4. Common prefixes for variable names
      5. 12.5. Explicit private scope for fields
      6. 12.6. Multiple declarations on same line
      7. 12.7. Constant values
      8. 12.8. Read-only fields
      9. 12.9. Public instance fields
      10. 12.10. Public static fields
      11. 12.11. Protected fields
      12. 12.12. Local variables
      13. 12.13. Static local variables [Visual Basic]
      14. 12.14. Block variables
      15. 12.15. Block variable initialization [Visual Basic]
      16. 12.16. Name of fields wrapped by properties
      17. 12.17. Location of fields wrapped by properties
      18. 12.18. References to fields wrapped by properties
      19. 12.19. Field initialization
      20. 12.20. Simplified syntax for object instantiation [Visual Basic]
      21. 12.21. The DirectCast operator [Visual Basic]
      22. 12.22. The assignment operator inside expressions [C#]
      23. 12.23. The as operator [C#]
      24. 12.24. The With keyword [Visual Basic]
      25. 12.25. Temporary variables for nested objects [C#]
      26. 12.26. Nonserializable fields
      27. 12.27. IntPtr fields and properties
    13. 13. Properties
      1. 13.1. Property names
      2. 13.2. Property size
      3. 13.3. Compact formatting for properties [C#]
      4. 13.4. Validation and assignment in properties
      5. 13.5. Properties vs. methods
      6. 13.6. Read-only properties
      7. 13.7. Write-only properties
      8. 13.8. Properties with arguments
      9. 13.9. Default properties [Visual Basic]
      10. 13.10. The value keyword [C#]
      11. 13.11. Alternate friendly names for indexers [C#]
      12. 13.12. Is-prefixed Boolean read-only properties
      13. 13.13. Properties that return arrays
      14. 13.14. Properties that return collections
    14. 14. Methods
      1. 14.1. Method names
      2. 14.2. Method size
      3. 14.3. Number of arguments
      4. 14.4. Parameter names
      5. 14.5. Reserved parameters
      6. 14.6. Parameters typed as base classes
      7. 14.7. Argument validation
      8. 14.8. The ByVal keyword [Visual Basic]
      9. 14.9. Reference types passed by reference
      10. 14.10. ref and out arguments [C#]
      11. 14.11. Multiple by-reference arguments
      12. 14.12. Optional parameters [Visual Basic]
      13. 14.13. Variable number of parameters
      14. 14.14. Multiple parameters of same type
      15. 14.15. Special-case methods with a variable number of parameters
      16. 14.16. Single exit point
      17. 14.17. The Return keyword [Visual Basic]
      18. 14.18. Returning the result of an expression
      19. 14.19. Method overloading to reduce boxing
      20. 14.20. Method overloading to reduce number of arguments
      21. 14.21. Method overloading based on argument-passing style [C#]
      22. 14.22. Overloaded method chaining
      23. 14.23. Number of local variables
      24. 14.24. Get-prefixed methods
      25. 14.25. Get-prefixed methods matching property names
      26. 14.26. Set-prefixed methods
      27. 14.27. Method names that include type of returned value
      28. 14.28. Factory method names
      29. 14.29. Factory method parameters
      30. 14.30. Operator overloading in reference types [C#]
      31. 14.31. == and != operator overloading [C#]
      32. 14.32. Modifying arguments in overloaded operators [C#]
      33. 14.33. Alternative methods for operator overloading [C#]
      34. 14.34. Conversion and parsing methods
      35. 14.35. URI values
    15. 15. Constructors
      1. 15.1. Parameter names
      2. 15.2. Constructor size
      3. 15.3. Assignments to writable properties
      4. 15.4. Assignments to read-only properties
      5. 15.5. Explicit parameterless constructor
      6. 15.6. Main constructor for robust instances
      7. 15.7. Additional constructors for ease of use
      8. 15.8. Private constructors
      9. 15.9. Friend and internal constructors
      10. 15.10. Protected Friend and protected internal constructors
      11. 15.11. Static constructors in reference types
      12. 15.12. Static constructors in value types
      13. 15.13. Delegating to constructors with more parameters
      14. 15.14. Delegating to constructors with fewer parameters
      15. 15.15. Private parameterless constructor to help delegation
      16. 15.16. Constructors that take a disposable object
      17. 15.17. Calling virtual methods from inside a constructor
      18. 15.18. Exceptions in constructors
      19. 15.19. Exceptions in static constructors
    16. 16. Dispose and Finalize Methods
      1. 16.1. The IDisposable interface
      2. 16.2. Dispose and Finalize methods
      3. 16.3. Implementing only the Finalize method
      4. 16.4. using blocks for disposable objects [C#]
      5. 16.5. Invoking Dispose in the Finally block [Visual Basic]
      6. 16.6. Dispose vs. Close method
      7. 16.7. Field access in Finalize method
      8. 16.8. Error handling in the Finalize method [Visual Basic]
      9. 16.9. Throwing DisposedObjectException
      10. 16.10. The Dispose-Finalize pattern
      11. 16.11. The Dispose-Finalize pattern in derived types
    17. 17. Delegates and Events
      1. 17.1. Delegate and event names
      2. 17.2. EventArgs-derived type names
      3. 17.3. Delegate naming style
      4. 17.4. Event naming style
      5. 17.5. Name of event-handling methods
      6. 17.6. Scope of event-handling methods
      7. 17.7. Delegate invocation
      8. 17.8. Delegates vs. interfaces for callback methods
      9. 17.9. Instantiation of delegate objects [Visual Basic]
      10. 17.10. Event syntax
      11. 17.11. Event definition through delegates [Visual Basic]
      12. 17.12. Event return type
      13. 17.13. Event raising [C#]
      14. 17.14. Event unsubscription
      15. 17.15. Events that notify a property change
      16. 17.16. Raising events from inside overridable methods
      17. 17.17. The hidden event variable [Visual Basic]
      18. 17.18. WithEvents variables [Visual Basic]
      19. 17.19. Reentrancy issues when raising events
      20. 17.20. Raising events from secondary threads
      21. 17.21. Implementing the SynchronizingObject property
      22. 17.22. Events in Finalize methods
      23. 17.23. Events in serializable classes
    18. 18. Execution Flow
      1. 18.1. Multiple statements on one line
      2. 18.2. Empty parentheses in method calls [Visual Basic]
      3. 18.3. Invoking static methods [Visual Basic]
      4. 18.4. Invoking methods in modules [Visual Basic]
      5. 18.5. Single-statement If blocks [Visual Basic]
      6. 18.6. Single-statement conditional and loop blocks [C#]
      7. 18.7. Nested conditional and loop blocks
      8. 18.8. AndAlso and OrElse operators [Visual Basic]
      9. 18.9. Comparisons with true/false
      10. 18.10. Conditional blocks to assign a Boolean value
      11. 18.11. The ternary operator (? :) [C#]
      12. 18.12. The IIf function [Visual Basic]
      13. 18.13. Testing and comparing object types
      14. 18.14. Testing a variable for multiple values [Visual Basic]
      15. 18.15. Statements in Case blocks [Visual Basic]
      16. 18.16. Order of Case blocks
      17. 18.17. Asserting the default case
      18. 18.18. GoTo keyword [Visual Basic]
      19. 18.19. goto keyword [C#]
      20. 18.20. Variable declaration in For and For Each loops [Visual Basic]
      21. 18.21. Array upper limit in For loops
      22. 18.22. Modifying the controlling variable in For loops
      23. 18.23. Floating-point variables in For loops
      24. 18.24. Constant subexpressions in loops
      25. 18.25. While loops [Visual Basic]
      26. 18.26. Unsafe code [C#]
    19. 19. Exception Handling
      1. 19.1. Exception variable names
      2. 19.2. Custom exception type names
      3. 19.3. The On Error statement [Visual Basic]
      4. 19.4. Using exceptions to control execution flow
      5. 19.5. Throwing specific exception objects
      6. 19.6. Throwing on Dispose and Close methods
      7. 19.7. Exception message style
      8. 19.8. Localized error messages
      9. 19.9. XML remarks documenting which exceptions a method can throw [C#]
      10. 19.10. Remarks documenting which exceptions a method can throw [Visual Basic]
      11. 19.11. Can-prefixed read-only properties to prevent exceptions
      12. 19.12. Order of Catch blocks [Visual Basic]
      13. 19.13. The When keyword [Visual Basic]
      14. 19.14. Setting return values in Finally blocks [Visual Basic]
      15. 19.15. Undoing state in Catch blocks
      16. 19.16. Catching SystemException and ApplicationException
      17. 19.17. Catching DivideByZeroException
      18. 19.18. Catching special .NET exceptions
      19. 19.19. Throwing NotSupportedException vs. NotImplementedException
      20. 19.20. Catching exceptions in class libraries
      21. 19.21. Rethrowing original exceptions
      22. 19.22. Rethrowing exceptions of a different type
      23. 19.23. Exception logging
      24. 19.24. Defining custom exception types
      25. 19.25. Overall structure of custom exception types
      26. 19.26. Constructors in custom exception types
      27. 19.27. Exceptions in constructors of custom exception types
      28. 19.28. Serialization in custom exception types
      29. 19.29. Base class for custom exception types
    20. 20. Numeric Types
      1. 20.1. Constants in lieu of "magic" numbers
      2. 20.2. Integer field width
      3. 20.3. Unsigned integers [C#]
      4. 20.4. The checked and unchecked keywords [C#]
      5. 20.5. Language-specific math functions [Visual Basic]
      6. 20.6. Shortened notation for common math operations
      7. 20.7. ++ and -- operators [C#]
      8. 20.8. Multiple ++ and -- operators in same expression [C#]
      9. 20.9. Conversion of Boolean values to integers
      10. 20.10. Shift operators [Visual Basic]
      11. 20.11. Division operators [Visual Basic]
      12. 20.12. Decimal variables
      13. 20.13. Floating-point variables
      14. 20.14. Equality test for floating-point values
      15. 20.15. Floating-point temporary results [Visual Basic]
      16. 20.16. Multiplication instead of division
      17. 20.17. Multiplication instead of exponentiation
    21. 21. Strings
      1. 21.1. Strings used in the user interface
      2. 21.2. The & Operator [Visual Basic]
      3. 21.3. Char variables
      4. 21.4. String variable initialization
      5. 21.5. Long string expressions
      6. 21.6. Methods and properties that return strings
      7. 21.7. Language-specific string functions [Visual Basic]
      8. 21.8. Verbatim (@) string constants [C#]
      9. 21.9. Strings containing control characters [Visual Basic]
      10. 21.10. ChrW vs. Chr function [Visual Basic]
      11. 21.11. Looping over all the characters of a string [Visual Basic]
      12. 21.12. Checking for null strings
      13. 21.13. Checking for empty strings
      14. 21.14. Case-insensitive comparisons
      15. 21.15. Three-case string comparisons
      16. 21.16. String comparisons with CompareOrdinal
      17. 21.17. Searching and replacing with regular expressions
      18. 21.18. Validating with regular expressions
      19. 21.19. Concatenating a fixed number of strings
      20. 21.20. Concatenating a variable number of strings
      21. 21.21. StringBuilder initialization
      22. 21.22. StringBuilder reuse
      23. 21.23. Configuration-dependent strings
      24. 21.24. Setting the culture for the current thread
      25. 21.25. Culture-aware parsing and formatting
    22. 22. Arrays and Collections
      1. 22.1. Array and collection object names
      2. 22.2. Custom collection type names
      3. 22.3. Nonzero bound arrays
      4. 22.4. Arrays and collections in performance-critical code
      5. 22.5. Array initialization
      6. 22.6. Jagged arrays
      7. 22.7. The Collection object [Visual Basic]
      8. 22.8. Methods and properties that return arrays and collections
      9. 22.9. Loops over array and collection elements
      10. 22.10. Looping over two-dimensional matrices
      11. 22.11. Large arrays of Boolean values
      12. 22.12. Generic vs. strong-typed collections
      13. 22.13. Collection initial capability
      14. 22.14. Collection growth factor
      15. 22.15. Adding multiple elements to a collection
      16. 22.16. The SortedList object
      17. 22.17. Case-insensitive Hashtable and SortedList collections
      18. 22.18. Iterating over Hashtable or SortedList collections
      19. 22.19. Custom collection classes
      20. 22.20. Custom dictionary classes
      21. 22.21. Zero-based indexers
    23. 23. Memory Usage
      1. 23.1. Early creation of long-lasting objects
      2. 23.2. Boxing
      3. 23.3. Clearing object references
      4. 23.4. Clear object references explicitly in loops
      5. 23.5. Keeping objects alive
      6. 23.6. Explicit garbage collections in server applications
      7. 23.7. Explicit garbage collections in client applications
      8. 23.8. Waiting for finalizers after explicit garbage collections
      9. 23.9. Large object heap fragmentation
      10. 23.10. Compound finalizable objects
      11. 23.11. WeakReference objects
      12. 23.12. Garbage collector settings
  5. 2. .NET Framework Guidelines and Best Practices
    1. 24. Files, Streams, and XML
      1. 24.1. Custom stream names
      2. 24.2. Working with file and directory names
      3. 24.3. Absolute file paths
      4. 24.4. User data files
      5. 24.5. Temporary files
      6. 24.6. Reading files
      7. 24.7. Closing StreamWriter and BinaryWriter objects
      8. 24.8. Creating file associations
      9. 24.9. Adding data files to the recent document list
      10. 24.10. Using isolated storage
      11. 24.11. Writing XML text
      12. 24.12. Reading and writing XML files
      13. 24.13. Searching XML nodes
      14. 24.14. DateTime serialization
    2. 25. PInvoke and COM Interop
      1. 25.1. The DllImport attribute [Visual Basic]
      2. 25.2. All external methods in one type
      3. 25.3. IntPtr parameters
      4. 25.4. The SetLastError option
      5. 25.5. Explicitly release COM objects
      6. 25.6. Signed interop assemblies
      7. 25.7. Using Primary Interop Assemblies
      8. 25.8. Building Primary Interop Assemblies
      9. 25.9. Setting properties vs. invoking methods
      10. 25.10. Blittable arguments and return values
      11. 25.11. Variant arguments
      12. 25.12. Delegate arguments
      13. 25.13. COM-friendly .NET components
      14. 25.14. The ComVisible attribute
      15. 25.15. The DispId attribute
      16. 25.16. The ComClass attribute [Visual Basic]
      17. 25.17. The ClassInterface attribute
      18. 25.18. Exposing .NET events to COM clients
      19. 25.19. The ComRegisterFunction and ComUnregisterFunction attributes
    3. 26. Threading
      1. 26.1. Thread name
      2. 26.2. The IsBackground property
      3. 26.3. The Suspend, Resume, and Abort methods
      4. 26.4. The AppDomain.GetCurrentThreadId method
      5. 26.5. The Sleep method
      6. 26.6. The Join method
      7. 26.7. The ThreadAbortException type
      8. 26.8. SyncLock and lock blocks
      9. 26.9. Synchronized methods
      10. 26.10. Nested synchronization blocks
      11. 26.11. Objects in synchronization blocks
      12. 26.12. System.Type objects in synchronization blocks
      13. 26.13. Synchronizing on arrays and collections
      14. 26.14. Synchronized collections
      15. 26.15. Synchronizing access to Windows Forms objects
      16. 26.16. volatile fields [C#]
      17. 26.17. Thread-safe singleton objects
      18. 26.18. Synchronizing on multiple objects
      19. 26.19. ReaderWriterLock objects
      20. 26.20. Base class for threading
      21. 26.21. Asynchronous delegates
      22. 26.22. Expose asychronous methods in your classes
      23. 26.23. Timers
    4. 27. Windows Forms Applications
      1. 27.1. Form names
      2. 27.2. Loading startup form from Main method
      3. 27.3. The STAThread attribute
      4. 27.4. Windows Forms object and control names
      5. 27.5. Menu item names and shortcuts
      6. 27.6. GDI+ object names
      7. 27.7. Windows component names
      8. 27.8. ADO.NET Components
      9. 27.9. Control scope
      10. 27.10. Autogenerated code
      11. 27.11. Business logic
      12. 27.12. Resizable forms
      13. 27.13. Scrolling and tabbed forms
      14. 27.14. Read control properties from resource files
      15. 27.15. Common logic in base forms
      16. 27.16. Tool windows
      17. 27.17. The DialogResult property
      18. 27.18. The MsgBox command [Visual Basic]
      19. 27.19. Support for Windows XP Themes
      20. 27.20. Caption for MDI forms
      21. 27.21. Menu and toolbar commands
      22. 27.22. Help for individual controls
      23. 27.23. TabIndex ordering
      24. 27.24. Control accelerator keys
      25. 27.25. The UseMnemonic property
      26. 27.26. Control validation
      27. 27.27. The CausesValidation property
      28. 27.28. Appending text to a text box
      29. 27.29. Multilined text boxes
      30. 27.30. Global error handlers
      31. 27.31. React to screen resolution changes
      32. 27.32. Lengthy operations
      33. 27.33. The DoEvents method
      34. 27.34. The AccessibleName property
      35. 27.35. Using the registry
      36. 27.36. Previous application instances
      37. 27.37. Browsable properties in controls and components
    5. 28. ADO.NET Programming
      1. 28.1. ADO.NET object names
      2. 28.2. Error handling for database operations
      3. 28.3. Native .NET data providers
      4. 28.4. Provider-agnostic code
      5. 28.5. Connection strings
      6. 28.6. ADO.NET object constructors
      7. 28.7. Authentication mode for SQL Server databases
      8. 28.8. The PacketSize property
      9. 28.9. Primary keys in database tables
      10. 28.10. Asynchronous database operations
      11. 28.11. DataReader vs. DataSet
      12. 28.12. Filtering data
      13. 28.13. Sorting, and grouping
      14. 28.14. Reading individual rows
      15. 28.15. Reading individual values
      16. 28.16. Limit the number of rows in a resultset
      17. 28.17. NULL values in queries
      18. 28.18. Special characters in LIKE queries
      19. 28.19. Close a connection automatically
      20. 28.20. Cancel a DataReader query
      21. 28.21. Parameterized commands vs. dynamic SQL queries
      22. 28.22. Reusing SqlCommand objects
      23. 28.23. Parameterized commands vs. stored procedures
      24. 28.24. SQL Server stored procedure names
      25. 28.25. Access tables through views and stored procedures
      26. 28.26. Stored procedures that return a value
      27. 28.27. Large binary and text fields
      28. 28.28. Process large binary and text fields in chunks
      29. 28.29. Resultset pagination
      30. 28.30. Batch commands for SQL Server queries
      31. 28.31. DataSet names
      32. 28.32. DataTable names
      33. 28.33. DataRelation names
      34. 28.34. Strong-typed DataSet classes
      35. 28.35. DataSet vs. DataTable objects
      36. 28.36. The DataSet and DataTable Locale property
      37. 28.37. The DataAdapter’s autoconnect feature
      38. 28.38. CommandBuilder objects
      39. 28.39. Autoincrementing identity columns
      40. 28.40. DataSet serialization
      41. 28.41. Reading master-detail tables
      42. 28.42. Advanced SQL Generation Options dialog box
      43. 28.43. TimeStamp fields for optimistic concurrency
      44. 28.44. Transaction duration
      45. 28.45. Resolving update conflicts
      46. 28.46. Using the DataSet in transactional updates
      47. 28.47. Updating master-detail tables
    6. 29. ASP.NET Web Forms Applications
      1. 29.1. Web Forms control names
      2. 29.2. HTML control names
      3. 29.3. Main page properties
      4. 29.4. The pageLayout property
      5. 29.5. The targetSchema property
      6. 29.6. The SmartNavigation property
      7. 29.7. The EnableViewState property
      8. 29.8. The page title
      9. 29.9. Accounting for Web crawlers
      10. 29.10. Disabling debug mode in production sites
      11. 29.11. Deprecated Response properties
      12. 29.12. Using ViewState vs. manually restoring control’s contents
      13. 29.13. AutoPostBack controls
      14. 29.14. Image-based and hyperlink-based controls
      15. 29.15. User input validation
      16. 29.16. Formatting and parsing according to user language
      17. 29.17. Displaying data from files or database fields
      18. 29.18. Asking for confirmation before critical operations
      19. 29.19. Client-side and server-side data validation
      20. 29.20. Checking mandatory fields
      21. 29.21. Checking data type in input fields
      22. 29.22. Syntax restrictions in the RegularExpressionValidator control
      23. 29.23. Accepting uploaded files from the user
      24. 29.24. Size and type constraints on uploaded files
      25. 29.25. Checking filenames
      26. 29.26. Opening and closing database connections
      27. 29.27. SQL Server authentication in Web applications
      28. 29.28. Lengthy server-side operations
      29. 29.29. Data binding in Web Forms
      30. 29.30. Displaying multiple database columns in databound list controls
      31. 29.31. The ItemCommand event
      32. 29.32. State management: The ViewState dictionary
      33. 29.33. State management: The in-process Session dictionary
      34. 29.34. State management: The service-based Session dictionary
      35. 29.35. State management: The SQL Server–based Session dictionary
      36. 29.36. State management: Cookies
      37. 29.37. State management: Hidden fields
      38. 29.38. State management: The Application dictionary
      39. 29.39. State management: Global static variables
      40. 29.40. Disabled and read-only sessions
      41. 29.41. ViewState and Session elements as properties
      42. 29.42. ViewState, Session, Application, and Cache element names
      43. 29.43. The EnableViewStateMac property
      44. 29.44. The ViewStateUserKey property
      45. 29.45. ViewState validation and encryption in Web gardens
      46. 29.46. ViewState validation and encryption in Web farms
      47. 29.47. Redirecting to another page
      48. 29.48. Passing data between pages: The query string
      49. 29.49. Passing data between pages: The Context.Items collection
      50. 29.50. Passing data between pages: The Context.Handler property
      51. 29.51. Passing local URLs to another application
      52. 29.52. Using COM and COM+ legacy components
      53. 29.53. Caching the page’s contents
      54. 29.54. The Cache object
      55. 29.55. Global error handlers
      56. 29.56. Custom errors
      57. 29.57. Application-level tracing
      58. 29.58. ASP.NET identity
      59. 29.59. Encrypted credentials and connection strings in Web.config
      60. 29.60. URL authorization
      61. 29.61. Configuration settings for forms authentication
      62. 29.62. Custom forms authentication
      63. 29.63. Forms authentication cookies
      64. 29.64. Robust password policy
      65. 29.65. Client-side scripts
      66. 29.66. Centralized configuration files
      67. 29.67. Removing unused HTTP modules
    7. 30. ASP.NET Web Services
      1. 30.1. Name of .asmx files
      2. 30.2. The WebService attribute
      3. 30.3. The WebMethod attribute
      4. 30.4. The SoapInclude attribute
      5. 30.5. Caching method results
      6. 30.6. Proxy class namespace
      7. 30.7. Synchronous invocations
      8. 30.8. Asynchronous invocations
      9. 30.9. Support for proxy servers
      10. 30.10. The CookieContainer property
      11. 30.11. SOAP headers
      12. 30.12. One-way Web service calls
      13. 30.13. Web Service Enhancements (WSE)
    8. 31. Serviced Components
      1. 31.1. COM+ transactions vs. ADO.NET transactions
      2. 31.2. Static members
      3. 31.3. Library vs. server components
      4. 31.4. Assembly-level attributes
      5. 31.5. The ClassInterface attribute
      6. 31.6. The JustInTimeActivation attribute
      7. 31.7. The AutoComplete attribute
      8. 31.8. The Transaction attribute
      9. 31.9. Isolation level for nonroot components
      10. 31.10. Types with methods that require different isolation levels
      11. 31.11. Poolable objects
      12. 31.12. The ApplicationAccessControl attribute
      13. 31.13. The authentication level
      14. 31.14. The impersonation level
      15. 31.15. The ComponentAccessControl attribute
      16. 31.16. The SecurityRole attribute
      17. 31.17. COM+ role-based security at the method level
      18. 31.18. Programmatic security
      19. 31.19. Component identity
      20. 31.20. Disposing of a serviced component
      21. 31.21. WebMethod attributes in serviced components
    9. 32. Remoting
      1. 32.1. Remotable types
      2. 32.2. Host applications for .NET remoting
      3. 32.3. Port numbers
      4. 32.4. URI extensions
      5. 32.5. Server-Activated vs. Client-Activated Objects
      6. 32.6. Declarative vs. programmatic configuration
      7. 32.7. Loading a .NET remoting configuration file
      8. 32.8. TCP vs. HTTP channel
      9. 32.9. The rejectRemoteRequests attribute
      10. 32.10. The typeFilterLevel attribute
      11. 32.11. The <customErrors> tag
      12. 32.12. Hosting remoting objects in IIS
      13. 32.13. Never-expiring Singleton objects
      14. 32.14. One-way remoting calls
      15. 32.15. The Soapsuds tool
      16. 32.16. Using shared interfaces with SAOs
      17. 32.17. Using shared interfaces and factory methods with CAOs
      18. 32.18. Integrated Windows security in IIS
      19. 32.19. Basic authentication security in IIS
      20. 32.20. Exchanging data between different time zones
    10. 33. Security
      1. 33.1. Assembly-level permission requests
      2. 33.2. Demand permissions at application startup
      3. 33.3. Declarative vs. imperative security actions
      4. 33.4. The AllowPartiallyTrustedCallers attribute
      5. 33.5. Assert security actions
      6. 33.6. Deny and PermitOnly security actions
      7. 33.7. Security in event handlers and delegates
      8. 33.8. Security in exception handlers
      9. 33.9. LinkDemand security actions
      10. 33.10. InheritanceDemand security actions
      11. 33.11. The SuppressUnmanagedCodeSecurity attribute
      12. 33.12. Mixing type-level and method-level imperative security
      13. 33.13. Security checks in value types
      14. 33.14. Types implementing the ISerializable interface
      15. 33.15. The StrongNameIdentityPermission attribute
      16. 33.16. Protect libraries from unauthorized use
      17. 33.17. Policy level for ASP.NET applications
      18. 33.18. Setting the principal policy
      19. 33.19. Role-based security
      20. 33.20. Applying ACLs for configuration and data files
      21. 33.21. Encrypting data
      22. 33.22. Hashing data files
      23. 33.23. Protecting serialized objects
      24. 33.24. Storing user passwords
      25. 33.25. Random data for cryptographic purposes
      26. 33.26. Random data from user passwords
      27. 33.27. Obfuscating code
  6. A. Test
  7. B. The FxCop Tool
  8. C. Source Code and Other Goodies
  9. D. About the Authors
    1. D.1. Francesco Balena
    2. D.2. Giuseppe Dimauro
  10. Index