Page Comparison - 3.2 Creating Code Elements (v.2 vs v.5)

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

  • One element needs to be replaced by another. This is typically achieved by either calling the ReplaceBy() method on the element to be replaced or, if this method is not available, by physically removing one element and adding another.
  • An element needs to be inserted as a child of another element. In this case, there is typically a method in the API for doing exactly that.

The Element Factory

The Element Factory is a class which is used to manufacture all types of entities, be it statements or whole declarations. The element factory is created via a GetInstance() method, which is supplied the corresponding PsiModule:

...

You're probably curious to know what the second parameter is. Essentially, the second parameter is an array o of object}}s which act in a similar way to the way the {{args parameters act in a string.Format() call.

...

Code Block
languagecsharp
int @event = 0;

The Type Factory

Creating types is an important task in the ReSharper ecosystem. For example, say you wanted to write a context action to implement change notification in a class. This would require you to create, say, an INotifyPropertyChanged interface type.

...

Please note that if you want to use the type to create, e.g., statements with the $ notation, you cannot simply use the parameter of IDeclaredType - you need to call GetTypeElement() on it. For more information on the ReSharper type systems, please see 3.1 Type System.