I know that attributes are not supported inside the method body but i wanted to know maybe someone has work around this. What i am interested in is a technique that allows you to enter custom Attribute inside the method body and onto an two things.
- Class Intensiation (Creating Objects
Foo foo = new Foo()) - When that object calls specific function (
foo.bar())
later on I plan to use the metadata of the entered attributes using reflection. I came along a group of people that actually calims that they have extented c# to do so but because of no downloadable I am unable to verify it.
Here is the link to their research paper
Freely Annotating c#
Please advise me the solution
UPDATE
further with reflection I already know the name of class Foo and its method bar.
what the purpose of this is to know that foo called bar() in some method.
for Example
static void Main()
{
[p1inst]
ConcretePrototype1 p1 = new ConcretePrototype1("I");
[p1call]
ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();
Console.WriteLine("Cloned: {0}", c1.Id);
// Wait for user
Console.Read();
}
above is example that illustrate the outcome. At present it can not be done because compiler gives error. but the authors of above mentioned research paper have claimed that they have done this to allow attributes inside the method body
The whole point is to identify that in some method an object of type FOO exists and that object has called bar() or not
I think you are on the wrong track. You can’t have attributes inside a method. You either didn’t read the paper entirely or missed some points.
It speaks of a source-to-source compiler that just translates
into this C# code:
So when the method
Begin(1)is called on theAnnotationclass, it will just lookup the method attribute withASCIndex=1.To solve your actual problem, you should look into the StackTrace class.
Example:
Output: