Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Writing a More Flexible StackTrace Class
|
293
Discussion
This recipe uses the System.Diagnostics.StackTrace object to obtain a list of stack
frames, which it then provides to the user. The
StackTrace class provides a conve-
nient way to obtain a stack trace, an exception object, or a specific thread from the
current point in code. Unfortunately, the
StackTrace provides only a very simplified
way to get at each stack frame. It would be much better if the
StackTrace object oper-
ated like a collection. To make this happen, you can create an intermediate object
called
StackTraceList that inherits from StackTrace and implements the ICloneable,
IList, ICollection, and IEnumerable interfaces.
The constructors for the
StackTraceList class mimic the StackTrace constructors.
Each
StackTraceList constructor passes its work along to the base class using the
base keyword:
public StackTraceList( ) : base( )
Each StackTraceList constructor contains a call to the private method, Init-
InternalFrameArray
. This private method copies all of the individual StackFrame
objects from the base StackTrace object into a private field of type StackFrame[]
called internalFrameArray. The StackTraceList uses the internalFrameArray field as a
convenient storage mechanism for each individual
StackFrame object; in addition,
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# Cookbook

C# Cookbook

Joe Mayo
C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata