15 Visual Studio Editor Tips including Intellicode and EditorConfig

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I get asked a lot about which plugins I use to make my development faster resharper is a common guess the truth though is that I use just plain visual studio with no paid plugins I do this because I don't want you as the viewer to think you have to buy an expensive add-on to do what I do in this video I'm gonna show you 15 tips to make your development experience faster and more consistent using just the tools built into Visual Studio now if you haven't come across it before my name is Tim quarry it's my goal to make learning c-sharp easier one of the ways I do that is by teaching context there are a lotta toriel's out there that teach you what to do I go a few steps beyond that to show you when to do it why you should or should not do it what pitfalls to avoid and what the best practices are basically I get you ready for the real world if that's the type of training you are interested in subscribe to my channel and hit the little bell icon to be notified when I release new videos also make sure you look in the description of each video for relevant links for instance each video has a link to my patreon as a patreon member you'll get exclusive perks in fact if you're a patreon member you should be receiving something very soon you also found length during a mailing list this is the best way to get discounts on courses and other important news now in this video's description you'll also see little time links to each tip in this video so you can use this video as a reference tool for later review alright let's go to a visual studio and I'm going to use the timko retail manager solution as the the project to then use at to see the editor okay so I'm not gonna actually make any code changes to this project and if you are wondering yes Tim Cole retail manager is coming back we're doing more on this very very soon but I want to use this code base to show us how to work with the ED or more efficiently so this first tip is going to be about intelecom now I'm not sure if you see Teleca for I just turned it on in my visual studio because I didn't want to confuse people with what it was before I started before I showed you how to use it this is a newer feature that is now built into Visual Studio as an extension get extensions madge extensions and you got it installed you should see down here Visual Studio Intelli code if it's not enabled or if it's not installed you can go ahead and install it by going online searching for Visual Studio Intelli code and the description says this is a I assisted developer productivity tool alright and that's exactly what it is so what this does is it helps us be more productive in our code by having an AI assist for us that makes intellisense even better let's do the mean by that so let's go to oh it doesn't matter let's open up let's go to login view okay so in here let's come down actually let's go a helper class that's a little bit more code in it alright so we have a a box let's go to a one has a string here we go set bound password so then Teleco let's just say I did a console.writeline well right now it's not telling me much besides just normal intellisense but once we get a once we have Intel akkad kind of spool up and then build or rebuild spawns helps that what'll happen is it will actually give us a list with the suggestions up top so you control J again and now notice there's four starred items this is Intel code saying you know what here are the most common suggestions for you in this particular instance so it's saying I think probably the most common thing I put in console dot write line is value y value because it's a string alright but it also D which is dependency object there's also get bound password and bound property these are both values these are all four values we could put in this right line that have been generated somewhere so it's saying I know you've got these generated values that might be what you want to write out to the console and so I'm gonna suggest that in order of importance or order I think that you might want them and so we can put a string first and it puts the other ones after that so that's pretty cool you'll have to search through an entire list of options when it's gonna bubble up the top the ones that are most important to us let's be something a little different let's go up and we're gonna add a using steam up here for using system dot IO okay so set some tiles high work with files so let's come back down here and I'm gonna say let's do path dot okay now again it takes a little bit for us to come in but there we go so now we have some suggestions one of the four most common things that path is used for combine get full path directory separator character and get temp file name so these are the most common things used on that path now what if I were to say file instead this exists right I'll text read all tanks delete and open read these are the most common things again there's a whole list of options you could go through it you can look through all of these and find the one you want but these are the most common and so if you're not real familiar with the file the system - iota file you can look here and go oh I see these are the most common ones let's see if one of those is the one I want okay same a directory okay create directory get current directory exists and get files those are the most common things you do the directory there's other things you can do get directory route get filesystem entries but the most common ones are these four now let's talk from it how did Intel a code know that these are the most those most commonly you used options for directory well what Microsoft did is they went to github and looked at a number of open source projects lots of them I don't want to quote the number or misquote the number but it was a lot of them and they looked at all the code and they analyzed it and they said okay here are the common patterns for writing c-sharp code so here's a common methods that people use here's a common parameters people use and here is how c-sharp is commonly developed and so that's when they get these suggestions from is that learning process they had an artificial intelligence scan all that code open source code so it's not yet secret code open source code it scanned it and said here's how that code gets written here is the most important things people use those common things now that's that's tip number one as in Teleco dantella code just either box makes your life easier okay but you may be saying Tim you know what my code base isn't like most other code bases in fact it's a little different the way we do things at work or the way I do things is just different I use different things inside of Visual Studio than most people do I use different directory options or file options or something else or I have my own library with certain things I do so it's not going to help me if to use Intel code well it will because don't forget that console.writeline said you probably and that's learning from my code this code right here but there is also another thing you can do and that's if you go to the the View menu the other windows and go to in Teleco Model Management now if you don't have this go ahead tools options and down here under Intel code under general make sure I enabled the output window logging c-sharp base-model saml-based model is that kind of cool we have zamel options too and I also enabled whoops I also enabled the acquired team models for completion this is kind of important one enable but I did all my c-sharp ones as well basically I want to use all of these options here with that now I can go to view other windows and I can say Intelli code Model Management and what this does is it's gonna create a a I scan of my specific code I'm going to teach it based upon my code that I've already written this tIMCO retail manager project it's gonna learn based upon this and then it's gonna suggest for me things that are unique to me so let's create a model and if we click on timko retail manager will see this learning your codes patterns and this will go through about a 30 second to five minute process where it scans your code and learns all about how you do things now if that concerns you don't worry yes this is scanning a code and yes this is creating a model based upon your code which has done that but this is not giving this to Microsoft this is not giving this to the rest of the world this is based upon your login to Visual Studio it's secured via HTTP to your login in Visual Studio which means you do have access to this on other machines the same model and you can share this model if I click this it's going to copy a link to the clipboard okay so if we go over here I just paste this in it's gonna create a link for you and I won't pay something I'll show you my specific link but it's a link to the cloud now if anyone has that link they have a link to your specific model which can be used to help train their visual studio or tell their visual studio how to work with your particular code base or your code style okay but it's not giving your code away and you control this if you decide you know what I don't want this anymore and won't have access to this hit delete you're good to go if you want to retrain it as in you've made some changes to your code base and you think that there's new suggestions you might want to have visible to you hit retrain it'll retrain on the same code base you can have more than one of these so you can read you can train this on multiple projects at your company and then bring all those suggestions together into one big suggestion list so it's going to take the Microsoft suggestions and it's going to take your suggestions and kind of combine them so they'll have a really targeted suggestion list for you based upon the most common things that you might need now is also a link here it says automatic model retraining and what that's gonna do is gonna teach you how to use Azure DevOps to make model training part of your build process which will allow your whole team to have the latest model for the Intel akkad model the latest one based upon the latest build so that's a that's a neat feature as well we're going to get into that today but that's a possibility if you want to go that far but this right here allows your whole team to get on the same page and become faster and more efficient even if it's just you you don't have a team this still gives you those suggestions at the top that are most common for the way you do things really important really cool stuff here all right so that's Intelli code now one of the things that people have seen me do quite a bit let's create you know what let's go over to our API and we're going a controller let's go to the very have this here let's go to there we go so a token controller now a token controller I don't have an I configuration those here I have I configuration and token controller I want and I configuration so what I'm going to do is I'm going to say I want an I configuration in a control dot to add my using statements and I'm gonna say config and I do control down again and say create initialize field underscore config and a few of you said whoa whoa whoa whoa whoa I don't get that when I do this I don't get the underscore I ask it configure it doesn't look right well that's because I made a change to my code styles so let's go to tools options and if we come up to the source code whoops not source code text editor there we go c-sharp code styles inside here we have formatting naming there we go so code styles is a bunch of stuff here we're gonna look at more of these in just a minute but let's look first at naming now because I have increased my fonts for video consumption it kind of crunches them here this is not ideal but in here you'll notice that I have private or internal field and says field name well what how did I get that well I created that as an option so you can say manage naming styles I have field name I create that by hitting a plus and filling this in I'll show you what I filled it in with I called the underscore field name required prefix as an underscore and then it's camelcase name after that so the sample is unders for example identifiers now if I put a underscore afterwards notice is gonna put underscore afterwards as well and if I said word separator is a - now I have kind of snake case but still kind of camel snake case which is weird okay but this shows you what's gonna turn out like so we have Pascale case no it's gonna change to a capital e I can have first word upper I can have all upper okay some really ugly styles here but what that allows me to do is say okay I want Pascal case I don't want a suffix or a word separator oops I want camel case there we go that's why I want my an item to look like so I created that naming style first then I said manage specifications and I chose which specification to create in this case is already there private or internal field and that's what this right here the I configuration that's what that is is a private or internal field okay a field is is a variable that you can access in your class all right so that's it's not a property it's a field if there's a property to have a get in the set at the end of it so a private or internal field gets this field name casing okay and that's a suggestion I could say you know what no that's an that's an error message I'm gonna leave as a suggestion though but that's how I have changed the way that it creates this variable all right so now when I do my quick action and refactor and I say give me a private read-only for this it creates it in the correct format that I want and that's based upon under text editor c-sharp code styles naming and I made that change okay so that's how I made that change well there's tons of other options inside code style let's look at some other ones in general and this is the really cool thing I think because it's hard to understand what qualify field access with this I'm not quite sure that means now I do but let's pretend I didn't well if I said prefer this watch what happens down here that's what's gonna look like oh no I don't want that I want that okay so you'll see what each thing is going to do now this is for field property method and event okay there's a ton of other options in here var preference for built-in type prefer var sure alright when variable type is apparent then prefer explicit type or prefer var notice I can change that and shows me that what the the values are and that's a refactoring elsewhere so var or explicit type I get to choose okay and based upon my preferences I can then apply these as refactorings suggestions warnings or errors so let's just do a couple of these I'm gonna say I want var for everything now I don't want me a suggestion I want it to be an error if you don't use var let's say we're going to go full var at my you know organization at tIMCO we're gonna full var nothing else and I hit I'll hit okay in a minute what we're gonna do is see how this then affects our code all right now formatting this is kind of cool so all I mentally format when typing that's awesome so when you don't put the spaces in the right spots that takes care of it when you're typing also when you put a curly brace also when you return or when you paste so I paste something in it's gonna format it for me automatically really cool how it's some other stuff in here indentation how do you want to indent things do you want to indent code blocks no yes okay see the difference down here indent open and close curly braces oh that's horrible flute player it was okay most these will probably fine but do you want indent case or do you want the the contents we're about the alive a case I don't want to do that what I have them indented but you know what I don't want to do I have a crazed I want the curly brace to line up with case that seems reasonable case labels many can bring them back underneath the curly brace and save myself a little bit of space that makes sense kind of it's up to you if you want do that or not I'm gonna leave it the way they is but it's definitely you now here's one place go to labels okay stop right there don't use go to labels how about that okay so ignore that section don't use go to Dale's just don't just don't don't all right if I specified enough don't use go to all right new lines now if you've ever used JavaScript the way that we layout c-sharp code may seem odd this would allow you to make your c-sharp code look like JavaScript don't do that because that's very uncommon and it will clash with everybody else in the universe when it comes to working with their c-sharp code versus yours but for example I can open up a clear brace on the same line if I uncheck this box again that's a JavaScript thing and there's a reason for it in JavaScript it's not just because that's the way JavaScript is although it is a little bit but in c-sharp we started on a new line we call that cleaner I do like that better I like that formatting better even though when I'm in JavaScript I do follow this pattern okay so definitely don't bring your your ideas or your thoughts from other languages and try to apply them here in the the formatting try and apply the formatting that is generally accepted as best practice the nice thing is by default that Visual Studio is set up to pretty much all best practices or most commonly use practices for C sharp which is excellent but if you work at a company where they do want to have a little bit different set up let's say control blocks they want to start control blocks with a clear ace on the same line you come in here and make this change so your editor is not fighting all the time with their adders because if you do a format and it changes all of them to look like this and they do a format and change them all look like this your source controls gonna have a bunch of little changes all over the place every time each of you checks in code that's not good not naturally just changing the formatting back and forth and how you little format war you don't want format Wars so this is the place to make those changes and have them apply automatically remember back here automatically format on paste on return on close curly brace on semicolon when typing so it's gonna keep fighting with you and do the what it thinks is the right thing so make sure you setup what those right things are in here and here okay same as spacing do you want mess of spacing or change how spacing works and this is not how many spaces to use will see that omit this is do you want to insert a space between a method name and it's open opening parenthesis so it GU right here there's no space click that and now notice there's a space between GU and the open parens so again you get to change that if you want wrapping same thing leave blocks on a single line or do I wrap them like so I don't like that I like the single line and state members and declarations on the same line I kind prefer that I don't like to have multiple lines on one okay so I'll leave it like that now with all of that being applied notice the VARs are still applied we hit okay okay and now if I were to do a build solution it should be it starts picking up on issues that I have all these are all VARs look at that let's go over here where they're not VARs look at sales data string these are now errors notice a little three here four errors and if I click it's actually says nine because multiple files have errors that's what I said that this is an error this is a problem to not have var if I hover over it use my use var instead of explicit type in the quick actions and now it's all happy okay now if you say you know what nope we're gonna change that let's go back to tools options and once this opens it's gonna take a little bit evidently but we can change it back and say you know what that's actually a warning that's not really a big deal then actually crashed my visual studio right there so let's try that again there we go so now I can come back to our text editor c-sharp code styles and down here for VAR i said prefer VAR well let's just make that a refactoring let's make a suggestion okay I'm gonna suggest I use far but that's it I'm not going to yell at you and give you a red squiggly I'm just gonna give you a quick suggestion okay so let's close this out and we'll open this and it should be that gives us suggestions notice kind of Gray's it a little bit and have a little dots underneath sales data and says hey you want to use var instead but it's it's subtle it's just a little indication it's barely noticeable notice it's a little then if I were to use var it kind of lights up a little bit takes that dot away so again settle for just notification but if you wanted you have something more pronounced you know so I can turn off let's just see just the the error messages there you go just the messages there's what's gonna tell me okay use var here instead okay so that is the code Styles let's talk now about the editor can fee because this is one that is newer and it's one you may have missed in a recent release now let's go back to our tools let's go to options and back here with coding styles know that says generate dot editor config file from settings so an editor config file is a file that has these settings in it let's click generate we do that let's put it right in the root of timco I'll hit OK I'll hit OK a new edit config file is detected at the root of solution would you like to make it a solution item yes and now we've got here nois solution items let's kind of collapses down under solution items I have edit or config and this is a config file the whole bunch of settings and there's some really long names in here and there's some wet readable C sharp prefer braces true and it's a warning ok so what's gonna happen is if I have an if statement let's just create a F statement here if one equals one then yes like that that's technically valid c-sharp code because I only have one line here after the if therefore this line applies to if this is true I'm not a big fan of that I prefer to see it as having curly braces notice the green squiggly under if and it says add braces you click that it's gonna add those braces and now it's all happy let's undo that let's go back to our a tour config notice it says warning well let's change this to error okay and now what's gonna happen is it's going to turn red and say that's a problem you can't do that and so just by changing this edit or config we've changed our settings and there's a plot this edit config since it applies at the solution level applies to all my projects I can also have an edit or config inside a project and it's going to apply the one closest to the the issue kind of like CSS does may you may ask why do we create these files which are a little harder to read when we have a tools options dialog and the reason we create his files is because this can go into source control what does that mean it means you can take these settings create a file that works for you or your company and then have everybody use the same settings so what's the order that gets the biscuit supplied it well it applies the the closest aide or config to your code and then it goes up the chain so notice remove the line below if you want to inherit edit or config settings from a higher directory in this case we said root equals true B this is the root it or config this is the authoritative one alright but if you're in a lower director you can turn that off and then it's going to inherit settings from a higher directory or you can say nope this is though this the authoritative one at this level and then there is no setting then the tools options code style from your visual studio will apply but this allows you to make all these settings and change them based upon what you think is best and then also change how it alerts you you can say instead of silence which is that refactor only we're going to change that to suggestion or to warning or to error now the nice thing is that you can build out your options visually see what the results are for most of them and then generate that edit config file from there then you can take this edit config file and share it around or even tweak it for something else now Eider config just you know is not a Microsoft thing Microsoft has adopted this standard this is an industry standard it applies to much more than just visual studio it's not a visual studio native thing it's something that that Microsoft has brought individual studio and said yes we want to do that and so here's our application of the edit or config option so when you search online for a tour config you may find solutions or help that are not specific to visual studio and options that might not work in Visual Studio because they're not implemented but this is a standard that Microsoft is applying now is another way to create an edit or config file I think this is pretty cool and so sometimes I'm kind of torn with which way I want to do this you can right-click on a project or a solution and you can say add new a door config and this isn't elico so this is part of in Teleco so if you go to tools options and let's look for Intelli code down here and one of the options we'll have in here is edit or config inference and I've turned that on and what's gonna do is if I right-click and say add new a door config file it's gonna scan my code and based upon what my code has done it's gonna create an 8 or config this is the config file it created the inferred from my solution or Mike actually my project okay so it it was done this date it was done against this codebase and you can modify it now but this is this is what my code does right now so if I have done things in my code I can create a style guide out of that an editor config guide that allows me to say here's how we're on do things going forward to match the current code base so if you have an old project or a project from somebody else that you need to continue to work on and continue to maintain you don't want to change styles halfway through so you can use this Intelli code version of edit or config to create an editor config for you that applies the same styles that the product has been using and that way going forward it'll override your visual studio settings to apply settings that apply to this particular project it may not be the way that you're most comfortable with but if a project has done things a certain way changing styles midway through is not a great idea don't just force a new style because you like this style better you kind of have to conform so it's not confusing and so it's consistent all right now let's move on the next tip and that's it's a smaller one but it's actually a really important one because it helps you get into visual studio faster let's go at tools and options under projects and solutions the very root of it or in general either one there's a few options here a couple options that are pretty important now I have already set one of them in that is track active item in solution explorer by default I don't believe that's checked but make sure that's checked what that's gonna do is when I am let's just say I notice I have two eight or configs here which editor config am I in well notice that this one over here is highlighted if I click Edit or config over here it highlights the one down here that tells me it exactly where I am let's collapse down the API let's collapse in the folder let's collapse down to a PDF I click the other eight or config it's gonna open up and dial right down to that edit config and show me where I'm at so that's a really important one to make sure especially with two files the same name that can be really confusing as to where you're at you can just look over and see where you're at if you don't have that on let's just uncheck that so now if I close this I minimize this let's minimize this which editor can fit my in well if you hover over it it tells you a path which you can't keep open unless you don't move the mouse okay well as tIMCO retail manager editor config that is timco retail manager trm api that editor config okay so that's the api one which is probably in here so oh there it is kind of confusing right so just by checking that box you make a big difference the other one is one that's a convenience thing and this is on by default but you can turn it off and this is can be helpful for loading your visual studio quickly restore solution Explorer product hierarchy state on solution load what does that mean well notice how I've got my folders and structure open where I have controllers open I have all the rest clothes I have highlighted editor config this layout visuals to your members if I were to close out visual studio right now and restart it this is the layout at half with controllers open trm api open expanded an api expanded if i uncheck this box it will not remember this layout which may seem like an inconvenience it can be if you want to go back to the same exact spot but by doing that you don't have to have visual so you remember where that is and load that back in a memory it's faster also reopen documents on solution load right now I have four or five probably eight or nine documents open oh seven documents open maybe more they're hidden under here that happens a lot and often I go through and right click and say close all but this well when I'm done I just want to get out of the project and so I close it when I open it back up it's going to try remember what all these documents are and then load each document I don't want that and by unchecking that box it will allow Visual Studio to open even faster so these two checkboxes down here make Visual Studio open faster and this check box up here make sure you know which file you're working on by showing it to you over on the right both of those I think are good where I have selected them and that is not the default so make sure you change those unless you really want to have that convenience and don't want to worry too much about the speed of your Visual Studio loading okay let's go back to our code and let's go back to inventory controller and notice that we have some some information for us it says these are just messages but it says use var and civ explicit type okay so let's look at a way to clean this up automatically there's a little broom icon it's really tiny best down here where it says run code cleanup and it's a little drop-down next to it so with the drop-down where you can configure code cleanup you have two different profiles here profile 1 and profile 2 this allows you to set things up differently based upon different environments so I'm gonna set up my environment now remove unnecessary usings some people love to do this I don't really care but at the same time hey why not right well that's usually a right-click step so you come up here and you right-click and you say remove and sort using but if we're in this configured code cleanup that's one of the included fixers also sort usings so it's gonna sort our usings for us and say those come jumble them up together all right apply implicit / explicit type preferences that's the VAR versus int or string let's apply that and we can have other things as well and remove braces for single line control students I really like to have those braces so let's add that and add access modifiers you know what I often forget that let's add that and unnecessary casts is an interesting one really could apply all of these but remove unused variables that's a dangerous one in case you're halfway through modifying something it get rid of those variables maybe not ideal and apply object collection initialization preferences let's not do that one but let's do these throw a sort the using removing unnecessary usings we're going to add or remove Cree races for single line which is going to add for us we're gonna apply our type preference which means it's gonna make it var instead of our character and we're add accessibility modifiers which means that this says I'm gonna hit OK here this is private right now I often forget that and just say read-only which it is private still be that's the default but I want to be explicit about that also let's create in here let's create an if statement if if true equals true console.writeline true makes no sense but there's our if statement we want to have changed now if I apply the default which is the first profile nose the first profile here and that's marked as default if I apply that by clicking the broom notice now this is private this has curly braces and this is var so it's apply this entire file so that's a quick way to apply some of your most common standards or formatting against a file let's look at are you are using Simmons there's our using statements where you've ordered them by Microsoft's first and in order by alphabetical and then we've ordered them by ours also alphabetical so now that we have that applied to one file the next tip is how would you apply this to say a project or a solution well that's actually pretty easy right click on your project and you're going to say analyze and code cleanup let's run profile one click that and now notice I have a whole bunch of files that have been changed notice the red checkmarks alright so in here has been changed I'm not even sure where we can actually do a comparison so let's do a compare the unmodified oh it removed a whole bunch of using statements so that's I think all it did for this file yep let's look at what it did for program I bet that did something similar yep it took some using statements out okay I didn't go through and find all the things that did let's look at one that's other one okay we took a user statement we ordered it and we change a thing to 'var so it's gone through my entire project and made changes based upon my preferences so that's really helpful because when you're getting ready to check this code in you can just say you know what go ahead and do a cleanup in case I missed anything it was going to take care of it for you now it should be the editor config we'll make sure that you don't do anything going forward or at least it will warn you so I did that if statement where I said if true equals true and then did my console.writeline it's already yell at me and I can do the quick fix but this way I only have to bother with that ayah say you know what apply that code fix and boom there we go done all right the next tip I want to show you is one that I've shown you before but you may have missed it and I'll make sure that I get it in here as well just like again show you one more time and that is the paste specials okay so I have copied some JSON to clipboard there's some JSON all right now c-sharp doesn't work directly with JSON doesn't like it we use objects and strongly typed items and names and all the rest well you can go to edit paste special I can choose paste JSON as classes I click that and it's going to create for me a whole bunch of classes for my my items that I have selected on the clipboard and of course my head is gonna crash once again because I've been messing with all the settings so much let's try it again edit let's go to pay special paces XML classes excellent it just crashed again on me I'm gonna show you the results of it because it's something quirky of my system right now I got some probably I'll redo some visuals to your things but there you go we've got the public class route object and it's created all of these names for us now these names are not correct okay fix name violation it'll fix it for us okay so we could go through and make these change we could even do a clean-up on this which clamp doesn't do naming I don't believe but we might have the ability to apply our naming here which I don't think we do so you might have to do it manually but what this is done for me is it's done a lot of typing so now all I need to do is I need to come in here and just make a few tweaks and I've got a class object okay the next one I want to show you let's go to WPF we'll go to the UI and as helpers and password box helper all right I've got interesting one here there's a couple of different suggestions I've got going on for VAR box equals D as password box if box is not equal to know what I'm gonna do is I'm going to use the quick actions and refactoring which I do all the time but I want to again point out and show you something new it can do that just makes it even better alright so we have this if box equals null and all the rest but if I do control dot here that's going to allow it to do explicit type if I wanted to all right there's also other quick actions refactoring I can do on the if statement notice invert if check that out so right now it says if box is not equal to null then do this all right whereas and here's another one there's even better one so if box equals null return otherwise do this well that doesn't necessarily make sense because if you said not equal to null do this either way return either way you don't have let's say return it's just done so I can quick action refactoring I can invert this and notice it's gonna keep the the sentiment it's gonna keep the the logic correct even though it inverts it watch what happens invert if it took the return statement away and it put my code inside here and say if not null then do this that's the same exact logic it's just that it flipped the if and it actually made my code a little more intuitive alright now up here this I've got the ability to use explicit type cool that's fine but use pattern matching so what's seen is that VAR box equals D as password box and then if box is not equal to null what's saying wait you don't need to do all that you can collapse that down and use pattern matching to find this information out let's right click quick actions and say use pattern matching now its collapses down to if D is a password box well guess what null is not a password box therefore is not a problem it's going to the same exact logic but let's let's back this back out I had one to even count McCrae braces three four five six lines of code that collapse down into four lines of code and the logic stayed the same and I did all that with my right-click quick actions and refactoring so continually check that out if you have a for each loop you can change that to link by using your quick action refactoring if you have a link you can change that possibly to a for each loop if it's possible but if it's possible it will suggest how to do that you can swap between a two so maybe you're not really good at link but you know that this for each loop Spri better off as a link statement no problem right click quick action refactoring and see how to do that by just letting it do it and that's really intelligent about how it does it now for this next item I'm gonna have to do a little bit of setup work so let's just pick the program that's fine now I'm gonna put in here a new method I'm gonna say public static let me return a tuple I'm going to turn a string first name string last name you remember a tuple allows you to return two values kind of like a anonymous class you can name them or you don't have to I prefer a name them I'm gonna say get like so and I'm gonna say let's just say return Tim Cory okay I returned that that full object like that or the full tuple okay that's all this this methods gonna do again this is not about the method itself it's about the fact that I'm returning a tuple but let's just say here in Maine I want to do a a console.writeline where I write out hello Tim the first name so I'm gonna say let's use var var actually let's declare it so I say string first name let's just say FN for first name string Ln for lastname equals get names like so that's one way to name a tuple right or we can say you know what let's not we're about typing we can do it like so we can save our first name last name or a name these two and I get the names okay but I just want to do console.writeline let's do our tree interpolation and say hello first name okay that's it that's what I want to do I don't care what the last name so instead of create a variable for it I can use an underscore this is called a discard character what it means is I don't care about this so don't create a variable for it a discard character or the underscore is a write only variable and yes you heard it correctly it's a write only means information goes in nothing comes out you can write anything you want to a discard character so I am going to write the last name value because I don't want to track that I don't want to store that in memory I just want to know about the first name so now I can use a first name still out of tuple but I don't have to grab that last name value in order to do that and that's a quick way to be a little more efficient your code and just get the information you want back from the values okay so that's a discard character now for this next one I'm gonna have to undo all of these changes I'm in at time changes in fact if you go to changes here you'll see a ton of things and you may be horrified because we're changing everything about tIMCO retail manager and the everything's horrible right well not really let's actually hits a ball cool right well I gotta come to the root here of changes right click and say undo changes and to say are you sure you want to do that yes I am and by doing that I still have to edit or configs these that's because these are added items so I can't undo them because they were non-existent but I can click on both of these and delete them so yes the editor configs are gone now we've actually reverted back to what we started with at the beginning of this video so you'll see that in here we're using the the actual types instead of var and there maybe if steam in here doesn't have clear braces probably isn't but there may be and so that's back where you started from essentially okay so now they're back where we started from let's go ahead and launch this because I want to show you the next cool thing which is zamel hot reload okay so we're going to start our application and our application start two things it starts a a wind farm project and it starts an API so get the wind form project open because I'm using I need to turn this off but I've got it on for now because I haven't turned it off yet pretty much these are some tools to help you with zamel but I really hate the fact that it's right there you can't shrink it down to that and it's a little more helpful I appreciate that I really do it gets it mostly out of the way is I'm not a big fan of seeing something big like this in my form but it does allow you do some modifications to your DPF but you're going to do I'm going to shrink this down a little bit I'm going to shrink down my visual studio as well as you can see both okay and with this now I'm gonna show you HOT reload let's unpin these and let's go to solution explorer and look at remember I'm using mvvm so my my view model and my model I'm sorry my view now my view are separate this is a login view so this is just the friend it has nothing to do the code now let's unpin this we have a little more space this is my zamel okay and this zamel controls how my form looks an X so for example if I come down here I have a user name right down here well what if my company came to me and said you know what we want that to be user space name well I could see how that looks by saying and watch over here on the right why do this user space name and it changes automatically that's the sam'l hot reload because I could hit save now and that's saved my source code and I can see immediately what it looks like you know if I say you know what I don't like it saying login form let's how it's a timko login form that looks better or it doesn't we can change how big this button is you know that that button doesn't have the right padding maybe we should say 10 instead of 5 oh you know what let's just go full on 20 all around ok maybe not maybe we'll say 40 20 you always we start playing around and say you know what I kinda like a big button like that that's a little more bold I like it and you know what let's just coloring out because I'm not a great designer but maybe we need to have some kind of gray battleship gray or dark slit slate gray dark slate gray that's kind of horrible but sure okay and now you start seeing all the different changes we can do to our form based upon zamel hot reload this allows you to see your changes in real time and it allows you to kind of work in your full zamel view even though you also see your form view but it's not a different screen if you want and you can change how your how your layouts work you know see it's a two star and see how it moves things around you can change it to auto and and see how that changes things okay so you can play around in here untick it you're tweaking your formatting correct and say okay I like that and then all you do is hit save and you're done when you start the application up again it's gonna look like this now maybe you shouldn't make it look like this specifically but you get the picture now let's gonna give you a freebie while we're here I've mentioned this on a video or two but this was I think it was like number two on my all-time list of things I wanted to have okay and that is this little button right here pop out zamel okay so we have our example and we have our view and I never liked the fact that I had to have both where I couldn't I had to have one okay so if I collapse one that was it I couldn't see the other now I can pop it out and I can have this code on a different monitor this zamel and I can still see my view so now I can make my view as big as I want all right so this is this is really great it's now I can zoom in here and really get this a look that's a hundred percent right there now it's exactly the size it's going to be on someone's window and now I can look like the zamel and different window and make modifications if I want to now that hot reload also makes it so I don't have to do that because I can do it when it's working life but this is a nice option now the next thing I want to show you is actually has to do with debugging so let's look at the sales view model and in the sales view mail we have this load products the inside here we get all the products and then we do something with them let's put a breakpoint right after we get the product list let's start this up and login go right to the products list ok so we're starting up there's our horrific view but it works and we hit login wait for it and go right here so now I have a product list and I can open up the locals window I can pin this and we see that we have a product list which says for I click this and I've already done because I was messing around for hand this is what you typically see trm desktop UI dot library models dot product model a list of four of them not helpful at all and what we used to have to do is open this up and look and say ok that's the skillet ok that's the flood bath towel and so on but now I can pick the property or properties that I want to see and I can pin them and now I see product name equals tan jillet-ben hard pair kit and large toaster oven without having to open up or expand this object now if I hover over the price list I expand this out it shows it in this list as well and you can also select multiple items so there's retail price as well and they can see product name and retail price in this list it makes it really easy for debugging quickly by just scanning through a huge list based upon the pinned properties now the neat thing is this kind of bonus you can do a search and here and find the items you want okay and goes right to okay there's two different properties that have fluffy in their name and so you can go right to the object you can even move between them it's like two of them all right and even if it's buried so let's do it again fluffy enter goes right to it you can go the next one and the next one there's a three entries one is the actual name itself since we painted that value so that search is really helpful if you're looking for something specific especially the gal list back that say a hundred or 300 or 500 items long you can search in there for the one you want and then expand out and see the other values of that particular object okay we can close this down stop it and have you ever had the issue where you know what I want to copy something let's copy this right here I'm you know paste down below and you say okay I open that up and miss Pratt Greg's able oh I want to copy this and so you copy this and go oh shoot I had that in the clipboard there's a clipboard a ring built into Visual Studio so if I hit ctrl shift V I can pace whichever one I want I can even use the hotkey of the number of the item so I can hit let's go down a new line here I can hit ctrl shift V and hit two and then paste that in enter ctrl shift V and hits two again is it moved I switched to values now for the notifier property change and there we go so this allows me to have multiple items on the clipboard at any one time now another bonus tip for you is that there's also one built into Windows itself if you haven't tried already it's pretty cool if you hit Windows V the first time it's going to ask you to set up but after that it's gonna keep track of your clipboard for you and you can paste things in from a ways back and just click on them and paste them in okay so pretty impressive stuff there right from windows so you have the clipboard ring inside Visual Studio which is specific I believe to visual studio alone but then as a clipboard ring for Windows which is for cross all windows products now before we talked about the idea of creating your own snippets and a snippet is like console.writeline so CW you tab twice and it fills in console dot write line we even create our own with console read line to fill that in for us but maybe you have code that it's not quite snippet worthy but it's code that you want to remember either inside a project or cross projects well there's the toolbox for that let's pin a toolbox now notice there's nothing in the toolbox but if I say you know what this line right here notify have property change I use that a lot and I always forget the syntax of the curly brace or the parens and all the rest drag it on to the toolbox and now you can right click and say rename and let's just call this n o PC know if I have property change okay and so now if you're in here you can click and drag that in and there's your code now obviously one line might not be a big deal if you had a whole property you use a lot okay let's rename this to demo property and you know you're in here and of course it would keep the same name so it might not be ideal but if we drag this on here it's gonna paste it in but maybe you'd want to change the names so snippets the sometimes better use allows you to change the names but this way you can kind of drag code in for example I used a poor code a lot alright so if I come over here my data access library data access and actually internal did access this code right here load data dapper load data now in any project I mean I can come over here and I can just drag in that method and there we go there is the structure for it now again I have to change some values if things are a little different or named a little different whatever but that gives my structure immediately it's also times used for demos I try not to use it for demos because the fact that you kind of missed how I create all that code but it is good for blocks of code that you somewhat repeat but you don't want to create a snippet for you just want to have something really quick but maybe you're even doing just inside of a certain project and then you're going to be done with it okay and that might be a way to you know drag it on when you're done with it right-click and say delete and if that's here you sure yep delete that one as well and you know now you have just that one snippet there but that way you can kind of have that intermediate step between the clipboard the clipboard ring and a whole snippet there's that kind of middle ground here where you can drag sections of code or bits of code into your classes all right let's go ahead and clear out all of these changes because again I don't want to have any changes and I'm gonna get rid of that I'm gonna show you one last one that that I have found to be really helpful sometimes when you're working you don't wanna get distracted by let's say right click add new class that kind of process you're using your mouse and set your keyboard there kind of heads down right here and say you know what I need to actually let's put our context here so I need a new controller and so what you're gonna do is gonna say you know create a new class and add the controller to it well nothing too a few steps where instead I could hit ctrl Q now how do you member cute control Q right up here so it says ctrl Q so hit ctrl Q I'm gonna say let's create let's add a class I hit enter and I type my name tests controller and there we go public class test controller so it's create my new class in the location where my cursor already was I was in home controller so therefore it create a same controller folder and I didn't have to use my mouse for anything it was just there it's done so that's a quick way to create a new file that's not all ctrl Q does let's just say that you wanted to tweak how the Intel occurred worked well ctrl Q and tell a code okay what do you want to do do you want to do the Model Management do you want to do the options what are the options i mouse my cursor down i hit enter there's intelligent ella code settings notice how quick that was control Q asks for it it searches it and it finds it okay this finds practically everything so whatever you want to do it will find theme notice the suggestions try theme okay change environment color themes oh there you go dark if I can change that right here and so it takes me right where I need to go based upon what I asked for so ctrl Q searches for practically anything it will find it for you and take you right there lets in the editor where it's mint code okay so ctrl Q really helpful now I know I told you 15 tips and I've already given you a bonus one or two in here but I want one more bonus one probably try to get more than this I thought 15 was probably enough and there's just more a show come down here to preview features vertical document tab layout some people really wanted this and I can see why let's measure show it to you so right now I have a lot of space left or right but not as much top to bottom so I can right-click on my tabs and say set tab layout to be left instead of top there we go now that's moved up a little bit and my tabs are now on the left I can even resize as I want to shrink it down or expand it I can switch to my items this means I have more room to see tabs and I have more vertical room on my monitor usually miners have less vertical room than they do horizontal room and so this allows you to make better use of your overall space on your miner if you want to do that kind of thing you don't like it no problem right click and say set layout back to top but again notice if I open up a lot of files there is this whole list of files now that are open that I don't see but if I right click set tab layout to left now be able to see all the open documents even though they wouldn't all show before because there wasn't there was just too many to open okay so I can just keep adding documents and it just keeps scrolling okay so that's a new feature of Visual Studio that's actually in a preview mode so you go to tools options under preview features you can check that box to enable that vertical tab our vertical document tab layout now there are a couple more features in this preview that might be of use to you one is load projects faster by having intellisense initialize in the background that means intellisense will not be available immediately when you open your application probably doesn't matter by doing that your project will load faster also auto-hide tool windows on startup so for example a toolbox or the data sources or sequel server object Explorer we can close all those are auto hide them except for a solution Explorer that makes the loading of visuals to go faster as well because it's not also populating those those windows okay so again a little bit more speed on startup using a couple of those preview features all right so that is a probably my 18 19 20 tips I shot for 15 but we got a little higher than that that's a bunch of tips on how to make your eddore even faster in Visual Studio there's a lot of power here's a lot of things you can do to really fly through this I already cut before so I didn't cover this time we have snippets as well so I actually you in a previous video how to create your own snippets and how to create your own item templates and soon we'll have a video on how to create your own project templates okay so there's a lot of things you can do to tweak your system the way you want andrey fly through the the setup stuff the basic stuff the the stuff that that makes it similar to everything else okay so code clamp really helps you make sure that your code is consistent across all your projects and in Teleco allows you to move faster as you're typing and the Eider config allows you to can keep those consistencies across your team with your application so all these tools built into Visual Studio don't cost a dime and can really make your life faster more efficient and more consistent I encourage you to try them out let me know what your favorites are down the comments but also let me know is there something else that you find really really helpful to making your eddore faster and more performance okay thanks for watching as always I am Tim quarry [Music] you
Info
Channel: IAmTimCorey
Views: 61,330
Rating: 4.9619327 out of 5
Keywords: visual studio tips and tricks, visual studio tips and tricks 2019, visual studio code productivity tips, iamtimcorey, tim corey, visual studio 2019, c#, c# tips, c# tips and tricks, c# tim corey, c# tips and tricks 2019, intellicode, intellicode refactoring, intellicode visual studio 2019, c# code cleanup, editorconfig, editorconfig visual studio, editorconfig tutorial, visual studio productivity
Id: qv6ZflueASY
Channel Id: undefined
Length: 75min 1sec (4501 seconds)
Published: Mon Dec 23 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.