In the Resharper API, JetBrains.Resharper.Psi.Csharp.Tree.AddAttributeBefore
takes an IAttribute param
, and an IAttribute anchor
. How are these arguments different, and how can they be constructed?
Asked
Active
Viewed 115 times
0

Matthew Piziak
- 3,430
- 4
- 35
- 49
2 Answers
3
Have a peek at the working with XML document inside it shows use of the AddAttributeBefore
call the first is the attribute you wish to insert. The second one is a attribute that already exists that you wish to insert before. If the second attribute is NULL
the new attribute is inserted after the last attribute.

John Mitchell
- 9,653
- 9
- 57
- 91
-
What if I want to convert a string into a simple attribute in front of a C♯ method, *e.g.* `[Obsolete]`? – Matthew Piziak Jul 10 '12 at 21:38
-
2@Matthew Piziak Try using myClass.AddAttributeBefore(CSharpElementFactory.GetInstance(myClass.GetPsiModule()).CreateTypeMemberDeclaration("["+yourAttribute+"] void Aaa() {}").Attributes[0], null). Didn't test it, though. – Dmitry Osinovskiy Jul 10 '12 at 21:48
2
basically, the param
is what you want to add, and anchor
is the element before which you want to add something. Keep in mind that you can, in most cases, have anchor == null
, which would cause the element to be added last.

Dmitri Nesteruk
- 23,067
- 22
- 97
- 166