Which setting tells Resharper (with StyleCop) to not align ASP.Net controller attributes on one line? - resharper

Example code:
[AllowAnonymous] [HttpPost("Register")] public async Task<IActionResult> Register(RegisterParameters parameters)
How it should look like:
[AllowAnonymous]
[HttpPost("Register")]
public async Task<IActionResult> Register(RegisterParameters parameters)
Which setting tells Resharper (with StyleCop) to not align ASP.Net controller attributes on one line, but on multiple? I didn't find the setting yet.

It's called "Place method attribute on the same line". But it works only if you have another setting called "Keep existing arrangement of attributes" turned OFF.

Additional Information to Dmitry Osinovskiy's answer:
"Place method attribute on the same line" can be found under "C#" → "Formatting Style" → "Line Breaks and Wrapping" → "Arrangement of Attributes" and needs to be set to "Never":
"Keep existing arrangement of attributes" can be found under "C#" → "Formatting Style" → "Line Breaks and Wrapping" → "Arrangement of Attributes" and needs to be set to "Off" (No tick):

Related

Resharper - Disable notification for unused public methods

Resharper 2016.1 is notify unused public methods. Is there a way to disable this notifications global? I want only disable notification of unused public methods. Unused private methods should be notified nevertheless.
You'll need to turn off Solution Wide Analysis (ReSharper → Options → Code Inspection Settings). This will disable a number of inspections, but also disable marking public methods as being unused. Alternatively, you can use ReSharper's annotations, and add an attribute such as [PublicAPI] to the public methods that are used externally.
Private methods will remain marked as unused, because that only requires ReSharper to analyse a single class, rather than the whole solution.
I have resharper 2018.1. I don't know if this is version specific but in addition to #citizenmatt's answer you also need to make sure that "Show non-private type members when solution-wide analysis is off" is unchecked on the same options page. You could search for 'solution wide' in top left search of resharper options to quickly get on that page as per the image below.

How do you set the File Layout to put [ClassInitialize] and [ClassCleanup] at the top of the file using Resharper 9?

How do you set the File Layout to put the MsTest [ClassInitialize] and [ClassCleanup] methods at the top of the file using Resharper 9?
With the default set-up for R#, the methods are just alpha sorted with the other test methods
I appreciate that I can amend the "All other members" from sort by Name, to sort first by Static and then by Name, but this seems like a quick hack
You can edit the file layout rules that ReSharper uses for reordering file content by code cleanup, by going to ReSharper → Options → Code Editing → C# → File Layout.
Full details are available in the web help, but the idea is to create a pattern very similar to the default "NUnit Test Fixtures" pattern, but for MSTest. In fact, this is a nice idea for a default pattern, so I've added a feature suggestion you can track or vote: RSRP-446275
Essentially, you want to do what the default NUnit Test Fixtures rule does.Create a new "type pattern" and add it between "NUnit Test Fixtures" and "Default Pattern". Double click to edit the pattern, and switch to constraints view by clicking the cog in the top right. Here you can say it has to be of Kind "Class" And "Has attribute" Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute.
Switch back to Composition (rules) view, and add an "Entry" from the Toolbox. Give it a name, such as "Setup/Teardown Methods", and double click on it. This should be set up the same as NUnit's - And (Kind=Method, Or (Has attribute=Microsoft...ClassInitializeAttribute, Has attribute=Microsoft...ClassCleanup)).
The NUnit pattern defines another couple of entries - an empty one for "All other members" and one for "Test methods", which is kind=method and has attribute=Test. Something similar could be done for mutest's TestMethod attribute.

MS Visual Studio 2013 MFC Application: Create a text box for messaging / output service

Using MS VC, I've created a "Dialog based" MFC Application. Let's call it MyApp1. I simply want to add some kind of "box" to my dialog to display text. I tried to add an "Edit Control" and then printing to it via
var_set.SetCueBanner(_T("Test"), TRUE);
var_set is the variable of the Edit Control CEdit. This code is added in a function that is called when pressing a button in the dialog. E.g.
void MyApp1Dlg::OnBnClickedButton1()
{
var_set.SetCueBanner(_T("Test"), TRUE);
}
However, I think this is at least not the way an "Edit Control" should be used... So I tried with a "Static Text". To control it, I read to use
HWND hwndText = GetDlgItem(dlg, IDC_STATIC);
SetWindowText(hwndText, L"Test");
But I would have to use the ID of the dialog dlg which is not defined in MyApp1Dlg.cpp file. I found it in the MyApp1.cpp. Should I export that instance to MyApp1Dlg.cpp or is there another way to display text in my dialog? In the final application, I'd like to use it similar to a
printf("output: %g\n", xx);
command. Thanks for hints.
The SetCueBanner function is for setting a prompt into the edit control. If you want to set the actual text, use SetWindowText - it's part of the parent class CWnd so you would not find it in the CEdit documentation. This works for both edit and static controls, although a static control might also need a RedrawWindow before it shows the new text.
var_set.SetWindowText(_T("Test"));
OK, I got an answer:
First, define an "Edit Control" box. Let's call the ID IDC_EDIT1. Next, in one of the MyApp1Dlg.cpp functions, insert
CString str;
str.Format(_T("%d x %d"), .5, .4);
SetDlgItemText(IDC_EDIT1, str);
and mark the property "Read only" to True.

