This article is a mirror article of machine translation, please click here to jump to the original article.

View: 27740|Reply: 2

[Source] .net/C# reflects non-anonymous functions <>f__AnonymousType0 methods

[Copy link]
Posted on 2020-10-16 17:51:42 | | | |
When using AOP face-to-face programming, you need to set the method to a virtual method to intercept the method normally. Because there are too many methods to miss virtual keywords, use reflection to get all methods to determine if you miss keywords. When using the reflection acquisition method, a large number of anonymous functions <>f__AnonymousType0 will be obtained, and this paper uses the reflection exclusion anonymous method to obtain all methods of all objects that inherit the generic base class, and the text includes .NET and .NET Core versions.

C# Anonymous Type Learning Diary
https://www.itsvse.com/thread-9417-1-1.html


Get the current assembly first

.NET version:



.NET Core Version:



The base class inherited by the service object



Reflection acquisition non-virtual method

When you get all the assemblies and all the methods through reflection, you may get the AnonymousType anonymous method, as shown in the figure below:



.NET version



.NET Core version



Determine whether it is an anonymous function



The Namespace and DeclaringType of anonymous functions are null, and the Namespace of non-anonymous functions must not be null!




Previous:C# Anonymous Type Learning Diary
Next:Debugging .NET programs with Notepad at home on a computer for ten years
 Landlord| Posted on 2020-10-16 18:02:10 |
When you get all the objects of the assembly, you will find some anonymous objects generated by the +<>c compiler
CompilerGeneratedAttribute properties can be used to distinguish between compiler-generated objects

The code is as follows:


 Landlord| Posted on 2024-5-29 11:18:39 |
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com