After I add a field I was able to press Ctrl + Enter and choose Initialize field from constructor. It added an argument to existing ctor or created a new ctor with that argument if it was not declared.
I wonder if this is just new version Resharper 2017.1 or old version of VS 2013?
I have it working on VS 2015 & Resharper 2016.3. But it doesn't appear when I press Ctrl + Enter in VS 2013 & Resharper 2017.1.
ReSharper 2017.1 Help states the following:
Generating Type Constructors
ReSharper | Edit | Generate Code | Constructor
Alt+Insert | Constructor
ReSharper_GenerateConstructor
The constructor generation wizard creates a non-default constructor that takes parameters for selected fields , properties and auto-properties .
All generated constructors follow the same pattern where:
Each field , property, or auto-property included in the constructor is initialized with a parameter.
The name of the parameter is derived from the name of the corresponding field or property .
If there are non-default base type constructors, the required parameters are added to the generated constructor and passed to the base class constructor.
Tip You can quickly generate constructors by typing ctor (without parameters), ctorf (with parameters that initialize all fields) or ctorp (with parameters that initialize all properties).
Tip You can set up common code generation options on the Code Editing | Members Generation page of ReSharper options.
I found another refactoring bulb (Quick actions menu Ctrl+.) (at least in new version of resharper for VS 2022) that have a menu "Add parameter to XXX.ctor"
Related
I am trying to configure the UiPath get queue items activity but when I specify the QueueItemData variable as the output it gives a warning asking for a generic IEnumerable object.
What is the proper UiPath queue object to use when a IRnumerable object is required?
You can simply use IEnumerable<UiPath.Core.QueueItem> as type for your variable. A simple way to create a suitable variable is to hit CTRL+K in an appropriate property field, like this:
Studio will then automatically add the variable after hitting Enter. You may need to change the scope manually.
You will want to use IEnumerable<UiPath.Core.QueueItem>.
Essentially, you can read that as this is an iterable collection that contains nothing but UiPath.Core.QueueItem objects.
Beware of Imposters
Be careful when you choose the generic type associated with the IEnumerable class though. There are many similarly named classes that can cause confusion, and if you choose the wrong one you'll end up with an error about being unable to case between one and the other.
Automatic Type Setting
When in doubt, allow the UiPath Studio tool to set the type for you. Just move the cursor into the input window for the field in question in the Properties tab and type set var: items. UiPath Studio will then register the variable and set the object type to the appropriate class. This takes the guess work out of figuring out which type to use.
I'm now using Visual Studio 2015 with Update 1 to debug an app. I customized the collectionplan.xml according to this article http://blog.qetza.net/en/2010/03/08/vs-2010-personnalisation-des-vnements-de-lintellitrace/ to trace my own code. When I want to trace a function inside a nested private class, that event doesn't show up in the diagnostic window.
I tried to change the TypeName tag to <full qualified outer class id>/<nested class name> which is found from the IL, but failed.
Is it impossible or I misspelled the the TypeName?
Finally, I got the answer by running GetType().AssemblyQualifiedName. The seperator should be +. So, if you want to trace a function inside a nested private class, here is an example:
<TypeName>Namespace.OuterClassName+NestedClassName</TypeName>
<MethodName>YourMethodName</MethodName>
<MethodId>Namespace.OuterClassName+NestedClassName.YourMethodName(...):ReturnType</MethodId>
I've tried in VS2015 with Update 1 on a nested private class. And, it works.
Hope my answer can help someone who happens to find this question.
I'm using Visual Studio 2010, project is in VB.NET, and I have ReSharper 7.1
It is falsely reporting errors not just warnings or suggestions.
lblAccountID.Text = AccountID.ToString()
ReSharper is giving me an error on the ToString, telling me "Incorrect number of arguments."
AccountID's Type is a custom class we have created, and it has ToString overloads that accept 0 parameters, or 1 parameter as DisplayFormat, or 1 parameter as another custom class we made that's another type of a displayformat. For some reason ReSharper is only seeing the 2 overloads that accept 1 parameter and it thinks the overload that accepts 0 parameters does not exist. I am calling ToString on this type of object in 13 different places so it is reporting 13 different errors but the code compiles and runs perfectly fine. There is no error, and it does not give me the option to ignore it.
Is there a way I can turn this off? I really don't need ReSharper telling me about these kinds of errors int he first place because if they truly exist Visual Studio will tell me about them itself.
Edit
I figured out how to recreate this issue, but it's an odd one. Just a bug in ReSharper, I guess. I reported it in their issue tracker.
This is the simplest way to recreate it. Inside of 1 project (ClassLibrary1):
Public Class Class1
Public Overridable Overloads Function ToString(i As Integer) As String
Return "Class1 - " & i.ToString()
End Function
Public Overloads Function ToString(s As String) As String
Return "Class1 - " & s
End Function
End Class
Public Class Class2
Inherits Class1
Public Overrides Function ToString(i As Integer) As String
Return "Class2 - " & i.ToString()
End Function
Public Overloads Function ToString(f As Boolean) As String
Return "Class2 - " & f.ToString()
End Function
End Class
Then in a new project in a new solution (cannot recreate error when both projects are in the same solution), add a reference to the DLL created from the 1st project.
Dim o As New Class2
Dim s As String = o.ToString()
s = o.ToString(s)
Both of these ToString methods are defined in Class2's base class, or the base class's base class, and ReSharper can't seem to find them, thinks they don't exist, and marks it as compile error even though it builds and runs perfectly fine.
From within Visual Studio, if you navigate to ReSharper->Options and then select Inspection Severity under Code Inspection you should be able to turn off the warning by selecting "Do not show" to the right of the item. See the screenshot below. Having said that, I wasn't able to locate the specific error mentioned in the question text, hopefully you will have better luck.
I'm working on a custom Visual Studio language service, and have several questions regarding the way file extensions are bound to a particular language service.
Source files for the language "Example Language" has two primary file extensions: .e1 and .e2. My extension has a class ExampleLanguagePackage which extends Package.
When you use the File → Open command and select a C# file (for example), the "Open" button has a dropdown arrow which allows you to select "Open With...". When you click that button, you are presented with options to open the file in the "CSharp Editor (Default)", "CSharp Editor with Encoding", or any of several other options. How can I provide a similar feature for my language, offering "Example Language (Default)" and "Example Language with Encoding" options?
When you open Tools → Options... → Text Editor → File Extension, you have the ability to bind (for example) the .foo extension to "Microsoft Visual C#" or any of several other options. How can I extend this page to allow user-defined file extensions to be associated with the "Example Language"?
What else should I watch out for when registering these items?
Most of these items are addressed by adding a custom implementation of IVsEditorFactory for your language and using a combination of registration attributes to register it. The actual implementation of this interface is beyond the scope of this question, but the documentation for the interface itself (and linked to that page), along with an example DjangoEditorFactory implementation in the Python Tools for Visual Studio project helped me with my initial implementation.
To support the Example language, I will make the following assumptions.
You've implemented an abstract class ExampleEditorFactory which provides the core implementation of IVsEditorFactory. The class should have a protected constructor with a bool argument to specify whether the factory should prompt the user for an encoding (similar to one of the constructors of the DjangoEditorFactory).
You have a class ExampleEditorFactoryWithoutEncoding which extends ExampleEditorFactory and constructs the base class specifying false for the promptForEncoding argument. This class should be marked with the [Guid] attribute.
You have a class ExampleEditorFactoryWithEncoding which extends ExampleEditorFactory and constructs the base class specifying true for the promptForEncoding argument. This class should be marked with the [Guid] attribute.
You have added the following entries to your VSPackage.resx resources file. The constants can be changed, but be aware that I have used the constant values 101 and 102 below.
101 = Example Language
102 = Example Language with Encoding
Registering the editor factories
The first thing to do is register your editor factories. This is done in two parts.
First, use the ProvideEditorFactoryAttribute. This attribute associates a resource identifier for the display name of the factory with the factory type itself.
[ProvideEditorFactory(typeof(ExampleEditorFactoryWithoutEncoding), 101)]
[ProvideEditorFactory(typeof(ExampleEditorFactoryWithEncoding), 102)]
Next, in the Initialize method of ExampleLanguagePackage, add calls to RegisterEditorFactory after you call base.Initialize().
protected override void Initialize()
{
base.Initialize();
RegisterEditorFactory(new ExampleEditorFactoryWithoutEncoding(this));
RegisterEditorFactory(new ExampleEditorFactoryWithEncoding(this));
}
Associate a logical view with the editor factories
I haven't found all the information I wanted about the use cases for the ProvideEditorLogicalViewAttribute attribute, but it's important to include at least the following. Make sure to register the logical view(s) with both factories you created.
[ProvideEditorLogicalView(typeof(ExampleEditorFactoryWithoutEncoding), VSConstants.LOGVIEWID.TextView_string)]
[ProvideEditorLogicalView(typeof(ExampleEditorFactoryWithEncoding), VSConstants.LOGVIEWID.TextView_string)]
If this step is not done, the feature where double clicking in the output window can take you to a line of code will not work as expected. For example, suppose the output window contained a line like the following.
c:\dev\file.e1(14,3): unexpected expression
Associating the TextView logical view allows the IDE to use your factory when you double click on this output line to take you to line 14, column 3 of the file c:\dev\file.e1. Otherwise it will use a different factory to open a new copy of your document, and the new window will likely be missing many features.
Associate the standard file extensions .e1 and .e2 with the editor factories
This step provides the "Open With..." support for .e1 and .e2 files described in the original question 1. This step is accomplished with the ProvideEditorExtensionAttribute attribute.
The default priority for the primary factory appears to be 50. The factory with explicit encoding should have a priority less than this, and 49 appears to be a good choice. Note that there is no need to specify the NameResourceID named parameter because it was already specified by the ProvideEditorFactoryAttribute usage above (the generated registry keys are identical).
[ProvideEditorExtension(typeof(ExampleEditorFactoryWithoutEncoding), ".e1", 50)]
[ProvideEditorExtension(typeof(ExampleEditorFactoryWithoutEncoding), ".e2", 50)]
[ProvideEditorExtension(typeof(ExampleEditorFactoryWithEncoding), ".e1", 49)]
[ProvideEditorExtension(typeof(ExampleEditorFactoryWithEncoding), ".e2", 49)]
Associate the .* extension with the editor factories
This step provides the "Open With..." support for all other files, and adds support for the File Extension options described in the original question 2. This step also uses the ProvideEditorExtensionAttribute attribute, but uses a much lower priority value to ensure the default editors for other file types are not overridden by the setting. Like in the previous step, the factory with explicit encoding is given a lower priority.
[ProvideEditorExtension(typeof(ExampleEditorFactoryWithoutEncoding), ".*", 2)]
[ProvideEditorExtension(typeof(ExampleEditorFactoryWithEncoding), ".*", 1)]
Final notes
This answer does not cover several details.
(High importance for Visual Studio 2012) If you are planning to support Visual Studio 2012, please see the topic Cannot get custom editor to use the provisional tab for details on the new (and otherwise poorly documented) property ProvideEditorFactoryAttribute.CommonPhysicalViewAttributes.
(Unknown importance) The ProvideEditorFactoryAttribute does not support specifying the LinkedEditorGUID value (search down the page). This value would normally be added to the registration of ExampleEditorFactoryWithEncoding, and the value would be the GUID of ExampleEditorFactoryWithoutEncoding.
The default type generation in Entity Framework 3.5/4.0 emits each of the types in "Xxxx.designer.cs" source files (where "Xxxx" is the name of the type being generated). This then allowed for the developer to generate his own "Xxxx.cs" source files where further implementation could take place, or attributes could be added to Metadata classes etc.
The more recent T4 templates that have been made available (POCO, Self Tracking etc.), including the default type generation in VS2012, all genrate "Xxxx.cs" themselves without the ".designer" suffix.
I know that it is easy enough to override the behaviour of the T4 templates to emit the ".designer" within the file names, but am I missing something here where we are actually being discouraged to extend these classes through the partial definitions?
In a recent project where I generated Self Tracking Entities, I found that I had to rename the emitted files so that I could extend the definitions with Metadata class attributes as well as overrides of .Equals(object) and .GetHashcode() (otherwise EF could not detect duplicates properly) for example.
Is there something that I have missed where we are now expected to leave the emitted partial classes as they are or is this merely an oversight and are most of you also having to rename source files being emitted?
Code generation strategy has changed in VS2012. Before the code that was generated was using EntityObject based entities and a context class derived from the ObjectContext class. VS2012 by default generates POCO entities and DbContext dervied context. If you still want ObjectContext based context and EntityObject based entities you need to:
Right-click on the designer surface and select properties
Change the "Code Generation Strategy" from "None" to "Default"
Remove .tt files from your solution to avoid having both contexts and duplicate entities.