What is the C # language property that makes reflection possible?

What is the C # language property that makes reflection possible? Is it something the whole object-oriented language can do, or is it something any interpreted language can do? Or something else...

+4
source share
4 answers

The compiler knows a lot about the program you are writing. He knows each class you programmed, the names of the methods, the arguments that they take. Traditionally, compilers threw this extra information about your program away after they generated executable code for your program.

.NET, . . .NET.exe DLL , . System.Type .

, , . [].

. . , . , . , , , . - , .

+9

/ # . BindingFlags , .

:

MethodInfo[] myArrayMethodInfo1 = myType.GetMethods(BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly);
+1

- .

:

int i = 42;
System.Type type = i.GetType();
System.Console.WriteLine(type);

, .

# - , -, #, . , , .

0

, ,

# - . .

#, . , benifit

.

0

Source: https://habr.com/ru/post/1524247/


All Articles