Learn how to keep code that may be used in situations explained above or perhaps there is code found that was not needed but may be in the future.
This is a sample folder structure under C:\CodeStash
Then under C:\CodeStash\csharp
Note in the above image, there are other sub-folders which in this case are actual full projects while in the files shown are not connected to the other files as they are code snippet.
using
System;
System.ComponentModel;
namespace
WindowsFrontEnd.Extensions
{
public
static
class
ControlExtensions
void
InvokeIfRequired<T>(
this
T control, Action<T> action) where T : ISynchronizeInvoke
if
(control.InvokeRequired)
control.Invoke(
new
Action(() => action(control)),
null
);
}
else
action(control);
Now to find the code above with a few files in the C# folder simply look for a telltale name while when there are a lot of files use the "find in folder".
With the explorer bar showing in VS-Code, right click on the folder and start typing for a key word, in this case typing "invoke" might pull up a lot of results while the coder remembers "if" was in the (extension) method name and ands "if".
Click on a result to open the file. At this point copy the code to Visual Studio while in other cases the code may need modification and here the coder can either drop the code in and modify or make a copy in the resulting file, modify, copy to Visual Studio then clean up the result file.
function
password_check() {
pass = document.getElementById(
"password"
).value;
console.log(pass);
regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
(regex.exec(pass) ==
) {
alert(
'invalid password!'
)
console.log(
"valid"
To access the code stash from Visual Studio
In the following screenshot there are several menu items besides code stash, the others simply open specific folders where there are Visual Studio solutions. The beauty of VS-Code is one can open folders with projects so in the case code is needed that is not in the code stash they are available also.
Extensions that may assist with a code stash comparing to other code.
Not all files should be stored in a repository, for instance, if node.js library is within the code stash, it's replaceable so ignore it. Here is a sample ignore file
node_modules/*
.gitignore
In the above example a folder names node_modules will not be pushed to the GitHub repository for code stash. This can be done in the source control tab in VS-Code activity bar. Note the file name is .gitignore and is also in the ignore file thus not committed/pushed to the GitHub repository.
VS-Code is not simply for writing code but also for storing full project and code snippets which has been explained how to interact with Visual Studio.