I know that when we use properties in C #, the compiler always generates methods for getting and setting them in CIL for them (for example, get_PropertyName and set_PropertyName), for example, consider the following code fragment:
class Program
{
class Test
{
public string Name { get; set; }
}
static void Main(string[] args)
{
Type type = typeof(Test);
foreach (var item in type.GetMethods())
{
Console.WriteLine(item.Name);
}
}
}
This program will produce the output with the help of methods Test
, among which are get_Name
, and set_Name
- getters and setters, of which I spoke. As far as I understand, if getters and setters are created behind the scenes, then an auxiliary field should also be created from which / in which getters and setters get / set values. So, from the previous example, I can use reflection to check the fields of the Test class, for example:
static void Main(string[] args)
{
Type type = typeof(Test);
foreach (var item in type.GetFields())
{
Console.WriteLine(item.Name);
}
}
, , , private
, . , , , , ( get;
set;
)?