C++/CLI Support
C++/CLI is a set of C++ language extensions by Microsoft designed for easy interoperability between managed and native code. It includes generics, value and ref classes, handles, tracking references, interfaces, and other syntactic additions.
Besides the main set of code analysis, navigation and search, coding assistance, and other features you’re used to with C++, JetBrains Rider provides additional support for C++/CLI-specific cases.
Search and navigation
Since C++/CLI is a bridge between the languages, JetBrains Rider provides cross-language navigation features to improve interoperability:
Find Usages and Go To Declaration work between C++/CLI and C#.
When looking for derived symbols from C++/CLI code, JetBrains Rider will find symbols in C# code in addition to symbols in C++/CLI.
Go to Base Symbols and Go to Derived Symbols work on imported CLR entities.
Go to Derived Symbols also works for get
/ set
functions inside C++/CLI properties and add
/ remove
functions inside C++/CLI events.
Code analysis
JetBrains Rider includes a set of inspections for C++/CLI-specific language constructions:
You’ll get a warning if there is missing
virtual
specifier for an interface member, or it does not havepublic
accessibility.JetBrains Rider inspects the way you allocate memory and suggests a quick-fix to replace
gcnew
withnew
when the target type is not valid. It also works for replacingnew
withgcnew
.JetBrains Rider warns you when you try to use the C++
final
specifier on a managed class or interface, with a quick-fix to make itsealed
instead.
There are also a few helpful quick-fixes for C++/CLI. For example, the safe_cast
operator in C++/CLI is especially useful when downcasting from a base class to a derived one: safe_cast
performs a dynamic check and throws InvalidCastException
if the conversion fails. You can use a quick-fix to convert a C-style cast to a safe_cast
.
Inlay hints
In addition to parameter name and type name hints, JetBrains Rider provides type conversion hints for C++/CLI boxing conversions, which result in an allocation on the managed heap. Such hints for standard conversions are disabled by default, but you can enable them on the page of JetBrains Rider settings Ctrl+Alt+S.
Formatting style
Additional formatting settings allow you to configure style for C++/CLI generic constraints: select the preferred indentation, add spaces where needed, and force line breaks (
).Postfix completion
Some C++ postfix templates are specially designed to produce C++/CLI code when invoked in its context.
Use
.gcnew
to produce instantiation expression for a type.Use
.safe_cast
to surround expression with.safe_cast
.