A couple of Visual Studio tips

Public forum to share code snippets, screen shorts, experiences, etc.
NickFriend
Posts: 248
Joined: Fri Oct 14, 2016 7:09 am

A couple of Visual Studio tips

Post by NickFriend »

Hi All,

This is pure coincidence, but I was thinking to post a couple of little tips I learnt recently with VS, then Phil posted suggesting doing exactly that.... and hey, it might even annoy Dick a little ;-)

If like me you're sometimes a bit lazy when creating code, you may put more than one entity into a single file (I particularly tend do this when creating enums). When your conscience kicks in and you want to separate out each entity, just right-click on the entity, Quick Actions and Refactoring, then Move type to xxxxxxx. VS automatically creates a separate file with just that code and named according to the entity (class, enum, etc).

Next one, I thought the visual scroll bar (showing a mini-view of your code file in place of the scroll bar, the old MetalScroll extension) had disappeared. But if you right-click on the scroll bar and go to Scroll Bar Options and select "map mode", it's still there and configurable.

Maybe everyone knows this already, but just in case...

Nick
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

A couple of Visual Studio tips

Post by Phil Hepburn »

Nice one (well two actually) Nick !

This was just the sort of thing I was thinking about. If we all try to post a short note here along with yours, as well come to something useful, then we will soon have a nice pile/set which will be geared towards .NET and X# application creation.

I will post a couple of things tomorrow, now that I feel that I have at least one listener/reader ;-0)

Thanks Nick,
and regards to all.
Phil.
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

A couple of Visual Studio tips

Post by ic2 »

Hello Nick,
it might even annoy Dick a little
Well, I have to inform you that you failed in this B) . Why would I it annoy me when I would finally read something which actually could be useful in VS?

First I am actually intrigued by your posting. I understand that it is considered good practice to make a separate .prg/.cs of every entity? In none of the many samples this is done, including a 100+ solutions from Microsoft with Universal Apps. It would have the advantage that it would more or less give me back the thing I miss most in VS compared to VO, which is being able to see which entity changed most recent. I would of course need to open a Explorer for that, and it's project wide then (instead of per mef as in VO) but VS would actually become a bit more of a "poor men's VO".

Next I have to inform you that I haven't been able to get this working. There is no Quick Action menu in X#. In C# there is and in VS 2015 that menu only contains Change signature (whatever that may be). But I have no C# projects yet on the Azure server where I have VS 2017 so I assume it works (only) there?

Please keep on posting these tips. As written in chit-chat, I am looking forward to the moment (if ever) that I find more positive option in VS than negative and posting tips like these could help.

Dick
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

A couple of Visual Studio tips

Post by robert »

Dick,

There are no quick actions yet. Fabrice wanted to add some of these, but I told him that there are some users that would like to see smartindent and case synchronization first.
We have added case synchronization in 1.02. Smartindent was also almost ready. I have personally disabled the smart indent in the release version of 1.02 because it was not working the way it works in XIDE and VO and I was sure you would not like it.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
NickFriend
Posts: 248
Joined: Fri Oct 14, 2016 7:09 am

A couple of Visual Studio tips

Post by NickFriend »

Dick wrote:Hello Nick,
First I am actually intrigued by your posting. I understand that it is considered good practice to make a separate .prg/.cs of every entity?
Dick,

Definitely. Of course there are limits eg. every client-end data object class in my app has an associated mapping object, which is normally a one line instantiation of a generic class, so I stick that in with the relevant data class. But otherwise put each class, enum, etc. into a separate code file.

