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

73 Views Asked by At

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?

1

There are 1 best solutions below

1
On

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 =(