The API you need is located in JetBrains.ReSharper.Psi.dll (PSI - is abbreviation
from Program Structure Interface).
First of all you need to fetch an object representing a class (IClass) and
explore its fields (IField's).
Create an action (see openapi use samples in the installation) and fetch
IClass aClass = context.GetData(DataConstants.DECLARED_ELEMENT) as IClass;
Then (when aClass is not null) fetch its fields:
IField fields = aClass.Fields;
To generate the method use:
ICSharpElementFactory factory = aClass.GetManager().GetElementFactory();
IMethodDeclaration methodDecl = (IMethodDeclaration)factory.CreateTypeMemberDeclaration(text);
This creates a method declaration which is not located in any class. To insert
the declaration you need fetch a declaration of the class.
To fetch declarations of the class:
IDeclaration declarations = aClass.GetDeclarations();
There can be multiple declarations in case of partial class. You have to
choose one to generate method into. This adds some complexity, so let's skip
it for first iteration (choose the first declaration).
NOTE: never assume that array of declarations is non-empty. Fetching declarations
can fail by a number of reasons. Just handle this case gracefully by exiting
Check that the declaration is C# class declaration:
JetBrains.ReSharper.Psi.CSharp.IClassDeclaration classDecl = declarations
And now insert method:
methodDecl = (IMethodDeclaration)classDecl.AddClassMemberDeclaration(methodDecl);
And reformat it according to code style settings:
ICodeFormatter formatter = CodeFormatterProvider.GetInstance (solution).GetFormatter
Chief Scientist, Vice President of Product Development
"Develop with pleasure!"
I can't find anything on using the API... can you get me started, or
point me where I need to go?
I'd like to use the Resharper API to build GetObjectData() methods
automatically for any specified classes that implement ISerializable.
I'd like to show a field selector, displaying all the fields of the
class, allow me to check these off, and then create the method with al
lthe info.AddValue calls for the selected fields.
info.AddValue ("fieldName", fieldName);
Also, creating the Serializable COnstructor, doing the same in
fieldName = info.GetInt ("fieldName");
Any help would be greatly appreciated.