Sam Holder
Sam Holder

Reputation: 32936

How do I prevent ReSharper from prefixing built in types with an '@' symbol when generating code?

I am writing a ReSharper plugin and I want to do this:

CSharpElementFactory factory = CSharpElementFactory.GetInstance(treeNode.GetPsiModule());
factory.CreateTypeMemberDeclaration(
    "public static $0 $1 (this $2 $4) { }",
    "string",
    someMethodName, 
    someArgumentType,
    SomeArgumentName);

which I want to output the code:

public static string SomeMethodName(this SomeArgumentType someArgumentName) { }

but it actually outputs this:

public static @string SomeMethodName(this SomeArgumentType someArgumentName) { }

it seems to do this with int (and I assume other built in types or keywords).

How can I prevent it from doing this and outputting valid code?

Upvotes: 1

Views: 69

Answers (1)

Shkredov S.
Shkredov S.

Reputation: 2117

if you'd like to use keyword 'string' you can't use quotations for it. Use 'string' in the pattern (otherwise ReSharper will try to escape 'string' keyword to use in the identifier position):

public static string $0 (this $1 $2){}

If you'd like to use 'System.String' you can explicitly bind '$0' to IDeclaredType for string:

IPsiModule module;
  factory.CreateTypeMemberDeclaration("public static $0 $1 (this $2 $4){}",module.GetPredefinedType().String,someMethodName, someArgumentType,SomeArgumentName);

ReSharper should follow code style in this case and automatically replace it with 'string' when code style is set to use keywords, but I'm not sure that it will work =(

Upvotes: 1

Related Questions