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/
Advertisement

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
 1234
567891011
12131415161718
19202122232425
2627282930  
« Aug   Oct »

Top Posts

  • #782 - You Can Create an Instance of a struct Without the new Keyword
  • #95 - ToString() Called Automatically When Doing String Concatenation
  • #866 - A catch Block Without Arguments Catches All Exceptions
  • #820 - A Protected Constructor Allows a Subclass to Create Instances
  • #447 - Use as Operator to Get At an Object's Interfaces
  • #282 - Creating Private Static Methods
  • #449 - You Can Pass an Interface Variable to a Method
  • #349 - The Difference Between Virtual and Non-Virtual Methods
  • #131 - Arrays Derive from System.Array
  • #1,204 - C# 6.0 - Using Null-Conditional with Indexer

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,825,006 hits

Create a free website or blog at WordPress.com.

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
  • Follow Following
    • 2,000 Things You Should Know About C#
    • Join 367 other followers
    • Already have a WordPress.com account? Log in now.
    • 2,000 Things You Should Know About C#
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
 

Loading Comments...