2,000 Things You Should Know About C#

Everything a C# Developer Needs to Know, in Bite-Sized Chunks

  • Home
  • About
  • Index
Posts Comments
  • Basics
  • Classes
  • Data Types
  • Methods
  • Exceptions
  • Visual Studio
  • Strings
  • Miscellaneous
  • Operators
  • Statements

#84 – Viewing Metadata as Source Code

September 9, 2010 1 Comment

When a C# application references another assembly, it has access to that assembly’s metadata.

One way to examine metadata for a type is to open the assembly using the IL Disassembler tool.  But you can also view the metadata directly in Visual Studio, using the Go To Definition command on anything not implemented in the current assembly.  The metadata will appear in a new code window, in the form of C# source code.

Suppose you have some code that creates a string object and calls its Replace method.  You can right-click on the Replace method in your code and select Go To Definition.

A new code window will open, showing all of the declarations for the string type, without their implementation.  The cursor will be positioned on the Replace method.  The title of the tab lists the class (“String”) and an indication that this was generated from metadata.

https://csharp.2000things.com/2010/06/28/examine-il-using-ildasm-exe/

Filed under Basics Tagged with C#, Metadata

Sean Sexton

Recent Posts

  • #1,219 – C# 6.0 – Filtering Exceptions
  • #1,218 – C# 6.0 – Using Expression-Bodied Property Getters
  • #1,217 – C# 6.0 – Using Expression-Bodied Methods
  • #1,216 – C# 6.0 – Initializing Read-Only Auto-Properties from Constructors
  • #1,215 – C# 6.0 – New Syntax for Dictionary Initializers

Blogroll

  • 2,000 Things You Should Know About WPF
  • Britannica Geek
  • Sean on Twitter
  • Sean's Stuff

Calendar

September 2010
S M T W T F S
« Aug   Oct »
 1234
567891011
12131415161718
19202122232425
2627282930  

Top Posts

  • Index
  • #349 - The Difference Between Virtual and Non-Virtual Methods
  • #416 - Use an Epsilon to Compare Two Floating Point Numbers
  • #443 - An Interface Cannot Contain Fields
  • #744 - The Purpose of Inheritance
  • #259 - Static vs. Instance Properties
  • #808 - Adding Parameters to an Extension Method
  • #392 - Reversing a String Using the Reverse Method
  • #143 - An Example of Implementing ICloneable for Deep Copies
  • #896 - Custom Exceptions Should Be Marked as Serializable

Tags

#define #if 6.0 Accessibility Anonymous Types Arguments Array Arrays Basics Boxing C# catch Class Class Diagram Classes Collections Constants Constructor Constructors Conversions Covariance Data Types Deep Copy Delegate Delegates Enum Enumeration Equals Events Exceptions Fields Finalizer Floating Point foreach Garbage Collection Generic Generics Heap IEnumerable Inheritance Intellisense Interface Interfaces Lambda Expression Main Memory Methods Miscellaneous Namespaces new null Nullable Object Object Initializer Operators Optional Parameters override Parameters Patterns Polymorphism Private Properties Public Reference Types Statements Static Strings struct Throw try Unicode Value Types Variables virtual Visual Studio

Blog Stats

  • 2,539,610 hits

Blog at WordPress.com.

Cancel
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy