How does a Property type passed to a function set the parameter value

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;
    }
}
Jon Skeet
people
quotationmark

You can't, basically. The C# compiler has special knowledge of the CallerMemberName attribute - it doesn't have special knowledge of your attribute.

It sounds like you should just be able to use CallerMemberName though, rather than having your own attribute at all...

people

See more on this question at Stackoverflow