Two code style for private/puublic property

How I can config code stile. I have two value (Property) and on public property I need first later big and on private first later start from "_"
What rules I need prepare in code stile?

Не как не могу настроить Code Style под C# так чтобы приватная публичная начиналась с большой буквы а вот  приватная с подчеркиванием.

public string Bbbbb { get; set; }
private string _aaaaa { get; set; }
0
1 comment

Hello Viktor,

Thank you for contacting Rider support.

This is a known problem and we have the following open issue on our tracker:

We would appreciate it if you could upvote it to demonstrate your interest. 

For the public properties, you can edit the C# | Naming Rules | Properties options in Rider settings.
Creating a rule for private property is not possible through Rider UI, but it can be done by editing the .DotSettings file or via ReSharper.

There are three options where you can put your custom rule: (see the Layer Settings article in Rider documentation)

  • This computer layer: %APPDATA%\JetBrains\Rider2023.2\resharper-host\GlobalSettingsStorage.DotSettings; (this file just exists, you can find it and paste (read below) an entry there)
  • Solution Team-shared layer: <SolutionName>.sln.DotSettings;
  • Solution Personal layer: <SolutionName>.sln.DotSettings.user;

You can generate .DotSettings file corresponding to Team-shared or Personal layers by pressing Save | Solution {} {layer} (see the screenshot attached). It would be saved next to your .sln file.

The .DotSettings has the following structure:

<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
{appropriate ReSharper Settings}
</wpf:ResourceDictionary>

To add naming rule for private properties, you would need to add the following entry between <wpf ...> </wpf> tags in desired .DotSettings file

    <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=ce122e9a_002Dc91f_002D46a2_002Dae9b_002D3caa742a3b24/@EntryIndexedValue"><Policy><Descriptor Staticness="Static, Instance" AccessRightKinds="Private" Description="Private properties"><ElementKinds><Kind Name="PROPERTY" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /></Policy></s:String>

If you have Visual Studio with ReSharper, you can configure these settings by yourself and:

  • sync ReSharper settings with Rider;
  • or save configured settings to Personal or Team-Shared solution layer right from ReSharper (save in a similar way); (Rider and ReSharper both use the same .DotSettings settings file)

You can also describe the exact naming rules to me, so that I can share the exact entries you should paste into your .DotSettings file.

Hope that helps.

If there is anything else I can assist you with or you have any other questions or difficulties, please let me know.
Have a nice day!

0

Please sign in to leave a comment.