c# - Method analysis using Reflection and CodeDom -


the context of question elaborate describe here , adversely affect responses not including it. want assert things method in unit test. of these things possible using reflection such format of try/finally block, class fields , method local variables, etc. know type , method signature.

    protected override void ontest ()     {         bool result = false;         somecomobject com = null; // system.__comobject          try         {         }                 {             system.runtime.interopservices.marshal.releasecomobject(com);         }          return (result);     } 

what have not been able achieve things like:

  • whether method contains single return (result); statement , whether statement last 1 in function.
  • whether variables of type system.__comobject have been manually de-referenced using system.runtime.interopservices.marshal.releasecomobject(object) in finally block.

since of these things not possible using reflection, , source code text analysis far ideal, turned codedom have not been able grip on it. have been told creating expression trees source code not possible. nor possible create expression trees runtime type. if correct, how can leverage codedom achieve things in list above?

i have used codedom in past code generation , compiling simple code classes assemblies. have no idea how used analyze internals of method. please advise.

in general, reflection built programming languages provides no access content of functions. pretty can't reflection.

you might able if have access byte-code equivalent, byte code can't answer questions syntax of method, e.g., "how many return statements exists returning same expression".

if want reason code, need reason source code. means need access parser, , other useful facts ("what declaration of x?", "is type of x , y compatible?", "does data flow x y?"), etc.

roslyn provides of information. there commercial solutions (i have one).


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -