I'm looking at a solution for getting the class name of a calling method in .Net 4.5 and I'm hoping to use a custom property attribute to implement it. Here is an example of using the System attribute CallerMemberName to get the member name but for my own attribute I'm not sure which functions to implement to return a value.
Does anyone know of links to more documentation on implementing this type of attribute or of any examples?
So far I'm planning on using the following:
[AttributeUsage(AttributeTargets.Parameter)]
class MyAttribute : Attribute
{
//some method to implement returning the attribute value
}
class CallerTestClass
{
public string GetCallerClass(
[MyAttribute]string className = "")
{
return className;
}
}
` tags.
– Jon Skeet Dec 03 '15 at 17:11