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

View: 2391|Reply: 0

[Source] .NET/C# reflection attribute, which can be judged by null types

[Copy link]
Posted on 3/24/2024 11:39:53 AM | | | |
Requirements: During C# development, it may be necessary to use reflection to dynamically obtain the attribute type of an object and then process it accordingly. We want to classify nullable types and base types as the same type, e.g. string? = string,int? = int


When judging the type, int? and int types are different types, as shown in the image below:



How to directly obtain the base type when determining the null type? Refer to the UnwrapNullableTypeThe code is as follows:





Reference:

The hyperlink login is visible.
The hyperlink login is visible.





Previous:C# programming uses the Override and New keywords to distinguish between them
Next:A simple comparison of Garnet cache and Redis developed with .NET
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