首页 > 解决方案 > vb.net 有没有办法知道实例化这个属性的属性构造函数中的类名?

问题描述

请注意,这是一个与使用反射通过自定义属性查找所有类的问题不同的问题。我知道。我在这里要问的是,当使用属性类时,它会增加一个计数器或类似共享变量的任何东西。我已经在下面解释了。我列出了一个类的属性使用情况。我想如果有一种方法可以维护字典,每当属性的对象被任何对象使用时,我就可以将两个名称都保存在字典中,然后,以后不要通过反射搜索,程序集名称等等例子。

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

我希望用户参数由系统自动获取,无论类使用它。说 myclass 正在使用它作为

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

标签: .netvb.netcustom-attributes

解决方案


推荐阅读