Then organisation in folders becomes your friend...
VSFolders.jpg
VSFolders.jpg (23.45 KiB) Viewed 590 times
In the screenshot you can see....
Solution (CIO Vesta)
The solution is divided into 4 folders - Client, Common, Core and Server
Each of those contains one or more projects (eg. Server contains CIOServerBase, CIOServerDAL, CIOServerEF, etc.
Each project is divided into folders....
And so on.

This allows a very granular organisation. Perhaps the only disadvantage is that VS automatically creates namespaces according to the folder structure - so if I create a class in the Companies folder it will automatically be in the namespaces CIOServerEF.EFEntities.Companies which I may or may not want. Haven't found how to change that behaviour yet.

Nick
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

A couple of Visual Studio tips

Post by robert »

Nick,

I think you and Dick are talking about different things. In VO an entity is a class declaration, a method, a property (access and/or assign) a function etc. I doubt that you will put each of these in a separate file. Your image shows that you work with the "one type = one file" principle and that is something different.

Dick, we are looking at adding an Entity browser window to the VS IDE. This would list all "entities" (methods, properties, functions procedures etc) from an Module in a single window. These are the same entities that are shown in the navigation bar in the editor. Selecting an entity from the list will open the source code editor at the right position.
Navigating to a different file in the Solution Explorer will refresh this list, just like navigating to a different module in VO will refresh the entity list. It will not be added to the next build but it is definitely on our "todo list".
We cannot limit the editor to a single entity like you can in VO. That wou require switching from a file based compiler to an entity based compiler and would require a repository of source code. We all know how long it took for the VO repository to become stable. We really do not want to go there.

Robert



Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

A couple of Visual Studio tips

Post by ic2 »

Hello Nick

Thanks for your reply. I think just like Robert that you are not putting every single entity in a different file, right? In that case you would get 1000's of files. But indeed for smaller projects one tends to put it all in 1 file.

I have copied a C# project to out Azure server with VS 2017. As you see in the picture I still have only the options Change signature in that menu.

What am I missing?
QuickActions.JPG
QuickActions.JPG (12.97 KiB) Viewed 590 times


Dick
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

A couple of Visual Studio tips

Post by ic2 »

Hello Robert,
Robert van der Hulst wrote:Nick,

Dick, we are looking at adding an Entity browser window to the VS IDE. This would list all "entities" (methods, properties, functions procedures etc) from an Module in a single window. These are the same entities that are shown in the navigation bar in the editor. Selecting an entity from the list will open the source code editor at the right position.
Navigating to a different file in the Solution Explorer will refresh this list, just like navigating to a different module in VO will refresh the entity list. It will not be added to the next build but it is definitely on our "todo list".

Robert
This would be a big improvement I think and yes, I realize that not much more can be done in VS. One of the main reasons of my VS dissatisfaction is that I rely heavily on the VO options to sort on last changed mefs/entities to see what I changed last. It saves me a lot of time, both in quickly finding were I was working on previously and on finding bugs: if someone reports a problem in this and that screen, the chance is high that the offending code is on the last changed entity or around. Doing the same in VS is so much more time consuming or simply impossible. Anything which (partly) mimics the VO behavior would help.


Dick
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

A couple of Visual Studio tips

Post by ic2 »

Hello Robert,
Robert van der Hulst wrote:Dick,

There are no quick actions yet. Fabrice wanted to add some of these, but I told him that there are some users that would like to see smartindent and case synchronization first.
We have added case synchronization in 1.02. Smartindent was also almost ready. I have personally disabled the smart indent in the release version of 1.02 because it was not working the way it works in XIDE and VO and I was sure you would not like it.

Robert
I appreciate your consideration regarding smartindent very much. Note that the absence of Quick actions is not a criticism; I was merely to indicate that I couldn't find Nick's option. Not in VS 2017/C# either by the way (see other posting).

Dick
NickFriend
Posts: 248
Joined: Fri Oct 14, 2016 7:09 am

A couple of Visual Studio tips

Post by NickFriend »

Hi Dick,

You're accessing the little quick action menu via the light bulb... rather than that, just right-click for the normal popup menu and you should see something like this.
VSMenu.jpg
VSMenu.jpg (28.05 KiB) Viewed 590 times
The option I was talking about in the first post is within the first menu option here - "Quick Actions and Refactorings".

Nick
Post Reply