Need help regarding anonymous methods

Hi,

I am creating a rule which checks for Class level variables, method level variables and method parameters. I know that for anonymous methods the nested class is generated by the compiler. But for the following anonymous method no nested class is generated but compiler creates a static method is generated

// Create a delegate instance

delegatevoidDel (int x);

// Instantiate the delegate using ananonymous method

Del d =delegate(int derive_one) {/* ... */};

The compiler creates a static method for such an anonymous method which has some compiler generated complex name and is contained in the same class as anonymous method. I m not able to differentiate between this compiler generated method and user defined method. I need help on it. If anybody has any idea about it pls let me know.

Thanks

[3548 byte] By [SyedJunaid] at [2007-12-21]
# 1

Hi Syed,

as these methods are incorrectly not marked with the GeneratedCodeAttribute, your only recourse for now is to check if the method contains the < character (as this character can not be used by user written code in C#)

We're talking to the C# compiler team to get them to decorate their generated code in the future.

Regards,

Jeffrey

JeffreyvanGogh-MSFT at 2007-9-10 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...
# 2

Hi Jeffrey

Thanks for ur suggestion. In fact I also thought of this option earlier, but the problem in checking for such methods using '<' character is:- How can we say for sure that '<' character is used by the compiler while naming only such anonymous methods. If it is used by compiler while naming some other kind of methods or class members also then it will be a trouble again for me. If u have answer pls help me out.

Thanks

Junaid

SyedJunaid at 2007-9-10 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...
# 3
Unfortunately there is no guarentee that the Compiler doesn't use the < for other compiler generated code. The real issue is that the method is not flagged with the GeneratedCodeAttribute by the compiler.
JeffreyvanGogh-MSFT at 2007-9-10 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...

Visual Studio Team System

Site Classified