.net - 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
解决方案
推荐阅读
- java - 是否可以先声明数组并在循环中对其进行初始化?
- node.js - 在 Node js 和 mongoose db 中的数组中查找对象
- java - Java:用图像中间字符串替换文本并与自动换行对齐
- laravel - Laravel 5.6 将 QueuedCommand 消息更改为更具可读性
- python - 如何在Python中的函数内循环不同项目的列表?
- ruby-on-rails - ActionController::ParameterMissing 和多选表中的行
- asp.net-mvc - asp.net MVC 不允许新建事务,因为会话中还有其他线程在运行
- visual-studio-code - 如何禁用 Visual Studio Code 自动保存
- sql - 在一对多关系中,是否可以在不使用计数和分组依据的情况下根据他们是否有某些孩子来查询父母?
- reactjs - 向蓝图选择组件弹出框添加元素?