Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a question about reflection and metadata

Status
Not open for further replies.

silverspecv

Programmer
Oct 31, 2003
125
0
0
US
I'm doing an online training thing for C#, and there is a little review quiz with the question:

Which type of metadata CANNOT be accessed by Reflection?
A) Class
B) Field
C) Operator
D) Any type can be accessed by Reflection

It says A)Class is the correct answer, but I'm not so sure. For my own edification, what CAN it read? The metadata isn't a collection of text strings you program into your objects, is it? Isn't it more of a system generated thing where reflection actually reads the dll or whatever and extracts exposed methods, etc?

So in the above, "operator" doesn't make sense, does it? Operator would mean like a + sign or something? And "field" would only be read as metadata if it was a parameter or return value of a method or an exposed property of an object right? I'm not sure about class, though. When the dll is compiled and is just sitting there, it is effectively a class right? And dll's are exactly what reflection does read, right?
 
In reflection, classes are referred to as types, and can be accessed:

Code:
System.Type t = obj.GetType();
or
Code:
System.Type t = typeof(int);

Fields, properties, events and methods can also be accessed:
Code:
obj.GetType().GetProperty("Name");

I'd say you found a mistake, as I would have answered C also.

Cheers,
Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top