This project is read-only.

insert a method with attribute?

Jan 21, 2011 at 7:38 AM


I would like to insert a method just like:


    public int add([PexAssumeUnderTest]Class1 target, int j)        


         int result = target.add(j);          

         return result;          


Is there any way to achieve this?

Jan 21, 2011 at 3:23 PM

Certainly, make a mutable copy of the assembly you want to modify, then make the new method (using the mutable metadata model), insert it in the right place and write out the assembly.

Jan 21, 2011 at 3:59 PM

Thanks for the quick responding.  If just for inserting the method, I know how to do it. however, I don't know how to add the attribute for the method and parameter.

Jan 21, 2011 at 6:08 PM

Add a new CustomAtrribute object to the Attributes collections of the method and parameter, respectively.

Jan 21, 2011 at 6:21 PM

could you give me an example?

Jan 21, 2011 at 7:53 PM

I still have some problems about how to define a new CustomAttribute, is there any sample code for that? 

Jan 24, 2011 at 2:03 AM

Have look at Normalizer.cs in the MutableMetadataModel project for examples of how custom attributes are constructed and added to a code model.