Visual CSharp 2005 Recipes (2006) [eng]
.pdf528 ■I N D E X
AddRectangle method |
application domains, 65 |
GraphicsPath class, 263 |
avoid loading unnecessary assemblies into, |
AddString method |
70–71 |
GraphicsPath class, 263 |
creating types that cannot cross app domain |
AddValue method |
boundaries, 71–72 |
SerializationInfo class, 459 |
creating, 66–67 |
AddXXXX methods |
creating types to be passed across app |
DateTime structure, 50 |
domain boundaries, 67–70 |
Administrator value |
executing assembly into different assembly, |
WindowsBuiltInRole enumeration, 413 |
74–76 |
ADO.NET |
instantiating type into different assembly, |
commonly used aspects, 300 |
76–80 |
Advanced .NET Remoting, 2nd edition |
loading assembly into, 72–74 |
Rammer, Ingo and Szpuszta, Mario, 384 |
passing data between, 80–82 |
All value |
unloading at runtime, 82–83 |
AttributeTargets enumeration, 91 |
Application Settings |
AllDirectories value |
Visual Studio, 226–227 |
SearchOption enumeration, 163 |
ApplicationBase property |
AllowDrop property |
AppDomainSetup class, 66 |
Control class, 251 |
ApplicationDirectory class |
AllowMultiple property |
System.Security.Policy namespace, 408 |
AttributeUsageAttribute class, 92 |
ApplicationException class, 487 |
AllowNavigation property |
applications |
WebBrowser control, 254 |
ensuring only one instance of can execute |
AllowPartiallyTrustedCallersAttribute class, 396 |
concurrently, 140–141 |
System.Security namespace, 395 |
apply templates command, 210 |
Alt value |
ArgumentException class |
ConsoleModifiers enumeration, 62 |
System namespace, 52, 307, 346, 467 |
AND (&) arithmetic operator, 147 |
ArgumentNullException class |
AND (&&) operator, 13 |
System namespace, 88, 487 |
animated system tray icon, 247–248 |
ArgumentOutOfRangeException class |
animation using DirectShow, 279–282 |
System namespace, 32, 487 |
AppDomain class, 175–176 |
Array class |
CreateDomain method, 66 |
Sort method, 51 |
CreateInstance method, 76–77 |
ArrayList class, 31 |
CreateInstanceAndUnwrap method, 77 |
Sort method, 51, 468 |
CreateInstanceFrom method, 76 |
System.Collections namespace, 59, 81, 468 |
CreateInstanceFromAndUnwrap method, 77 |
ToArray method, 52 |
ExecuteAssembly method, 75–76 |
arrays |
ExecuteAssemlyByName method, 75 |
copying a collection to, 52–54 |
GetData method, 80–81 |
sorting, 51–52 |
IsFinalizingForUnload method, 83 |
ASCII property |
SetData method, 80–81 |
ASCIIEncoding class, 34 |
SetPrincipalPolicy method, 415 |
Encoding class, 353 |
SetThreadPrincipal method, 415 |
ASCIIEncoding class |
System namespace, 415 |
ASCII property, 34 |
Unload method, 83 |
GetEncoding method, 34 |
AppDomainSetup class |
assemblies |
properties, 66 |
allowing partially trusted code to use strong- |
values, 81 |
named assemblies, 394–396 |
AppendChar method |
delay signing, 20–21 |
SecureString class, 432 |
ensuring runtime grants specific permissions |
AppendChild method |
to, 400–402 |
XmlNode class, 187 |
inspecting evidence, 409–411 |
Application class |
limiting permissions granted to, 402–403 |
OpenForms property, 220 |
signing with Authenticode, 22–25 |
Run method, 4 |
strong-naming, 17–19 |
System.Windows.Forms namespace, 4 |
unloading at runtime, 82–83 |
application development |
viewing permissions required by, |
introduction and tools, 1 |
403–406 |
530 ■I N D E X
binary data |
CancelAsync method |
Base64-encoding, 38–41 |
WebClient class, 342 |
binary files |
CanGoBack property |
reading and writing, 158–160 |
WebBrowser control, 254 |
BinaryFormatter class, 60 |
CanGoForward property |
Deserialize method, 58 |
WebBrowser control, 254 |
Serialize method, 58 |
CanHandlePowerEvent property |
System.Runtime.Serialization.Formatters. |
ServiceBase class, 512 |
Binary namespace, 58, 464 |
CanHandleSessionChangeEvent property |
BinaryReader class |
ServiceBase class, 513 |
Read method, 158 |
CannotUnloadAppDomainException class |
ReadDecimal method, 158 |
System namespace, 83 |
reading from MemoryStream, 36 |
CanPauseAndContinue property |
ReadString method, 158 |
ServiceBase class, 512 |
System.IO namespace, 36, 158, 344 |
CanShutdown property |
BinaryWriter class |
ServiceBase class, 512 |
converting decimal type to byte array, 36 |
CanStop property |
System.IO namespace, 36, 158 |
ServiceBase class, 512 |
Write method, 158 |
Capacity property |
BitConverter class |
StringBuilder class, 32 |
converting bool type to and from byte array, |
Caspol.exe, 397 |
36–38 |
caspol -e off, 398, 400 |
converting int type to and from byte array, |
caspol -e off command, 398, 400 |
36–38 |
Code Access Security Policy tool, 396 |
GetBytes method, 36 |
casting |
System namespace, 427 |
specialized collection classes, 135 |
ToBoolean method, 36 |
CC property |
ToInt32 method, 36 |
MailMessage class, 353 |
ToString method, 38, 427–428 |
CCW (COM callable wrapper) defined, 455 |
Bitmap class |
cert2spc.exe, 25 |
creating object, 270 |
Certificate Creation tool |
BitVector32 class |
arguments supported, 26 |
does not implement ICollection interface, |
creating test X.509 certificate, 25 |
134 |
Certificates class |
blocking |
Find method, 350, 376 |
determining if asynchronous methods are |
Select method, 376 |
finished, 325 |
Certificates property |
Body property |
WebClient class, 350 |
MailMessage class, 353 |
WebRequest class, 349 |
BodyEncoding property |
Change method |
MailMessage class, 353 |
Timer class, 108 |
bool type |
Changed event |
converting to and from byte array using |
FileSystemWatcher class, 176–177 |
BitConverter class, 36–38 |
ChangeExtension method |
BufferHeight property |
Path class, 165–166 |
Console class, 29 |
char array |
BufferWidth property |
converting binary data to and from, 38 |
Console class, 29 |
character-encoding classes, 34 |
byte arrays |
CheckExecutionRights property |
Base64 encoding and decoding using |
SecurityManager class, 398–400 |
Convert class, 38 |
CheckFileExists property |
converting to standard value types, |
OpenFileDialog class, 172 |
36 |
ChildNodes property |
■C |
XmlDocument class, 184 |
XmlNode class, 184 |
|
callback |
classes |
determining if asynchronous methods are |
restricting who can extend and override |
finished, 326 |
members, 407–409 |
CancelAllJobs method |
ClassesRoot field |
Win32_Printer class, 298 |
RegistryKey class, 509 |
■I N D E X 531
Clear method |
COM Interop |
Console class, 29 |
accessing ADO objects, 451 |
SecureString class, 433 |
all code full trust, 395 |
ClientCertificates collection |
COM port, accessing, 179–180 |
HttpWebRequest class, 350 |
Combo Box class |
System.Security.Cryptography.X509 |
creating autocomplete version, 232–234 |
Certificates namespace, 376 |
ComboBox control |
ClientCertificates property |
AutoCompleteMode property, 232 |
SmtpClient class, 352 |
KeyPress event, 232 |
WebRequest class, 376 |
OnKeyPress method, 232 |
ClientHandler class, 364 |
OnTextChanged method, 232 |
ClientRectangle property |
TextChanged event, 232 |
Control class, 265 |
command line |
Clone method |
accessing command-line arguments, 10–11 |
ICloneable interface, 463–464 |
creating and using a code library, 9–10 |
cloneable types |
creating and using a code module, 7–9 |
implementing, 463–467 |
creating a console application, 2–4 |
CloneMenu method |
creating a Windows-based application, 4–7 |
MenuItem class, 239 |
including code selectively at build time, 12–15 |
CloneNode method |
command-line utilities |
XmlDocument class, 189 |
Tlbexp.exe, 455 |
XmlNode class, 191 |
Tlbimp.exe, 451 |
Close method |
xsd.exe (XML Schema Definition Tool), |
connection objects, 302 |
207 |
data reader classes, 320 |
command objects |
HttpListenerContext class, 347 |
common properties, 312 |
CloseAllFigures method |
creating, 312 |
GraphicsPath class, 263 |
CommandLine property |
CloseMainWindow method |
Environment class, 10, 500 |
Process class, 138–139 |
CommandText property |
code |
command objects, 312 |
See also unmanaged code |
IDbCommand interface, 311 |
preventing decompilation, 27–28 |
CommandTimeout property |
selectively including at build time with |
command objects, 312 |
command line, 12–15 |
CommandType enumeration |
code access permissions, 402 |
System.Data namespace, 312 |
code access security, 393 |
values, 312 |
disabling, 396–398 |
CommandType property |
Code Access Security Policy tool. |
command objects, 312 |
See Caspol.exe |
IDbCommand interface, 311 |
code groups, 393 |
CommonDialog class |
code library |
System.Windows.Forms namespace, 172 |
create and use from command line, |
comparable types |
9–10 |
implementing, 467–471 |
code module |
Compare method |
create and use with command line, 7–9 |
IComparer interface, 235, 468 |
collections |
CompareExchange method |
copying to arrays, 52–54 |
Interlocked class, 129 |
ColumnCount property |
CompareTo method |
TableLayoutPanel container, 238 |
IComparable interface, 467 |
COM |
Compiled option |
exposing .NET components, 455–456 |
RegexOptions enumeration, 45 |
COM callable wrapper. See CCW (COM callable |
CompileToAssembly method |
wrapper) |
Regex class, 45–46 |
COM clients |
complex types |
recommendations, 456 |
XML schemas, 200 |
type requirements, 455 |
Component class |
COM components |
System.ComponentModel namespace, 72, |
releasing quickly, 452–453 |
342, 358 |
using in .NET clients, 450–452 |
WebClient class derives from, 342 |
532 ■I N D E X
ComputeHash method |
Contains method |
HashAlgorithm class, 164, 424–425, 430 |
Rectangle struct, 259–260 |
ConditionalAttribute class, 13 |
context-sensitive help, 252–253 |
applying to a method, 13 |
ContextMenu property |
System.Diagnostics namespace, 12 |
NotifyIcon control, 247 |
used by Trace and Debug classes, 15 |
Control class |
Configuration class |
AllowDrop property, 251 |
System.Configuration namespace, 309 |
ClientRectangle property, 265 |
ConfigurationFile property |
deriving class from, 265 |
AppDomainSetup class, 66 |
DoDragDrop method, 251 |
ConfigurationManager class |
DragDrop event, 251 |
ConnectionStrings property, 309 |
DragEnter event, 251 |
OpenExeConfiguration method, 309 |
Handle property, 279, 442 |
System.Configuration namespace, 309 |
MouseDown event, 244, 251 |
Configure method |
MouseMove event, 244 |
RemotingConfiguration class, 381 |
MouseUp event, 244 |
connection pooling, 304 |
Region property, 263, 265 |
example, 305–306 |
System.Windows.Forms namespace, 265 |
settings, 304–305 |
Tag property, 217 |
Connection property |
Control value |
command objects, 312 |
ConsoleModifiers enumeration, 62 |
ConnectionString property |
ControlBox property |
ConnectionStringSettings class, 309 |
Form class, 244 |
IDbConnection interface, 301, 307 |
ControlCollection class |
ConnectionStrings property |
Add method, 214 |
ConfigurationManager class, 309 |
obtaining, 214, 219 |
ConnectionStringSettings class |
ControlPolicy element |
ConnectionString property, 309 |
SecurityPermission class, 397, 399 |
creating and configuring, 309 |
ControlPrincipal element |
ProviderName property, 309 |
SecurityPermission class, 415, 418 |
System.Configuration namespace, 309 |
controls, creating irregularly shaped control, |
ConnectionStringsSection collection |
263–265 |
adding ConnectionStringSettings object to, 309 |
Controls property |
SectionInformation class, 309 |
Container class, 214 |
console |
Form class, 219 |
manipulating appearance, 28–30 |
Convert class |
reading user input, 61–64 |
Base64 encoding and decoding, 38 |
console application |
FromBase64CharArray method, 38 |
creating from command line, 2–4 |
FromBase64String method, 38 |
Console class |
System namespace, 38 |
Beep method, 275 |
ToBase64CharArray method, 38 |
example, 275–276 |
ToBase64String method, 38 |
KeyAvailable method, 62 |
Convert method |
properties and methods, 29 |
Encoding class, 35 |
Read method, 61 |
CopyFromScreen method |
ReadKey method, 61 |
Graphics class, 270 |
ReadLine method, 61 |
CopyTo method |
System namespace, 28, 61, 483 |
FileInfo class, 149 |
ConsoleColor enumeration |
ICollection interface, 52 |
System namespace, 29 |
count function, 196 |
ConsoleKeyInfo class |
Covington, Michael A |
properties, 62 |
System.GC.KeepAlive(mutex) statement, |
System namespace, 62 |
141 |
ConsoleModifiers enumeration |
Create method |
values, 62 |
DirectoryInfo class, 150 |
ConstructorInfo class |
FileInfo class, 149 |
Invoke method, 87–88 |
HashAlgorithm class, 164, 424, 426 |
System.Reflection namespace, 87 |
KeyedHashAlgorithm class, 430 |
Container class |
RandomNumberGenerator class, 421 |
Controls property, 214 |
WebRequest class, 344 |
■I N D E X 533
XmlReader class, 197, 200–201 |
Credentials property |
XmlWriter class, 197 |
SmtpClient class, 352 |
CreateAdapter factory method |
WebClient class, 350 |
DbProviderFactory class, 328 |
WebRequest class, 349–350, 376 |
CreateAttribute method |
critical sections, 116 |
XmlDocument class, 187 |
CrossProcess value |
CreateCommand factory method |
MemoryProtectionScope enumeration, |
connection objects, 312 |
436 |
DbProviderFactory class, 328 |
CryptGenRandom function, 421 |
CreateCommand method |
cryptography, 393–394 |
IDbConnection interface, 312, 328 |
calculating the hash code of a file, 425–427 |
CreateConnection factory method |
calculating the hash code of a password, |
DbProviderFactory class, 328 |
422–425 |
Created event |
creating a cryptographically random |
FileSystemWatcher class, |
number, 421–422 |
176–177 |
encrypting and decrypting data using data |
CreateDomain method |
protection API, 435–437 |
AppDomain class, 66 |
ensuring data integrity using keyed hash |
CreateElement method |
code, 429–431 |
XmlDocument class, 187 |
verifying a hash code, 427–429 |
CreateInstance method |
working with security-sensitive strings in |
Activator class, 90 |
memory, 432–435 |
AppDomain class, 76–77 |
CS1555 compilation error, 2 |
CreateInstanceAndUnwrap method |
CultureInfo class, 484 |
AppDomain class, 77 |
CurrentCulture method, 484 |
CreateInstanceFrom method |
System.Globalization namespace, |
Activator class, 90 |
484 |
AppDomain class, 76 |
Currency value |
CreateInstanceFromAndUnwrap method |
DbType enumeration, 316 |
AppDomain class, 77 |
Current property |
CreateNode method |
IEnumerator interface, 475 |
XmlDocument class, 187 |
CurrentConfig field |
CreateParameter factory method |
RegistryKey class, 509 |
DbProviderFactory class, 328 |
CurrentCulture method |
CreateParameter method |
CultureInfo class, 484 |
IDbCommand interface, 316, 328 |
CurrentDirectory property |
CreatePrompt property |
Environment class, 500 |
SaveFileDialog class, 173 |
CurrentPrincipal property |
CreateShortcut method |
Thread class, 415, 418 |
WshShell class, 518 |
CurrentUICulture property |
CreateSubdirectory method |
Thread class, 243 |
DirectoryInfo class, 150 |
CurrentUser field |
CreateSubdirectory property |
RegistryKey class, 509 |
DirectoryInfo class, 144 |
CurrentUser value |
CreateSubKey method |
DataProtectionScope enumeration, |
RegistryKey class, 509 |
436 |
CreateText method |
CursorLeft property |
FileInfo class, 149 |
Console class, 29 |
CreationTime property |
CursorSize property |
DirectoryInfo class, 144 |
Console class, 29 |
FileInfo class, 144 |
CursorTop property |
CreationTime value |
Console class, 29 |
NotifyFilters enumeration, 177 |
CursorVisible property |
CredentialCache class |
Console class, 29 |
Add method, 376 |
custom attribute |
DefaultCredentials property, |
creating, 91–93 |
350, 352 |
custom event argument |
implements ICredentialsByHost interface, |
implementing, 490–492 |
352 |
custom exception class |
System.Net namespace, 350 |
implementing, 486–490 |
■I N D E X 535
Deserialize method |
DllImportAttribute class |
BinaryFormatter class, 58 |
EntryPoint portion, 440 |
IFormatter interface, 58 |
SetLastError field, 448 |
SoapFormatter class, 58 |
System.Runtime.InteropServices namespace, |
destructor, 480 |
439 |
dialog boxes, showing, 172–174 |
Dns class |
Dictionary class |
BeginGetHostEntry method, 355 |
System.Collections.Generic namespace, 54, |
EndGetHostEntry method, 355 |
223 |
GetHostByName method, 355 |
Direction property |
GetHostEntry method, 355 |
parameter objects, 316 |
GetHostName method, 355 |
Direction value |
System.NET namespace, 355 |
ParameterDirection enumeration, |
Document property |
316 |
PrintDialog class, 285 |
Directory class |
PrintPreviewControl class, 293 |
Exists method, 167 |
PrintPreviewDialog class, 292 |
GetCurrentDirectory method, 168 |
WebBrowser control, 255 |
GetLogicalDrives method, 170 |
DocumentCompleted event |
SetCurrentDirectory method, 168 |
WebBrowser control, 254 |
System.IO namespace, 167–168 |
DocumentElement class |
using instead of DirectoryInfo, 147 |
containing nested XMLNode objects, 184 |
Directory property |
DocumentElement property |
FileInfo class, 144 |
XmlDocument class, 184 |
DirectoryInfo class, 143 |
documents |
Attributes property, 148 |
validating against a schema, 199–204 |
copy method is missing from class, |
DocumentText property |
150 |
WebBrowser class, 211 |
derives from FileSystemInfo class, 145 |
WebBrowser control, 255 |
GetDirectories method, 163 |
DoDragDrop method |
GetFiles method, 163 |
Control class, 251 |
members, 144 |
DOM (W3C Document Object Model), 184 |
methods, 150 |
Domain property |
Refresh method, 145 |
ProcessStartInfo class, 136 |
System.IO namespace, 144, 147, 149, 163 |
double buffering |
using Directory class instead, 147 |
using to increase redraw speed, 271–273 |
DirectoryName property |
DoubleBuffered property |
FileInfo class, 144 |
Form class, 271 |
DirectoryName value |
Down value |
NotifyFilters enumeration, 177 |
OperationalStatus enumeration, 337 |
DirectoryNotFoundException class, 145 |
DownloadData method |
DirectorySecurity class |
WebClient class, 341 |
retrieving, 180 |
DownloadDataAsync method |
DirectShow |
WebClient class, 341 |
showing animation, 279–282 |
DownloadDataCompleted event |
DisallowPublisherPolicy property |
WebClient class, 341 |
AppDomainSetup class, 66 |
DownloadFile method |
DisplayName property |
WebClient class, 341 |
ServiceInstaller class, 516 |
DownloadFileAsync method |
disposable class |
WebClient class, 341 |
implementing, 480–483 |
DownloadString method |
Dispose method |
WebClient class, 341 |
IDisposable interface, 480, 510 |
DownloadStringAsync method |
SecureString class, 433 |
WebClient class, 341 |
Timer class, 108 |
DownloadStringCompleted event |
Dispose pattern |
WebClient class, 341 |
example, 481–483 |
DPAPIProtectedConfigurationProvider class, |
implementing, 480 |
309 |
using statement, 480 |
drag-and-drop operations, 251–252 |
Distributed Component Object Model. See |
DragDrop event |
DCOM |
Control class, 251 |