0

Please note that this is a different question than, the one which asks about finding all classes by custom attributes using reflection. I know that. What I am asking here is, when the attribute class is used, it increments a counter or whatever like a shared variable. I have explained below. I am listing the attribute usage by a class. I thought if there is a way that I can maintain a dictionary, whenever an object of the attribute is used by whatever object, so that I can keep both names in a dictionary and then, later on, do not search by reflection, assembly names etc. Example.

Class MyAttribute
Inherits Attribute
Sub New(byval name as string, optional byValue user as string = "")
me.name = name
me.user = user
'maintain dict here
End Sub

I want the user parameter, to be grabbed automatically by the system whatever class is using it. Say myclass is using it as

MyAttribute("bobe") ' note I am not passing user param, it should be auto to the name of the class MyClass here
MyClass
'exyz
End Class
Sahib Khan
  • 557
  • 4
  • 19
  • 2
    Be aware that your attribute's constructor only runs if something causes the attributes for a *particular* class to be retrieved. You're not guaranteed that this has happened for all attributes for all loaded assemblies, unless you run some reflection code that finds all loaded assemblies and queries the custom attributes for all types. At which point *that* code seems to have the opportunity to gather the data you're asking for. – Damien_The_Unbeliever Nov 05 '18 at 15:14
  • I understand this part of it. I m just curious if I can get rid of looping over all the assemblies, and then finding types by my custom attribute. – Sahib Khan Nov 17 '18 at 03:47

0 Answers0