【发布时间】:2016-03-08 10:10:48
【问题描述】:
我正在寻找在 .Net 4.5 中获取调用方法的类名的解决方案,我希望使用自定义属性属性来实现它。 Here 是使用系统属性 CallerMemberName 获取成员名称的示例,但对于我自己的属性,我不确定要实现哪些函数来返回值。
有谁知道有关实现此类属性或任何示例的更多文档的链接?
到目前为止,我计划使用以下内容:
[AttributeUsage(AttributeTargets.Parameter)]
class MyAttribute : Attribute
{
//some method to implement returning the attribute value
}
class CallerTestClass
{
public string GetCallerClass(
[MyAttribute]string className = "")
{
return className;
}
}
【问题讨论】:
-
请阅读格式帮助以了解如何发布代码块 - 使用缩进而不是
<code>标签。
标签: c# .net visual-studio custom-attributes