locked
Checking code through fxcop RRS feed

  • Question

  • Hi,

    I am new in fxcop.I want to write my own custom rule.But my question is can I fetch and check the actual code from fxcop rule.eg-

    if my code is something like

    using System.Data;

    using System.Text;

    class test()

    {

    int i=0;

    }

    then

    can i get the value of line 5 that is int i=0 by any way.

    like method.Instructions[5].values.toString() = "int i=0"

    means I want to get the actual code and on the basis of that I want to write my logic.

    is it possible in fxcop

    Tuesday, September 6, 2011 2:00 PM

Answers

  • FxCop allows you to inspect the IL that was generated for your method, or to inspect a tree structure of "Nodes" that represent your compiled code.

    for example, int i = 0, results in a Local in the list of locals, and an AssignmentExpression with a Literal source and a Local as target. It's somethimes a little hard to wrap your head around, but once you have it, it's usually quite simple as long as you stay inside the same class or method.

    If you want to inspect sourcecode, check out StyleCop, which works on a source level.

    • Marked as answer by eryang Thursday, September 15, 2011 7:43 AM
    Wednesday, September 7, 2011 7:00 AM

All replies

  • FxCop allows you to inspect the IL that was generated for your method, or to inspect a tree structure of "Nodes" that represent your compiled code.

    for example, int i = 0, results in a Local in the list of locals, and an AssignmentExpression with a Literal source and a Local as target. It's somethimes a little hard to wrap your head around, but once you have it, it's usually quite simple as long as you stay inside the same class or method.

    If you want to inspect sourcecode, check out StyleCop, which works on a source level.

    • Marked as answer by eryang Thursday, September 15, 2011 7:43 AM
    Wednesday, September 7, 2011 7:00 AM
  • We temporarily mark a reply since the thread idle for a long time, please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 15, 2011 7:43 AM