Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand the reflection of .NET

Shulou Source: shulou.com Published: 2022-06-02 20:31:34 11月12日 Update

In this issue, the editor will bring you a reflection on how to solve .NET. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Reflection

Reflection provides objects (Type types) that encapsulate assemblies, modules, and types. You can use reflection to dynamically create an instance of a type, bind a type to an existing object, or get a type from an existing object and call its methods or access its fields and properties. If attributes are used in your code, you can access them using reflection.

Get variable type

Int I = 42

System.Type type = i.GetType ()

Load assembly

System.Reflection.Assembly o = System.Reflection.Assembly.Load ("mscorlib.dll")

Applicable scenario

Need to access the properties of the program metadata

Check and instantiate types in an assembly

Build new types at run time, using classes in System.Reflection.Emit

Perform late binding to access methods of types created at run time

Performance influence

The performance loss of reflection mainly comes from three cases: comparison type, traversal member and calling member, in which the comparison type takes the least time and the calling member takes the most time, so minimize the use of member dynamic invocation and other reflection methods can improve application performance. In addition, the reflection performance can be improved by adopting late binding and avoiding the magnifying effect of the reflection method in the loop.

The above is the editor for you to share how to solve the reflection of .NET, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Tags: Type reflection program performance member object property content dynamic instance method analysis run minimum professional small and medium code rich content method variable Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Information Linux Xiaomi NVidia