Resharper - Disable notification for unused public methods - resharper

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.

Related

Can I make sure resharper does not change the order of the fields in this class?

I'm using this NetResource class to send files to a network drive and it looks like this:
[StructLayout(LayoutKind.Sequential)]
public class NetResource
{
public ResourceScope Scope;
public ResourceType ResourceType;
public ResourceDisplayType DisplayType;
public int Usage;
public string LocalName;
public string RemoteName;
public string Comment;
public string Provider;
}
Now it's very important that the order of these fields stay the same, as hinted on by the StructLayout attribute.
However, when someone would run a resharper cleanup, resharper decides to move the fields around and that would break the code.
Is there any way of telling rehsarper to not mess with it? I feel like if I can't do that, someone is going to eventually break the code and have no idea where to look.
But a mediocre solution to that I think would be to create a unittest that can check if there layout is as expected.
Edit: I've seen this answer, but it is outdated and requires resharper settings to be updated. I will also not be guaranteed that coworkers use this resharper setting. I'm looking for a way to add it in the code, just like you can do // ReSharper disable once InconsistentNaming
I see a couple of solutions here:
You might mark the class with NoReorderAttribute from the JetBrains.Annotations (there are several ways to add them to a project). Then ReSharper will stop reordering members inside the marked code entity.
It is mostly about already mentioned answer, I will show you how to get the same things in last ReSharper builds. All you need is to add "System.Runtime.InteropServices.StructLayoutAttribute" to "Non-reorderable types" pattern in ReSharper | Options | Code Editing | C# | File Layout.
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
To make sure your colleagues use the same settings in ReSharper, save this change to the Solution team shared layer (Save To at the bottom of the Options dialog). Then if any of your colleagues opens the solution, ReSharper will automatically use the setting from this layer with no additional actions required.

Can ReSharper insert/normalize regions like CodeMaid does?

I tried to clean up entire codebase with Resharper's "Default configuration with regions". But Resharper is not creating any new regions.
CodeMaid works great but I don't want to use both tools - CodeMaid & Resharper.
I am primarily using CodeMaid since it generates regions in below format, Resharper doesn't.
#region Public Properties
#endregion Public Properties
#region Public Methods
#endregion Public Methods
#region Private Methods
#endregion Private Methods
//...
What I am looking for is Resharper's standard configuration file that I can import and should generate regions per above format. Resharper's File Layout editor/designer is very confusing.
Can ReSharper insert/normalize regions like CodeMaid does?
Yes, it can.
And, while I personally think expanding regions like that is a nightmare, here's where you set it:)
So, basically, you create or edit a pattern where you specify the groupings, and if you want to enclose something in a region, drag it from the toolbox, and then drop stuff into it.
Be carefull not to overdo it, I've been there, and now I am rather using the 'remove regions' feature of auto cleanup.

Menu items are being enabled or disabled by default. Why?

I have some legacy code and for some reason, menu items are being enabled or disabled on launch. My question is, how? Is there any way to do this without calling the EnableMenuItem() function? Is there a way for MFC to do the opposite from what the resource settings say?
I'm also at a loss as to why the current ones are being disabled or reenabled in a SDI when the last child window has closed. This is probably due to me not understanding the framework well enough and I thought I've read through all of the docs here.
With MFC, menu items could be disabled if there is neither a ON_UPDATE_COMMAND_UI handler nor a ON_COMMAND handler for the menu item -- according to this MSDN article,
If the framework does not find an ON_UPDATE_COMMAND_UI entry during
command routing, it automatically enables the user-interface object if
there is an ON_COMMAND entry somewhere with the same command ID.
Otherwise, it disables the user-interface object
...
It is possible to disable the default disabling of user-interface objects.
For more information, see the m_bAutoMenuEnable member of class CFrameWnd in the MFC Reference
[this applies to menu-items and toolbar-items]

Determining which Visual Studio context menu was selected?

