Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an attribute, SelectAttribute, that I can apply to fields and properties. If possible, I want the attribute to run a check to verify that it goes only on fields and properties of type string.

I am using C# 2015, .Net version 4.8.

What I have tried:

Nothing so far, I am not sure if this is even possible.
Posted
Updated 3-Apr-20 3:27am
Comments
gggustafson 2-Apr-20 14:53pm    
I think you'll need some form of Reflection.
j snooze 2-Apr-20 17:38pm    
I concur with gggustafson. Use reflection to dive into objects, the properties and such.

1 solution

This documentation should set you down the right path
Accessing Attributes by Using Reflection (C#) | Microsoft Docs[^]
The worked example in that link uses the typeof the class with the attribute so in theory you could check for string
 
Share this answer
 
Comments
Maciej Los 3-Apr-20 10:35am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900