How to automatically generate getters and setters in Android Studio

Is there a shortcut in Android Studio for automatically generating the getters and setters in a given class?
Using Alt+ Insert for Windows or Command+ N for Mac in the editor, you may easily generate getter and setter methods for any fields of your class. This has the same effect as using the Menu Bar -> Code -> Generate...
and then using shift or control button, select all the variables you need to add getters and setters
for macOS, ⌘+N by default.
Right-click and choose "Generate..." to see current mapping. You can select multiple fields for which to generate getters/setters with one step.
See http://www.jetbrains.com/idea/webhelp/generating-getters-and-setters.html
Android Studio & OSx :
Press cmd+n > Generate > Getter and Setter
Android Studio & Windows :
Press Alt + Insert > Generate > Getter and Setter
create the variable
right click
select "Generate" and then select "Getter and Setter" option
Android Studio & Windows :
fn + alt + insert
You can generate getter and setter by following steps:
Declare variables first.
click on ALT+Insert on keyboard placing cursor down to variable declaration part
now select constructor and press Ctrl+A on keyboard and click on Enter to create constructor.
Now again placing cursor at next line of constructor closing brace , click ALT+INSERT and select getter and setter and again press CTRL+A to select all variables and hit Enter.
That's it. Happy coding!!
Position the cursor under the variables -> right-click -> Generate -> Getter and Setter -> Choose the variables to make the get and set
or
Alt + Insert -> Getter and Setter -> Choose the variables
As noted here, you can also customise the getter/setter generation to take prefixes and suffixes (e.g. m for instance variables) into account. Go to File->Settings and expand Code Style, select Java, and add your prefixes/suffixes under the Code Generation tab.
Using Alt+ Insert or Right-click and choose "Generate..."
You may easily generate getter and setter or Override methods in Android Studio.
This has the same effect as using the Menu Bar Code -> Generate...
This answer deals with your question but is not exactly an answer to it. =) It's an interesting library I found out recently and I want to share with you.
Project Lombok can generate common methods, such as getters, setters, equals() and hashCode(), toString(), for your classes automatically. It replaces them with annotations reducing boilerplate code. To see a good example of code written using Lombok watch a video on the main page or read this article.
Android development with Lombok is easy and won't make your android application any 'heavier' because Lombok is a compile-time only library. It is important to configure your Android project properly.
Another example:
import lombok.Getter;
import lombok.Setter;
public class Profile {
#Getter #Setter
private String username;
#Getter #Setter
private String password;
}
Android development with Lombok is possible. Lombok should be a compile-time only dependency, as otherwise the entirety of Lombok will end up in your DEX files, wasting precious space. Gradle snippet:
dependencies {
compileOnly "org.projectlombok:lombok:1.16.18"
}
In addition you may want to add the Lombok IntelliJ plugin to support Lombok features in your IDE at development time. Also there is Hrisey library which is based on Lombok. Simply put, it's Lombok + Parcellable support.
You can use AndroidAccessors Plugin of Android Studio to generate getter and setter without m as prefix to methods
Ex: mId;
Will generate getId() and setId() instead of getmId() and setmId()
Use Ctrl+Enter on Mac to get list of options to generate setter, getter, constructor etc
use code=>generate=>getter() and setter() dialog ,select all the variables ,generate all the getter(),setter() methods at one time.
Another funny way
Type the parameter name anywhere in the object after definition, you will see setter and getter, Just select and click enter :)
I tried with Android Studio 2.3
Right click on Editor then Select Source -> Generate Getters and Setters or press Alt + Shift + S
Just in case someone is working with Eclipse
Windows 8.1 OS | Eclipse Idle Luna
Declare top level variable private String username Eclipse kindly generate a warning on the left of your screen click that warning and couple of suggestions show up, then select generate.

Apply a context action to an entire file

Is there any way to make Resharper apply a context action at every applicable site in a file?
In particular, in order to comply with coding standards, I wish to apply 'Specify type explicitly' to every 'var' declaration across a number of files.
In general, you can't apply a context action in multiple code positions.
However, in the case of specifying type explicitly, you can use Code Cleanup to batch-apply this.
Choose "ReSharper > Tools > Clean up code"
Click "Edit Profiles"
Click "Add" to create a new cleanup profile and specify a name for it (say, "goodbye var").
In the list of profile settings, clear all check boxes to prevent unwanted code style changes.
Under C# > Use 'var' in declaration, select "Do not change" for "Replace direction", and "Always use explicit type" in the other two drop-downs.
Click "OK".
Choose "ReSharper > Tools > Clean up code" once more, choose the "goodbye var" profile, and click "Run".
Note that you can invoke code cleanup in different scopes: step 7 above implies that you're calling it in the scope of the currently opened file. However, you can choose a wider scope (folder, project, solution) in the Solution Explorer and invoke Code Cleanup from there.

Resources