I'm writing a VS2012 add-in, adding a command to Build Explorer context menu (see related question). The command gets added to 2 different context menus:
Build Explorer
Team Explorer, Builds page, My Builds section
When my one callback is called, how do I know which of these it is?
I tried get the focused control (using P/Invoke as this question suggests). However, it gets me a Tabs container for (1), and null for (2). I could try to cast the control to the tabbed container, but that sounds pretty bad...
Any better alternative?
My new/other idea - it is similar to yours:
You should try to monitor which window was activated lastly.
If you create an eventhandler for your command, then you may be able to check which window is active when your command fired. A simple evenent handler for a command:
void cmdEvents_BeforeExecute( string guid, int ID, object customIn, object customOut, ref bool cancelDefault )
{
Window2 teamExplorer = _applicationObject.Windows.Item("Team Explorer") as Window2;
if (_applicationObject.ActiveWindow.Caption == teamExplorer.Caption)
{
//You are called from Team Explorer
}
else
{
//Somewhere else
}
}
And the way you can subscribe:
static _dispCommandEvents_BeforeExecuteEventHandler _myHandler;
static CommandEvents _cmdEvents;
public void OnConnection(...)
{
Command command = ...; // Init your command
int ID = command.ID;
string GUID = command.Guid;
CommandEvents _cmdEvents = _applicationObject.Events.get_CommandEvents(GUID, ID);
_myHandler = new _dispCommandEvents_BeforeExecuteEventHandler(cmdEvents_BeforeExecute);
_cmdEvents.BeforeExecute += _myHandler;
}
You may find a better way to identify the window(s) by GUID. You should keep at least _cmdEvents as static because when it will be desroyed, your event handler could vanish (least for internal commands).
In OnDisconnection you should unsubscribe.
Reworked by the comment, and founded links:
As the menu item is shown every place it seems there is no way to distinct between them from an Add-In, you should add two command and distinct them by their context.
The way instead of converting the Add-In to a VS-Package MZ-Tools HOWTO: Controlling the state of command in a Visual Studio add-in, try MZ-Tools HOWTO: Use the IVsMonitorSelection ... you can also get it from an Add-In.
But:
Neither the AddNamedCommand nor the QueryStatus methods honor the
invisible state: the button that must be invisible ...
remains disabled rather than invisible.
I think this makes it impossible to do it from an Add-In on a suitable way, but maybe you can check the contexts.
Other way you could get further, if you try to migrate your command/menu into a VSPackage and create a custom UIContext for the menu items or find a suitable predefined one. I have no access to a Studio enhanced with Build Explorer so I can't try it.
The following discussion is about custom contexts for vs-packages:
http://davedewinter.com/2008/04/05/dynamic-menu-commands-in-visual-studio-packages-part-3/
Sadly the links are broken from the post, and I can't reach Part 1. and Part 2. which is about the discussion of the problem from the beginning.
But there is no guarantee you can create a context which suits you.
Only context ID I found for Team Explorer is the guidTeamProjectCmdUIContext.
It is placed at vsshilds.h in Visual Studio 2010 SDK, vsshell*.h are also contain several others.
MSDN: Vsct files to define command, menus, ect. from packages.
Condition attribute for items:
http://msdn.microsoft.com/en-us/library/bb491718.aspx
http://msdn.microsoft.com/en-us/library/bb166515.aspx
MSDN: VisibilityItem element for commands and toolbars.
VisibilityItem element determines the static visibility of commands and toolbars.
... After the VSPackage is loaded, Visual Studio expects command visibility to be determined by the VSPackage rather than the VisibilityItem.
And finally about predefined Context Guids:
http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.uicontextguids80.aspx
http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.uicontextguids.aspx

how to disable UITextTapRecognizer on a UITextView

I want to try to disable the UITextTapRecognizer, which I think is a built in property of the UITextView, as I suspect it is interfering with a tap gesture recognizer that I want to implement. How is it possible to do this?
Thanks for reading!
I'm not sure this answers your question directly (i.e. "disable the UITextTapRecognizer"), but I think it might help. You can prevent that tapRecognizer from recognizing gestures, thereby basically "disabling" it (I think).
"You can prevent gesture recognizers from looking at specific touches
or from even recognizing a gesture. You can specify these “prevention”
relationships using either delegation methods or overriding methods
declared by the UIGestureRecognizer class.
The UIGestureRecognizerDelegate protocol declares two optional methods
that prevent specific gesture recognizers from recognizing gestures on
a case-by-case basis."
Try the gestureRecognizerShouldBegin: or gestureRecognizer:shouldReceiveTouch: delegate protocol methods.
"In addition, there are two UIGestureRecognizer methods (declared in
UIGestureRecognizerSubclass.h) that effect the same behavior as these
delegation methods. A subclass can override these methods to define
class-wide prevention rules."
look at:
- (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer *)preventedGestureRecognizer;
- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)preventingGestureRecognizer;
source: Apple docs (event handling guide for iOS)
I hope it helps!

Resources