|
About Reflections Article Review:
.net/c# Dynamic Execution Methods Using Reflection h ttps:// www.itsvse.com/thread-4771-1-1.html
c# Determining if a property is assigned a value through reflection h ttps:// www.itsvse.com/thread-3045-1-1.html
c# Reflection to get the displayname of an object property h ttps:// www.itsvse.com/thread-3219-1-1.html About emit Review:
NET/C# Emit Dynamically Generated Assemblies h ttps:// www.itsvse.com/thread-9597-1-1.html First, create a new simple object, instantiate the object, use emit and expression to read and modify the value of the object, you can see that the results are as expected, as shown below:
BenchmarkDotNet was used for benchmarking, only object values were read for testing, and the running platforms were Net472 and NetCoreApp31, the test results are as follows:
NET/C# using BenchmarkDotNet to test code performance. h ttps:// www.itsvse.com/thread-9576-1-1.html
To summarize:
Using both emit and expression is more efficient than using reflection to get a value. emit outperforms expression in the .NET 4.7.2 framework, but expression outperforms emit in the .NET Core 3.1 framework.
If your program only needs to dynamically execute an object once, it is recommended to use reflection (after all, you don't need to encapsulate it again, and you don't need to create a delegate), if your program needs to dynamically execute an object several times, it is recommended to use emit or expression, and of course, it needs to be encapsulated further.
The test code is as follows:
When using Expression to get the value of an object, the online code will report the following error:
Expression of type 'System.Int32' cannot be used for return type 'System.Object' I really don't know how these people use it, just copy and paste! |
Previous: NET/C# Emit Dynamically Generated AssembliesNext article: .NET Core call gRPC HTTP (non-TLS protected ) address error solution
|