Is there a way to create an auto property via code snippet using ReSharper? Like the prop for VS?
Resharper 5 has a prop snippet which goes to auto-property. Does 4.5 not?
You can create a Live Template
Just go to the Resharper menu, and choos Live Templates. Click the little green + icon and add this:
public $type$ $name$ { get; set; }
Then give the wanted shortcut, and you are good to go.
Yes. You can setup any snippet you wish. These are called "Live Templates" in Resharper, and have a lot more functionality than the VS versions. Just choose "Resharper->Live Templates.." in VS to edit them.
Related
For one of my internship mission, I need to use a C# app-builder, serenity.is with Visual Studio 2015. I'm following this official tutorial.
More precisely, I followed the begin of the tutorial p 43. (I'm just adapting it to what I do, I join the code at the end of the post).
Nothing is going wrong till p 49. The code generator of the app-builder, sergen.exe, is creating some code (I don't have the detail of what he creates but it doesn't seem to be important).
They ask me to "rebuild all", what I did, and everything should work smoothly.
As project is modified, Visual Studio will ask if you want to reload changes, click Reload All.
REBUILD the Solution and then press F5 to launch application.(tutoriel)
Nevertheless, when i compile and execute my code, I've got a bunch of syntax error which shouldn't happen.
You can find the code of my migration file below, but I don't think it is the problem.
using FluentMigrator;
using System;
using FluentMigrator.Infrastructure;
namespace Serene3.Migrations.DefaultDB
{
[Migration(20170802070000)]
public class DefaultDB_20170802_070000_TcpDump : Migration
{
public override void Up()
{
Create.Schema("tcpdump");
Create.Table("TCPDump").InSchema("tcpdump")
.WithColumn("TimeStp").AsString(16).Nullable()
.WithColumn("IdTransmission").AsInt32().Identity().PrimaryKey().NotNullable()
.WithColumn("IdSource").AsString(32).Nullable()
.WithColumn("IdDestination").AsString(32).Nullable()
.WithColumn("PortSource").AsString(16).Nullable()
.WithColumn("PortDestination").AsString(16).Nullable()
.WithColumn("-->").AsInt32().NotNullable()
.WithColumn("<--").AsInt32().NotNullable();
}
public override void Down()
{
}
}
}
I tried to stay as close as the tutorial as possible. I probably forgot to do something, but I can't find what.
Is there any Serenity user which could help?
Feel free to ask any other details
Make sure that all column names are supported by the tool. Column names like "-->" and "<--" would need special syntax in SQL and can't be used as property names in generated code files.
Use property-ready names without special characters or spaces. If you need special names, consult the tools documentation and make sure to use supported techniques.
I'd like to create some sort of Visual Studio add on where I could hover over a line like:
public int counter {get; set;}
and upon selecting my menu item (or light bulb), it would insert a line similar to the following above it:
[DataMember Order=1]
public int counter {get; set;}
I found this example:
https://msdn.microsoft.com/en-us/library/dn903708.aspx
but I'm not sure it's taking me in the right direction. I was thinking that adding a menu item might make sense (so I could bind it to a keyboard shortcut), but the tricky part would be intelligently setting the "Order" parameter based on an observation of other instances of that attribute nearby.
Any suggestions?
Your digging in the right direction. You might also be interested in the LightBulb extensibilty sample on GitHub.
Additionally, I'd recommend looking into the Roslyn code analysis APIs. The VS 2015 Roslyn based compilers might make it a bit easier to ID where you want those lightbulbs.
Sometimes when I'm developing I may prefer to quickly inline classes, interfaces and/or enums when I'm building a fresh design or from within a test fixture. However, I find it inconvenient to interrupt my thought process to create new code files, copy and paste the class/interface/enum written inline to the new file, and all the time it takes to navigate between them.
I'm looking for an extension, macro, or hidden shortcut combo that will automatically create a file for the highlighted or selected inline class/interface/enum, and, if possible, copy the using list so that it can be built (but remove & sort will clean it up later).
I'm open to extensions, macros, or hidden shortcut keys. Suggestions?
Edit #1: ReSharper looks awesome, yes, and it appears to have exactly what I need, but I would like to find a free solution, if it exists, that didn't push me back $200.
Edit #2: After your helpful input, I'm pushing for my dev team to all run the ReSharper trial, and re-evaluate in a few weeks if the value-add is worth it. We want keep our extension use consistent, so I'm hoping we all find it equally worthwhile.
Example: I want to turn this (IExample.cs):
using System.Linq;
public interface IExample
{
}
public class Example : IExample
{
}
public enum ExampleType
{
}
...into these:
IExample.cs:
using System.Linq;
public interface IExample
{
}
Example.cs
using System.Linq;
public class Example : IExample
{
}
ExampleType.cs
using System.Linq;
public enum ExampleType
{
}
The built in refactoring tools do not have a simple way to extract a class to its own file, so the simplest thing to do if you do not have a refactoring tool like Resharper or Refactor! Pro that do have it is to:
Copy the class to memory.
Add a new file with the class name.
Paste the class to the new file.
ReSharper offers the feature Move to another file to match type name, the ALT+Enter shortcut makes your work faster.
Devexpress Refactor!pro can be your solution....in example you posted, refactor! Pro shows a quick action menu at the bottom of the class name that you want to move.
In this Actionmenu there s the "Move to file" option that' s all you need....
EDIT:
Apparently, this method does move the type to its own file but still keeps the relationship with the previous class, so it won't actually change anything other than generate a seperate file. The type will still be nested in the same way.
This is a pretty old question and I just encountered the same issue.
In Visual Studio 2019 (and probably in 2017 as well, though I did not check),
you can select the entire class -> right click -> Quick Actions and Refactoring -> Move Type to its own file.
It correct all references to said type, too.
Very handy!
I was watching a video about C# and the guy used a shortcut to implement a property.
public decimal Price { get; set; }
He wouldn't write the whole line, but instead let the visual studio editor fill in the get and set. Does anyone know the shortcut for completing the last part of the line above? Or even better, like a pdf quick-reference overview?
In Visual Studio 2010 you can type 'prop' then press tab twice. It's probably the same in earlier versions.
Edit: You'll then have to change the type (defaults to int) and the name (defaults to MyProperty).
Edit2: I've just found this great tool that allows you to edit these code snippets to override their default behaviour, or create new ones: http://snippeteditor.codeplex.com/
Using C# in VS2005, is there special way to create properties in the IDE or can you just type out the getters and setters?
In the code editor type prop + Tab + Tab
Well, you can type the word prop and then hit tab twice for a code snippet. propg will generate a readonly property (only a getter).
I think what you're after are code snippets, have a look here and here.
There are also snippets besides prop for properties that you may save you time, see here for the list of built-in snippets.
There are built-in code snippets - try typing prop then pressing TAB twice. This will automatically generate the code for a property with a getter a setter, and let you tab between a couple of points to declare property name and type.