Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding reflection

I recently started work at a new company and a .net web application we have is built using reflection. I have only been out of school for a year and haven't worked with this concept. After studying the code... it looks like there is a single backend interface of type object that has about 20 classes that inherit from it. lots of generic gets and sets

On the surface it looks like standard inheritance to me. I guess my question is, what makes this reflection? Is it because the interface is not strongly typed?

Thanks

like image 363
sdmiller Avatar asked Apr 24 '10 18:04

sdmiller


2 Answers

Please read about Reflection on Wikipedia first. Then check out the Reflection Namespace on MSDN.

I believe I know the general pattern that you are encountering. The need for reflection arises as the user can specify type and member names at runtime. The program then has to use reflection to map the supplied names to actual type members.

Generally speaking, if your program inspects object types at runtime, then you are using reflection.

BTW, Strong and Weak are attributes of the language type system, but not of any application or structure ( eg. interface, etc ) written using that language. ie. "C# is considered by many to be a strongly typed language".

like image 80
kervin Avatar answered Nov 06 '22 13:11

kervin


Who says it is "built using reflection"? Your coworkers?

Generally speaking, to use reflection means to inspect or generate code at runtime.

If the application is using reflection, it is probably using stuff from the System.Reflection namespace, so to get a feel for the extent to which reflection is used, you could remove references to this namespace and see what breaks...

like image 40
Rune Avatar answered Nov 06 '22 15:11

Rune