Attribute property

14 views
Skip to first unread message

Egor Nazarov

unread,
Jan 21, 2017, 8:43:32 AM1/21/17
to resharper-plugins
Hello everyone,
I'm writing my first plugin and I'm a bit confused with the absence of good reference. Could someone please give me an idea how to do the next thing:

Given that I have a method marked with [Test] attribute and I got the IAttribute instance of this attribute, how should I write the PsiTransormation to replace it with 

[Test(Description = "some text")]?

Thanks in advance.

Egor Nazarov

unread,
Jan 22, 2017, 6:53:43 AM1/22/17
to resharper-plugins

Matt Ellis

unread,
Jan 23, 2017, 1:01:26 PM1/23/17
to resharper-plugins
Hi Egor. This looks like it will do the job just fine. You could also use IAttribute.AddPropertyAssignmentBefore/After with a value from CSharpElementFactory.CreatePropertyAssignment and CSharpElementFactory.CreateStringLiteralExpression.

The only feedback I'd give is to generally avoid using something like typeof(TestAttribute) in GetTypeElementByCLRName. While it's fine here, it's only because the ReSharper SDK ships nunit.framework.dll that it's available. For other types, you'll have to use the full name by string - "NUnit.Framework.TestAttribute".

Regards
Matt

Egor Nazarov

unread,
Jan 24, 2017, 5:34:54 AM1/24/17
to resharper-plugins
Thaks Matt.
Reply all
Reply to author
Forward
0 new messages