03.01.2015 Views

C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

26<br />

Reflection<br />

What’s in This Chapter<br />

➤➤<br />

➤➤<br />

➤➤<br />

➤➤<br />

➤➤<br />

Learning about assemblies<br />

Enumerating fields, properties, methods, and events<br />

Getting and setting property values<br />

Creating add-ins<br />

Compiling and executing scripts at run time<br />

Wrox.com Downloads for This Chapter<br />

Please note that all the code examples for this chapter are available as a part of this chapter’s<br />

code download on the book’s website at www.wrox.com/go/csharp5programmersref on the<br />

Download Code tab.<br />

Reflection is a process by which a program can examine and manipulate program objects at<br />

run time. For example, serialization (described in the preceding chapter) uses reflection to figure<br />

out what values an object has and what their data types are so that it can save and restore them.<br />

IntelliSense also uses reflection to describe the parameters that a method takes while you are<br />

entering those parameters.<br />

Reflection is a fairly advanced technique that isn’t necessary for most programs. Usually,<br />

when you write a program, you know what you want it to do and what methods you need to<br />

call to do it. It’s unusual, for example, to be working with an Invoice class and not know<br />

what properties, methods, and events that class defines. Even if you don’t know what’s in a<br />

class and you use reflection to find out, it would be quite hard to make the program use those<br />

discovered items effectively.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!