<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ visual studio - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ visual studio - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 28 Jul 2026 20:13:12 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/visual-studio/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Visual Studio vs Visual Studio Code – What's The Difference Between These IDE Code Editors? ]]>
                </title>
                <description>
                    <![CDATA[ The first time I heard about “Visual Studio”, I thought it was the same as “Visual Studio Code”. I don’t know why Microsoft decided to confuse everyone with the names of those two development tools. But that’s a story for another day. “Visual Studio”... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/visual-studio-vs-visual-studio-code/</link>
                <guid isPermaLink="false">66adf24611a28b6eb378d2cd</guid>
                
                    <category>
                        <![CDATA[ editor ]]>
                    </category>
                
                    <category>
                        <![CDATA[ rich text editor ]]>
                    </category>
                
                    <category>
                        <![CDATA[ visual studio ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Visual Studio Code ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kolade Chris ]]>
                </dc:creator>
                <pubDate>Tue, 31 Jan 2023 19:17:31 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/01/VSvVSC.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>The first time I heard about “Visual Studio”, I thought it was the same as “Visual Studio Code”. I don’t know why Microsoft decided to confuse everyone with the names of those two development tools. But that’s a story for another day.</p>
<p>“Visual Studio” and “Visual Studio Code” are not the same thing. Visual Studio is an integrated development environment (IDE) and Visual Studio Code is a rich text editor like Sublime Text and Atom.</p>
<p>But the difference between the tools is more than just IDE and text editor. </p>
<p>An IDE is a robust tool for writing, editing, debugging, and running your code. A text editor only lets you write and edit your code. You might have to step out of a text editor to run your code or download plugins to help it do the running for you.</p>
<p>In this article, you'll learn the main differences between Visual Studio and Visual Studio Code. But firstly, we need to know what “Visual Studio” is and what “Visual Studio Code is” before diving into those differences. </p>
<h2 id="heading-what-well-cover">What We'll Cover</h2>
<ul>
<li><a class="post-section-overview" href="#heading-what-is-visual-studio">What is Visual Studio?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-visual-studio-code">What is Visual Studio Code?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-the-difference-between-visual-studio-and-visual-studio-code">What is the Difference between “Visual Studio” and “Visual Studio Code”?</a></li>
<li><a class="post-section-overview" href="#heading-which-should-you-choose-between-visual-studio-and-visual-studio-code">Which should you Choose between “Visual Studio” and “Visual Studio Code”?</a></li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></li>
</ul>
<h2 id="heading-what-is-visual-studio">What is Visual Studio?</h2>
<p>Visual Studio was first released in 1997 by Microsoft. It's an integrated development environment (IDE) for developing, editing, and debugging websites, web, and mobile applications as well as cloud services. </p>
<p>Because it's an IDE, programming utilities like a debugger, compiler, intellisence, and more are all bundled into it for you.</p>
<p>Visual Studio comes with built-in support for C# and .NET. It also supports other programming languages like C, C++, Python, F#, web languages (HTML, CSS, JavaScript), and a lot more. Support for Java was removed back in Visual Studio 2017.</p>
<p>Visual Studio runs on Windows and Mac. It has 3 editions – community, professional, and enterprise. The community version is free, while the professional and enterprise are not.</p>
<p>The installation is quite a bit more robust on Windows than Mac. So, on Windows, you might have to download more than 42 GB depending on what you want to do.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/Screenshot-2023-01-31-122422.png" alt="Screenshot-2023-01-31-122422" width="600" height="400" loading="lazy"></p>
<p>But on Mac, as of the time of writing this article, you need around 6.2 GB of disk space.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/Screenshot-2023-01-31-at-11.30.22.png" alt="Screenshot-2023-01-31-at-11.30.22" width="600" height="400" loading="lazy"> </p>
<h2 id="heading-what-is-visual-studio-code">What is Visual Studio Code?</h2>
<p>Visual Studio Code (also called VS Code) is like the mini version of Visual Studio. It is an open-source and lightweight text editor available on Windows, Mac, and Linux. There’s also the web version available at <code>https://vscode.dev/</code>.</p>
<p>VS Code comes with built-in support for JavaScript, TypeScript and Node JS, but you can use it to code in any language you want. All you need to do is download the relevant extensions. </p>
<p>Some of the extensions are made by Microsoft, but a lot of others are third-party extensions.</p>
<p>Unlike Visual Studio, you don’t need much space to download VS Code. You might not need more than 200 MB of disk space to download it. </p>
<p>Since it supports JavaScript, TypeScript, and Node JS by default, you get a debugger and intellisence, too. But to get intellisence, a compiler, and debuggers for other languages, you have to download relevant extensions.</p>
<p>Now you know that Visual Studio is an IDE and Visual Studio Code is a text editor. So let's summarize their main differences next.</p>
<h2 id="heading-what-is-the-difference-between-visual-studio-and-visual-studio-code">What is the Difference between “Visual Studio” and “Visual Studio Code”?</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Basis</strong></td><td><strong>Visual Studio</strong></td><td><strong>Visual Studio Code</strong></td></tr>
</thead>
<tbody>
<tr>
<td><strong>Type</strong></td><td>Visual Studio is a full-fledged IDE</td><td>VS Code is a text editor (AKA Code editor)</td></tr>
<tr>
<td><strong>Platform</strong></td><td>Visual Studio runs on Windows and Mac</td><td>VS Code runs on Windows, Mac, and Linux</td></tr>
<tr>
<td><strong>Size</strong></td><td>Visual Studio is relatively large. You might have to download more than 40 GB on Windows and over 6 GB on Mac</td><td>VS Code does not require more than 200 MB on any platform</td></tr>
<tr>
<td><strong>Support</strong></td><td>Visual Studio has built in support for C# and .NET, alongside several common languages apart from Java</td><td>VS Code supports JavaScript, Typescript, and Node JS out of the box. It also supports other programming languages – as long as there’s an extension(s) for that</td></tr>
<tr>
<td><strong>Pricing</strong></td><td>Visual Studio Community Edition is free, but the professional and enterprise editions code $45 and $250 per month respectively.</td><td>VS Code is free. Most of the extensions are also free but there are freemium ones</td></tr>
<tr>
<td><strong>Extensions</strong></td><td>Visual Studio does not have as many extensions as VS Code</td><td>VS Code has numerous professionally and curated extensions for various purposes</td></tr>
</tbody>
</table>
</div><h2 id="heading-which-should-you-choose-between-visual-studio-and-visual-studio-code">Which should you Choose between “Visual Studio” and “Visual Studio Code”?</h2>
<p>There has been a long-running debate about which is better and which to choose between Visual Studio and Visual Studio Code. Well, it depends on what you are doing.</p>
<p>If you’re developing exclusively with a language supported by Visual Studio such as C#, C, C++, Python, and others, Visual Studio or other relevant IDEs are likely the best option for you. </p>
<p>But even if you’re developing in those languages but you require a React, Vue, or Angular frontend, VS code might be the best option for you.</p>
<p>If you’re working in a team, they might provide you with the enterprise version of Visual Studio, or any other IDE that correlates with the language you are working with. For example, PyCharm for Python and IntelliJ Idea for Java.</p>
<p>If you’re using Linux, you have to choose Visual Studio Code or some other IDE apart from Visual Studio. That’s because Visual Studio does not run on Linux.</p>
<p>If you’re the kind of person that likes to customize your editor to your taste, just go for VS Code because it's highly customizable. You also should probably choose VS Code if you are mixing technologies.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>This article showed you the differences between Visual Studio and VS Code, and also what they both are separately.</p>
<p>The debate should never be which one is better than the other, but which is best for what you want to do, or what you need. That’s why we looked at some scenarios that might encourage you to choose one over the other.</p>
<p>Thank you for reading.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Automatically Generate C# Code Snippets in Visual Studio ]]>
                </title>
                <description>
                    <![CDATA[ By Gilad Bar Ilan When you use code snippets in Visual Studio, it can make your coding process a lot easier and faster. But what are code snippets? And how can you use them? In this article, we'll look at how you can create code snippets in C#. Just ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-automatically-generate-code-snippets-visual-studio/</link>
                <guid isPermaLink="false">66d45ede4a7504b7409c33d9</guid>
                
                    <category>
                        <![CDATA[ automation ]]>
                    </category>
                
                    <category>
                        <![CDATA[ C ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Productivity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Snippet ]]>
                    </category>
                
                    <category>
                        <![CDATA[ visual studio ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 09 Jul 2021 18:28:18 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/07/gbi.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Gilad Bar Ilan</p>
<p>When you use code snippets in Visual Studio, it can make your coding process a lot easier and faster. But what are code snippets? And how can you use them?</p>
<p>In this article, we'll look at how you can create code snippets in C#. Just keep in mind that snippets are available in other languages in Visual Studio as well.</p>
<p>If you already know what code snippets are, then you can skip down to the <strong>“How to Auto-Generate Code Snippets”</strong> section.</p>
<h2 id="heading-what-are-code-snippets">What are Code Snippets?</h2>
<p>If you regularly work with Visual Studio, you might already know what code snippets are. Code snippets represent a shortcut for a larger piece of code. </p>
<p>As an example, open a C# project in Visual Studio and write “for” and then press the tab key twice. As you can see, instead of writing the full for loop we created a for loop just by writing “for”.</p>
<p>There are a lot more pre-defined code snippets you can use. For example, if you write “cw” and then press the tab key twice you’ll see an auto-completion that writes this:</p>
<pre><code class="lang-cs">Console.WriteLine();
</code></pre>
<p>You can check out the full list of the pre-defined code snippets in the docs here:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://docs.microsoft.com/en-us/visualstudio/ide/visual-csharp-code-snippets?view=vs-2019">https://docs.microsoft.com/en-us/visualstudio/ide/visual-csharp-code-snippets?view=vs-2019</a></div>
<h2 id="heading-how-to-create-custom-code-snippets">How to Create Custom Code Snippets</h2>
<p>Now that you understand what a code snippet is, we can now go over how to create one.</p>
<p>To create your first code snippet, create a “.snippet” file. I called my file “MySnippet.snippet”, but you can call it whatever you want.</p>
<p>After the creation of the code snippet file, open the file in Visual Studio and add the following piece of code into the file.</p>
<pre><code class="lang-xml"><span class="hljs-meta">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">CodeSnippets</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">""</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">CodeSnippet</span> <span class="hljs-attr">Format</span>=<span class="hljs-string">"1.0.0"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">Header</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Title</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">Title</span>&gt;</span>    
            <span class="hljs-tag">&lt;<span class="hljs-name">Author</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">Author</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Description</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">Description</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Shortcut</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">Shortcut</span>&gt;</span> 
        <span class="hljs-tag">&lt;/<span class="hljs-name">Header</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">Snippet</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Code</span> <span class="hljs-attr">Language</span>=<span class="hljs-string">""</span>&gt;</span>
                &lt;![CDATA[]]&gt;
            <span class="hljs-tag">&lt;/<span class="hljs-name">Code</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">Snippet</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">CodeSnippet</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">CodeSnippets</span>&gt;</span>
</code></pre>
<p>In the example above, we use the basic structure of a code snippet file. Now, we’ll edit it and create a code snippet that will convert “cr” to <code>Console.ReadLine()</code>.</p>
<h4 id="heading-title-tag">Title Tag</h4>
<p>The title tag contains the title of the snippet (not the shortcut name). In this example we’ll call the title “ReadLineSnippet”.</p>
<h4 id="heading-author-tag">Author Tag</h4>
<p>In the Author tag, you can insert your name/company to get credit for the snippet creation.</p>
<h4 id="heading-description-tag">Description Tag</h4>
<p>In the description tag, insert a short description of what the snippet does exactly.</p>
<h4 id="heading-shortcut-tag">Shortcut Tag</h4>
<p>The name in the shortcut tag is the name that calls the larger piece of code. For example:</p>
<pre><code class="lang-cs">cw -&gt; Console.WriteLine();
</code></pre>
<p>The “cw” is specified as the name in the shortcut tag.</p>
<h4 id="heading-language">Language</h4>
<p>Because we're working with C# we should specify that in the language:</p>
<pre><code class="lang-cs">&lt;Code Language = <span class="hljs-string">"CSharp"</span>&gt;
</code></pre>
<h4 id="heading-">&lt;![CDATA[]]&gt;</h4>
<p>The &lt;![CDATA[]]&gt; holds the value of our snippet. In our example, inside the squared brackets we’ll insert <code>Console.ReadLine()</code> like this:</p>
<pre><code class="lang-cs">&lt;![CDATA[Console.ReadLine();]]&gt;
</code></pre>
<h3 id="heading-additional-code-snippet-options">Additional Code Snippet Options</h3>
<h4 id="heading-defining-variables">Defining Variables:</h4>
<p>We can also define variables and give them a default value. By defining a variable we can use it multiple times in the snippet, and we give the user the option to change all the occurrences of the default value at once.</p>
<p>For example, if our snippet creates the following code:</p>
<pre><code class="lang-cs">arr -&gt; 
Object[] arr = <span class="hljs-keyword">new</span> Object[<span class="hljs-number">100</span>];
<span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; arr.Length; i++)
{   
    arr[i] = <span class="hljs-keyword">default</span>(Object);
}
</code></pre>
<p>And we define “Object” as a variable, we can replace all its occurrences. All we need to do is to write in the first occurrence a different name – for example “int” – and then tab twice and it will turn all occurrences of “Object” to “int”.</p>
<p>If we had defined <code>arr</code> as a variable too, we could move from one variable to another by pressing tab (when you create the snippet the first variable will be selected in red/cyan color – you can move to the other by pressing tab).</p>
<h3 id="heading-how-to-define-a-variable">How to define a variable</h3>
<pre><code class="lang-xml"><span class="hljs-meta">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">CodeSnippets</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">""</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">CodeSnippet</span> <span class="hljs-attr">Format</span>=<span class="hljs-string">"1.0.0"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">Header</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Title</span>&gt;</span>init array.<span class="hljs-tag">&lt;/<span class="hljs-name">Title</span>&gt;</span>    
            <span class="hljs-tag">&lt;<span class="hljs-name">Author</span>&gt;</span>Gilad Bar-Ilan<span class="hljs-tag">&lt;/<span class="hljs-name">Author</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Description</span>&gt;</span>creates and initializes an array.<span class="hljs-tag">&lt;/<span class="hljs-name">Description</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Shortcut</span>&gt;</span>myArr<span class="hljs-tag">&lt;/<span class="hljs-name">Shortcut</span>&gt;</span> 
        <span class="hljs-tag">&lt;/<span class="hljs-name">Header</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">Snippet</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Code</span> <span class="hljs-attr">Language</span>=<span class="hljs-string">"CSharp"</span>&gt;</span>
                &lt;![CDATA[$typeName$[] $varName$ = new $typeName$[100];
                for(int $i$ = 0; $i$ &lt; $varName$.Length; $i$++)
                {
                  $varName$[$i$] = default($typeName$);
                }]]&gt;
            <span class="hljs-tag">&lt;/<span class="hljs-name">Code</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Declarations</span>&gt;</span>      
                <span class="hljs-tag">&lt;<span class="hljs-name">Literal</span>&gt;</span>      
                    <span class="hljs-tag">&lt;<span class="hljs-name">ID</span>&gt;</span>varName<span class="hljs-tag">&lt;/<span class="hljs-name">ID</span>&gt;</span>      
                    <span class="hljs-tag">&lt;<span class="hljs-name">ToolTip</span>&gt;</span>variable name.<span class="hljs-tag">&lt;/<span class="hljs-name">ToolTip</span>&gt;</span>         
                    <span class="hljs-tag">&lt;<span class="hljs-name">Default</span>&gt;</span>arr<span class="hljs-tag">&lt;/<span class="hljs-name">Default</span>&gt;</span>        
                <span class="hljs-tag">&lt;/<span class="hljs-name">Literal</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">Literal</span>&gt;</span>      
                    <span class="hljs-tag">&lt;<span class="hljs-name">ID</span>&gt;</span>typeName<span class="hljs-tag">&lt;/<span class="hljs-name">ID</span>&gt;</span>      
                    <span class="hljs-tag">&lt;<span class="hljs-name">ToolTip</span>&gt;</span>type name.<span class="hljs-tag">&lt;/<span class="hljs-name">ToolTip</span>&gt;</span>         
                    <span class="hljs-tag">&lt;<span class="hljs-name">Default</span>&gt;</span>Object<span class="hljs-tag">&lt;/<span class="hljs-name">Default</span>&gt;</span>        
                <span class="hljs-tag">&lt;/<span class="hljs-name">Literal</span>&gt;</span>
                 <span class="hljs-tag">&lt;<span class="hljs-name">Literal</span>&gt;</span>      
                    <span class="hljs-tag">&lt;<span class="hljs-name">ID</span>&gt;</span>i<span class="hljs-tag">&lt;/<span class="hljs-name">ID</span>&gt;</span>      
                    <span class="hljs-tag">&lt;<span class="hljs-name">ToolTip</span>&gt;</span>iterator name.<span class="hljs-tag">&lt;/<span class="hljs-name">ToolTip</span>&gt;</span>         
                    <span class="hljs-tag">&lt;<span class="hljs-name">Default</span>&gt;</span>i<span class="hljs-tag">&lt;/<span class="hljs-name">Default</span>&gt;</span>        
                <span class="hljs-tag">&lt;/<span class="hljs-name">Literal</span>&gt;</span>
             <span class="hljs-tag">&lt;/<span class="hljs-name">Declarations</span>&gt;</span>     
        <span class="hljs-tag">&lt;/<span class="hljs-name">Snippet</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">CodeSnippet</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">CodeSnippets</span>&gt;</span>
</code></pre>
<p>As you can see in the example above, each variable we use needs to be inside the <code>&lt;Literal&gt;</code> tag under the <code>&lt;Declarations&gt;</code> tag.</p>
<ul>
<li><code>&lt;ID&gt;</code>  — How we call the variable in the <code>&lt;![CDATA[]]&gt;</code></li>
<li><code>&lt;ToolTip&gt;</code> — A short description of the variable.</li>
<li><code>&lt;Default&gt;</code>  — The default value of the variable.</li>
</ul>
<p><strong>NOTE</strong> — When you use a variable in the <code>&lt;![CDATA[]]&gt;</code> you should write it in the following structure: <code>$&lt;here you put the variable name&gt;$</code>.</p>
<h3 id="heading-how-to-add-the-code-snippet-to-your-project">How to add the code snippet to your project</h3>
<p>After we’ve created our code snippet file, we want to use it in our projects. To do so we should put the file inside the custom snippet folder of Visual Studio. This will automatically add the code snippet to our project.</p>
<p>If you want to find the folder path:</p>
<ul>
<li>Open a C# project.</li>
<li>Go to Tools -&gt; Code Snippets Manager</li>
<li>Copy the path you see in the head of the box opened where it says “Location”.</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/image-200.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>After you’ve got the path, simply add the file into the path.</p>
<p><strong>NOTE —</strong> Your “My Code Snippets” folder may be located in a different place on your computer, so don't rely on the path in the picture.</p>
<h2 id="heading-how-to-auto-generate-code-snippets">How to Auto-Generate Code Snippets</h2>
<p>Now we can now go over what it means to auto-generate code snippets.</p>
<p>We know that adding “.snippet” files into the “My Code Snippets” folder adds the snippets automatically into our project. So now we can use that behaviour to create code that will automatically create snippet files and add them to our project.</p>
<h3 id="heading-what-kind-of-code-snippets-do-we-want">What kind of code snippets do we want?</h3>
<p>In this project, we are going to create a snippet for objects with a default constructor where the shortcut name will be the type name. For example:</p>
<pre><code class="lang-cs">Random + tab twice -&gt; Random random = <span class="hljs-keyword">new</span> Random();
</code></pre>
<p>The idea of the project is to read the namespaces we use in our project and make a custom snippet for each object that follows the conditions. </p>
<p>We want to add the snippets for the types of every namespace we use. This means that even if we specify a namespace in the ‘using’ but don’t use any of its objects, we’ll still include a code snippet for its members (those who follow the condition).</p>
<p>In addition to the namespaces, we are also going to create a snippet for our defined types.</p>
<h4 id="heading-things-we-need-to-take-care-of">Things we need to take care of:</h4>
<ul>
<li>Remove the no longer needed types’ code snippets (if we removed types we’ve created or removed namespaces from the project).</li>
<li>Update the code snippets every time the user runs the program (we don’t update in the background).</li>
<li>Add new snippets for new namespaces we use / types we create.</li>
<li>Make a structure for the types’ code snippet.</li>
</ul>
<h3 id="heading-how-to-get-all-of-our-defined-objects">How to get all of our defined objects</h3>
<p>If we want to get the full list of the user-defined types there are two ways to do so.</p>
<p>The first way – which is not as good as the second – is by using Regular Expressions. By using regular expressions, we can go over each file in our project and match for a default constructor in a class/declaration of a struct (because structs always have a default constructor).</p>
<h4 id="heading-problems-with-the-regex-technique">Problems with the Regex technique</h4>
<p>If the user separates the files we can check before using the regex if the file was modified. By doing that we can avoid repeating files that haven’t been modified.</p>
<p>But minor changes in the file will cause us to read the file again even if there is no difference in the objects. It'll also result in unorganized files that have a lot of code in a single file which can cause us to read the file over and over. (If the whole code is in a single file or just a few we won’t be able to avoid reading unchanged parts from the code.)</p>
<h4 id="heading-the-second-technique-reflection">The Second Technique — Reflection</h4>
<p>Instead of using Regex we can use reflection and get the classes we created by reading the metadata instead of reading each file as a text.</p>
<pre><code class="lang-cs">
        <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;summary&gt;</span></span>
        <span class="hljs-comment"><span class="hljs-doctag">///</span> Returns a list of all the types we created.</span>
        <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;/summary&gt;</span></span>
        <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;returns&gt;</span><span class="hljs-doctag">&lt;/returns&gt;</span></span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> List&lt;Type&gt; <span class="hljs-title">GetCustomTypes</span>(<span class="hljs-params"></span>)</span>
        {
            StackTrace myStackTrace = <span class="hljs-keyword">new</span> StackTrace();

            <span class="hljs-comment">//contains the name of the namesapce of the project</span>
            <span class="hljs-comment">//using stackframe we get's the first calling method (main - the bottom of the stack) and then we check the namespace of the type where the method is located.</span>
            <span class="hljs-comment">//in our case main is located under 'Program' then we check what is the namespace of Program.</span>
            <span class="hljs-keyword">string</span> namespace_ = myStackTrace.GetFrame(myStackTrace.FrameCount - <span class="hljs-number">1</span>).GetMethod().DeclaringType.Namespace;

            Assembly assembly = Assembly.GetExecutingAssembly();

            <span class="hljs-comment">//holds all the custom types.</span>
            <span class="hljs-comment">//assembly.GetTypes() =&gt; returns all the types.</span>
            <span class="hljs-comment">//then we remove all the types which is not related to our namesapce.</span>
            <span class="hljs-comment">//then we remove all the compiler created types.</span>
            <span class="hljs-comment">//then we remove all the types which doesn't have a default constructor.</span>
            <span class="hljs-keyword">var</span> types = assembly.GetTypes().Where(x =&gt; x.Namespace == namespace_).Where(x =&gt; !x.Name.Contains(<span class="hljs-string">"&lt;&gt;c"</span>))
                        .Where(x =&gt; x.GetConstructors().Any(x =&gt; x.GetParameters().Length == <span class="hljs-number">0</span>));
            <span class="hljs-keyword">return</span> types.ToList();
        }
</code></pre>
<h3 id="heading-how-to-get-the-libraries-objects">How to get the libraries’ objects</h3>
<p>We'll run into a lot of problems in this part of the project. Let's look at what might go wrong.</p>
<h4 id="heading-problem-1">Problem 1</h4>
<p>If we read the assemblies we use in our project using Reflection we won’t have the option to get the types from libraries we defined in the ‘using’ but that we don’t actually use. For example:</p>
<pre><code class="lang-cs"><span class="hljs-keyword">using</span> System.Linq;
<span class="hljs-keyword">using</span> System.IO;
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span>
{  
    <span class="hljs-keyword">int</span>[] arr = Enumerable.Range(<span class="hljs-number">0</span>,<span class="hljs-number">100</span>).ToArray(); <span class="hljs-comment">//Linq's functionallity</span>
}
</code></pre>
<p>In the example above ,we only use Linq functionality, which means that if we are going to read the used assemblies in the project we won’t see System.IO even though we want it to be shown.</p>
<h4 id="heading-problem-2">Problem 2</h4>
<p>Another possible problem happens even when we do use the library. This is because a namespace can have multiple assemblies and due to efficiency the compiler won’t call all the assemblies when it doesn’t need to. So even if we use the library it doesn't mean we’ll have all the assemblies.</p>
<h4 id="heading-how-can-we-solve-the-problem">How can we solve the problem?</h4>
<p>This problem is complicated because we cannot change the way the compiler works. So if we want to solve the problem we’ll have to be creative.</p>
<p>Our solution won't be very efficient, but we don’t have a lot of options for how to solve this.</p>
<h4 id="heading-we-can-use-an-algorithm">We can use an algorithm</h4>
<ul>
<li>We get all the namespaces we use in all of our “.cs” files in the project.</li>
<li>Then we iterate over all the System DLL files and we check if the types there relate to one of the namespaces we use in the project.</li>
<li>We add to this list also our defined types, as well as references we added to the project, if the reference is defined in the ‘using’ we add his types even if we don‘t use his types in the program itself.</li>
<li>After we do that we check if the type has a default constructor.</li>
</ul>
<p>The code for solving the problem is quite complicated, so let’s go over it.</p>
<pre><code class="lang-cs"><span class="hljs-keyword">using</span> System;
<span class="hljs-keyword">using</span> System.Reflection;
<span class="hljs-keyword">using</span> System.Linq;
<span class="hljs-keyword">using</span> System.IO;
<span class="hljs-keyword">using</span> System.Collections.Generic;
<span class="hljs-keyword">using</span> System.Diagnostics;
<span class="hljs-keyword">using</span> System.Text.RegularExpressions;

<span class="hljs-keyword">namespace</span> <span class="hljs-title">Reader</span>
{
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">TypeReader</span>
    {
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> List&lt;Type&gt; <span class="hljs-title">GetAllTypes</span>(<span class="hljs-params"></span>)</span>
        {
            <span class="hljs-meta">#<span class="hljs-meta-keyword">region</span> GetSystemLibrary Files</span>
            <span class="hljs-keyword">string</span> systemDllPath = <span class="hljs-keyword">typeof</span>(<span class="hljs-keyword">string</span>).Assembly.Location; <span class="hljs-comment">//gets the dll of the string type.</span>
            systemDllPath = Path.GetDirectoryName(systemDllPath);
            <span class="hljs-keyword">string</span>[] systemLibraries = Directory.GetFiles(systemDllPath); <span class="hljs-comment">//the list of the system libraies dlls.  </span>
            <span class="hljs-meta">#<span class="hljs-meta-keyword">endregion</span></span>

            <span class="hljs-meta">#<span class="hljs-meta-keyword">region</span> Namespaces in project files.</span>
            <span class="hljs-keyword">string</span>[] namespaces_ = Directory.GetFiles(GetSourceCodePath())
                                      .Where(x =&gt; x.EndsWith(<span class="hljs-string">".cs"</span>)).ToArray();
            namespaces_ = GetNamespaces(namespaces_).ToArray();<span class="hljs-comment">//we remove the semi colon</span>
            <span class="hljs-meta">#<span class="hljs-meta-keyword">endregion</span></span>

            <span class="hljs-meta">#<span class="hljs-meta-keyword">region</span> Check the system libraries.</span>
            List&lt;Type&gt; types = systemLibraries.Where(x =&gt; x.EndsWith(<span class="hljs-string">".dll"</span>)).Select(x =&gt;
            {
                Assembly asm = <span class="hljs-literal">null</span>;
                <span class="hljs-keyword">try</span>
                {
                    asm = Assembly.LoadFile(x);

                }
                <span class="hljs-keyword">catch</span>
                {
                    asm = <span class="hljs-literal">null</span>;
                }

                <span class="hljs-keyword">return</span> asm;
            }).SelectMany(x =&gt; x != <span class="hljs-literal">null</span> ? x.GetTypes() : <span class="hljs-keyword">new</span> Type[] { })
                        .Where(x =&gt; x != <span class="hljs-literal">null</span> &amp;&amp; !x.Name.Contains(<span class="hljs-string">"&lt;&gt;c"</span>)).Where(x =&gt; namespaces_.Contains(x.Namespace))
                        .Where(x =&gt; x.IsPublic &amp;&amp; (x.IsClass || x.IsValueType)).ToList();
            <span class="hljs-meta">#<span class="hljs-meta-keyword">endregion</span></span>

            <span class="hljs-meta">#<span class="hljs-meta-keyword">region</span> add assemblies we use in our program.</span>
            types.AddRange(AppDomain.CurrentDomain.GetAssemblies()
                           .SelectMany(x =&gt; x.GetTypes().Where(x =&gt; !x.Name.Contains(<span class="hljs-string">"&lt;&gt;c"</span>)).Where(x =&gt; namespaces_.Contains(x.Namespace)))
                           .Where(x =&gt; x.IsPublic &amp;&amp; (x.IsClass || x.IsValueType)));
            <span class="hljs-meta">#<span class="hljs-meta-keyword">endregion</span></span>

            <span class="hljs-meta">#<span class="hljs-meta-keyword">region</span> add custom types we created.</span>
            types.AddRange(GetCustomTypes()); <span class="hljs-comment">//adds our custom created snippets</span>
            <span class="hljs-meta">#<span class="hljs-meta-keyword">endregion</span></span>

            <span class="hljs-meta">#<span class="hljs-meta-keyword">region</span> add types belongs to refrences we didn't use in our project.</span>
            types.AddRange(GetUnUsedRefrenecedTypes(namespaces_)); <span class="hljs-comment">//adds the refrenced libraries we specify but don't use.</span>
            <span class="hljs-meta">#<span class="hljs-meta-keyword">endregion</span></span>

            <span class="hljs-meta">#<span class="hljs-meta-keyword">region</span> filter types.</span>
            types = types.Where(x =&gt; x.IsValueType || x.GetConstructors().Any(x =&gt; x.GetParameters().Length == <span class="hljs-number">0</span>)).ToList();
            <span class="hljs-meta">#<span class="hljs-meta-keyword">endregion</span></span>

            <span class="hljs-meta">#<span class="hljs-meta-keyword">region</span> remove duplicated type names.</span>
            types = types.GroupBy(x =&gt; x.FullName).Select(x =&gt; x.First()).ToList();
            <span class="hljs-meta">#<span class="hljs-meta-keyword">endregion</span></span>

            <span class="hljs-keyword">return</span> types;
        }

        <span class="hljs-comment">//Returns the assembly of the main function.</span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">string</span> <span class="hljs-title">GetMainAssemblyLocation</span>(<span class="hljs-params"></span>)</span>
        {
            StackTrace main = <span class="hljs-keyword">new</span> StackTrace();
            <span class="hljs-keyword">string</span> path = main.GetFrame(main.FrameCount - <span class="hljs-number">1</span>).GetMethod().DeclaringType.Assembly.Location;
            <span class="hljs-keyword">return</span> Path.GetDirectoryName(path);
        }

        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">string</span> <span class="hljs-title">GetSourceCodePath</span>(<span class="hljs-params"></span>)</span>
        {
            <span class="hljs-keyword">string</span> projectPath = GetMainAssemblyLocation();

            <span class="hljs-keyword">try</span>
            {
                <span class="hljs-keyword">while</span> (!Directory.GetFiles(projectPath).Any(x =&gt; x.EndsWith(<span class="hljs-string">".cs"</span>)))
                {
                    projectPath = projectPath.Remove(projectPath.LastIndexOf(<span class="hljs-string">"\\"</span>));
                }
            }
            <span class="hljs-keyword">catch</span>
            {
                <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> SourceCodeNotFoundException();
            }

            <span class="hljs-keyword">return</span> projectPath;
        }

        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> List&lt;<span class="hljs-keyword">string</span>&gt; <span class="hljs-title">GetNamespaces</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] files</span>)</span>
        {
            List&lt;<span class="hljs-keyword">string</span>&gt; namespaces = <span class="hljs-keyword">new</span> List&lt;<span class="hljs-keyword">string</span>&gt;();

            <span class="hljs-keyword">foreach</span> (<span class="hljs-keyword">string</span> file_ <span class="hljs-keyword">in</span> files)
            {
                StreamReader fileStream = <span class="hljs-keyword">new</span> StreamReader(file_);
                Regex matchUsing = <span class="hljs-keyword">new</span> Regex(<span class="hljs-string">@"using([ ]|\t|\n)+\S+;"</span>);
                <span class="hljs-keyword">string</span>[] fileNamespaces = matchUsing.Matches(fileStream.ReadToEnd()).Select(x =&gt; x.Value)
                                          .Select(x =&gt; x.Remove(x.IndexOf(<span class="hljs-string">"using"</span>), <span class="hljs-string">"using"</span>.Length).Trim()).ToArray();
                namespaces.AddRange(fileNamespaces);

                fileStream.Close();
            }

            <span class="hljs-keyword">return</span> namespaces.Select(x =&gt; x.Remove(x.Length - <span class="hljs-number">1</span>, <span class="hljs-number">1</span>)).Distinct().ToList();
        }

        <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;summary&gt;</span></span>
        <span class="hljs-comment"><span class="hljs-doctag">///</span> This is used in case we have a custom refrenced library (could be a dll we created)</span>
        <span class="hljs-comment"><span class="hljs-doctag">///</span> and we specify that in the using, however, we don't use his assemblies.</span>
        <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;/summary&gt;</span></span>
        <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;returns&gt;</span><span class="hljs-doctag">&lt;/returns&gt;</span></span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> List&lt;Type&gt; <span class="hljs-title">GetUnUsedRefrenecedTypes</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] namespaces_</span>)</span>
        {
            <span class="hljs-keyword">string</span> sourceCode = GetMainAssemblyLocation();
            List&lt;Type&gt; otherTypes = <span class="hljs-keyword">new</span> List&lt;Type&gt;();

            <span class="hljs-keyword">string</span>[] fileNames = Directory.GetFiles(Path.GetDirectoryName(sourceCode));

            <span class="hljs-keyword">if</span> (fileNames.Any(x =&gt; x.EndsWith(<span class="hljs-string">".dll"</span>)))
            {
                fileNames = fileNames.Where(x =&gt; x.EndsWith(<span class="hljs-string">".dll"</span>)).ToArray();

                <span class="hljs-keyword">foreach</span> (<span class="hljs-keyword">var</span> file <span class="hljs-keyword">in</span> fileNames)
                {
                    Assembly asm;

                    <span class="hljs-keyword">try</span>
                    {
                        asm = Assembly.LoadFile(file);
                    }
                    <span class="hljs-keyword">catch</span>
                    {
                        <span class="hljs-keyword">continue</span>;
                    }

                    otherTypes.AddRange(asm.GetTypes().Where(x =&gt; !x.Name.Contains(<span class="hljs-string">"&lt;&gt;c"</span>))
                                        .Where(x =&gt; x.IsPublic &amp;&amp; (x.IsClass || x.IsValueType))
                                        .Where(x =&gt; namespaces_.Contains(x.Namespace)).GroupBy(x =&gt; x.Name)
                                        .Select(x =&gt; x.First()));
                }
            }

            <span class="hljs-keyword">return</span> otherTypes;
        }

        <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;summary&gt;</span></span>
        <span class="hljs-comment"><span class="hljs-doctag">///</span> Returns a list of all the types we created.</span>
        <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;/summary&gt;</span></span>
        <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;returns&gt;</span><span class="hljs-doctag">&lt;/returns&gt;</span></span>
        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> List&lt;Type&gt; <span class="hljs-title">GetCustomTypes</span>(<span class="hljs-params"></span>)</span>
        {
            StackTrace myStackTrace = <span class="hljs-keyword">new</span> StackTrace();
            Type mainType = myStackTrace.GetFrame(myStackTrace.FrameCount - <span class="hljs-number">1</span>).GetMethod().DeclaringType;

            <span class="hljs-comment">//contains the name of the namesapce of the project</span>
            <span class="hljs-comment">//using stackframe we get's the first calling method (main - the bottom of the stack) and then we check the namespace of the type where the method is located.</span>
            <span class="hljs-comment">//in our case main is located under 'Program' then we check what is the namespace of Program.</span>
            <span class="hljs-keyword">string</span> namespace_ = mainType.Namespace;
            Assembly assembly = mainType.Assembly;

            <span class="hljs-comment">//holds all the custom types.</span>
            <span class="hljs-comment">//assembly.GetTypes() =&gt; returns all the types.</span>
            <span class="hljs-comment">//then we remove all the types which is not related to our namesapce.</span>
            <span class="hljs-comment">//then we remove all the compiler created types.</span>
            <span class="hljs-comment">//then we remove all the types which doesn't have a default constructor.</span>
            <span class="hljs-keyword">var</span> types = assembly.GetTypes().Where(x =&gt; x.Namespace == namespace_).Where(x =&gt; !x.Name.Contains(<span class="hljs-string">"&lt;&gt;c"</span>)); ;
            <span class="hljs-keyword">return</span> types.ToList();
        }
    }

    <span class="hljs-keyword">internal</span> <span class="hljs-keyword">class</span> <span class="hljs-title">SourceCodeNotFoundException</span> : <span class="hljs-title">Exception</span>
    {
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">string</span> Message =&gt; <span class="hljs-string">"Could not load the '.cs' files, please make sure\n"</span> +
                                    <span class="hljs-string">"your files located in the default place / you have a valid project type."</span>;
    }
}
</code></pre>
<h4 id="heading-important-note"><strong>Important Note:</strong></h4>
<pre><code class="lang-cs"><span class="hljs-comment">//If I mention in the explanation the words "main function" I mean:</span>

<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span>
{   
    TypeReader.GetAllTypes();
}
<span class="hljs-comment">//Which means that the main function does not located in the </span>
<span class="hljs-comment">//TypeReader class it's the main function who calls the class.</span>
</code></pre>
<h3 id="heading-getsystemlibrary-files-region">GetSystemLibrary Files Region</h3>
<p>In these lines, we get all the library files of “System”.</p>
<ul>
<li>We check where the assembly of one of the system DLLs is located (in our case where the assembly of ‘string’ is).</li>
<li>Then we remove the file name from the path so we’ll have only the directory.</li>
<li>Then we take only the library files from the directory (“.dll”).</li>
</ul>
<p>We do so because all of the System libraries files are located in the same directory.</p>
<h3 id="heading-namespaces-in-the-project-files-region">Namespaces in the project files Region</h3>
<p>In these lines, we get all the namespaces we use in all of our project files.</p>
<h4 id="heading-custom-methods-we-use-in-these-lines">Custom methods we use in these lines</h4>
<p><strong>GetSourceCodePath —</strong> This function returns the path of our source code. First, we get the path of the main function’s dll. By assuming that the user works with the default way of sorting directories in Visual Studio, we ‘remove’ directories from our path until we reach a directory with .cs files.</p>
<p><strong>GetMainAssemblyLocation</strong> — We use StackTrace to get the assembly location of the main function. An example for 'Removing' is<br>C:\Users\File1\File2 -&gt; C:\Users\File1</p>
<p>If we can’t find any directory we throw <strong>SourceCodeNotFoundException</strong>.</p>
<p><strong>GetNamespaces —</strong> The method returns all the namespaces within the files we entered. It iterates over each file and reads all the namespaces we are using in each one of them using Regex.</p>
<p>For each namespace we’ll get <code>using &lt;Something&gt;;</code> then we’ll remove all of the extra characters and we only keep the <code>&lt;Something&gt;</code>.</p>
<h4 id="heading-in-getalltypes">In GetAllTypes</h4>
<ul>
<li>We read all the files from our source code directory</li>
<li>We only keep the files with an extension of “.cs”</li>
<li>We get the namespaces of the files.</li>
</ul>
<h3 id="heading-check-the-system-libraries-region">Check the system libraries Region</h3>
<p>In these lines, we check the system libraries. These lines fix both problems we mentioned before.</p>
<ul>
<li>We get all the files in the system DLL's directory and we only keep those that represent a dll (with an extension of “.dll”).</li>
<li>We try to load each one of these files.</li>
<li>If we can load the file then we get the types in the assembly.</li>
<li>We remove all the compiler created types “&lt;&gt;c”.</li>
<li>We only keep the types related to one of the namespaces in our project.</li>
<li>Then we only keep the public types and those that are class or struct.</li>
</ul>
<h4 id="heading-why-do-we-do-it-like-this">Why do we do it like this?</h4>
<p>The problems we mentioned before were caused because we tried to check what the program <strong>actually</strong> uses in runtime. But the compiler makes optimizations, and that’s why we cannot really reach the cases mentioned in the problems.</p>
<p>So for solving this problem, we need to get creative and check the namespaces we use in our project files. Then we load the assemblies, and at the end check that each type if its namespace is one of the namespaces we use in our project.</p>
<h3 id="heading-add-assemblies-we-use-in-our-program-region">add assemblies we use in our program Region</h3>
<p>In these lines, we add the assemblies we use in our program.</p>
<p>For each one of the assemblies, we make the same check for the type it contains.</p>
<ul>
<li>If the type is public</li>
<li>If it’s struct or class</li>
<li>If it’s not a compiler-created type.</li>
<li>If it’s related to one of the namespaces we use in our project.</li>
</ul>
<h3 id="heading-add-custom-types-we-created-region">add custom types we created Region</h3>
<p>In this line, we add all of the custom types we’ve created.</p>
<p><strong>GetCustomTypes —</strong> The function uses StackTrace for getting the namespace and the assembly of the main function.</p>
<p>After we have the assembly we get the types that related to the main’s namespace.</p>
<h3 id="heading-add-types-belongs-to-references-we-didnt-use-in-our-program-region">add types belongs to references we didn't use in our program Region</h3>
<p>In this line, we add the types that belong to references we didn’t use in the program and that were specified in the ‘using’ (just like we did for the system types, but this time we do that for the references we added manually, not ‘System’).</p>
<p><strong>GetUnUsedReferencedTypes</strong> </p>
<ul>
<li>We go over the source code directory (the manually added references located there).</li>
<li>We try to load the ‘.dll’ files and add all the types that pass the conditions we did in previous checks in main.</li>
</ul>
<h3 id="heading-filter-types-region">filter types Region</h3>
<p>In this line, we only keep value types and classes that have a default constructor (if they are value types they have a default constructor for sure).</p>
<h3 id="heading-remove-duplicated-type-names-region">remove duplicated type names Region</h3>
<p>We remove duplicated types by name.</p>
<h2 id="heading-how-to-build-the-snippets">How to Build the Snippets</h2>
<p>We've gotten through the hard part, so now it’s time to build the snippets!</p>
<pre><code class="lang-cs"><span class="hljs-keyword">using</span> System;
<span class="hljs-keyword">using</span> System.IO;
<span class="hljs-keyword">using</span> System.Collections.Generic;
<span class="hljs-keyword">using</span> System.Linq;
<span class="hljs-keyword">using</span> Reader;

<span class="hljs-keyword">namespace</span> <span class="hljs-title">SnippetGenerator2</span>
{
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">CodeSnippetGenerator</span>
    {
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> SnippetLocation;

        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">CodeSnippetGenerator</span>(<span class="hljs-params"><span class="hljs-keyword">string</span> snippetLocation</span>)</span>
        {
            <span class="hljs-keyword">this</span>.SnippetLocation = snippetLocation.EndsWith(<span class="hljs-string">"\\"</span>) ? snippetLocation : snippetLocation + <span class="hljs-string">"\\"</span>;
        }

        <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">UpdateSnippets</span>(<span class="hljs-params"></span>)</span>
        {
            List&lt;Type&gt; allTypes = TypeReader.GetAllTypes();
            Func&lt;Type, <span class="hljs-keyword">string</span>&gt; makeFileName = x =&gt; SnippetLocation + x.Name + <span class="hljs-string">"-"</span> + x.Namespace + <span class="hljs-string">".snippet"</span>;

            DirectoryInfo myCodeSnippets = <span class="hljs-keyword">new</span> DirectoryInfo(SnippetLocation);
            <span class="hljs-keyword">string</span>[] snippetFileNames = allTypes.Select(x =&gt; makeFileName(x)).ToArray();
            <span class="hljs-keyword">string</span>[] previous = myCodeSnippets.GetFiles().Where(x =&gt; x.Name.EndsWith(<span class="hljs-string">".snippet"</span>)).Select(x =&gt; x.Name).ToArray();

            <span class="hljs-comment">//we only keep the files that no longer exsisted.</span>
            previous = previous.Where(x =&gt; !snippetFileNames.Contains(x)).ToArray();
            previous.ToList().ForEach(x =&gt;
            {
                <span class="hljs-keyword">try</span>
                {
                    File.Delete(SnippetLocation + x);
                }
                <span class="hljs-keyword">catch</span> { }
            });<span class="hljs-comment">//we remove the files we don't need.</span>

            allTypes.ForEach(x =&gt; 
            {
                <span class="hljs-keyword">if</span> (!Directory.GetFiles(SnippetLocation).Contains(makeFileName(x)))
                    CreateSnippet(x);
            }
            ); <span class="hljs-comment">//we create snippets for the types.</span>
        }

        <span class="hljs-function"><span class="hljs-keyword">public</span> List&lt;<span class="hljs-keyword">string</span>&gt; <span class="hljs-title">RemoveAllCodeSnippets</span>(<span class="hljs-params"></span>)</span>
        {
            <span class="hljs-keyword">string</span>[] files = Directory.GetFiles(SnippetLocation).ToArray();
            List&lt;<span class="hljs-keyword">string</span>&gt; notDeleted = <span class="hljs-keyword">new</span> List&lt;<span class="hljs-keyword">string</span>&gt;();


            files.ToList().ForEach(x =&gt;
            {
                StreamReader snippetFile = <span class="hljs-keyword">new</span> StreamReader(x);

                <span class="hljs-keyword">if</span> (snippetFile.ReadToEnd().Contains(<span class="hljs-string">"&lt;Author&gt;AUTO-GENERATOR&lt;/Author&gt;"</span>))
                {
                    snippetFile.Close();

                    <span class="hljs-keyword">try</span>
                    {
                        File.Delete(x);
                    }
                    <span class="hljs-keyword">catch</span>
                    {
                        notDeleted.Add(x);
                    }
                }
            });

            <span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>;
            <span class="hljs-keyword">while</span>(i &lt; notDeleted.Count)
            {
                i++;
                <span class="hljs-keyword">try</span>
                {
                    File.Delete(notDeleted[i]);
                }
                <span class="hljs-keyword">catch</span>
                {
                    <span class="hljs-keyword">continue</span>;
                }
                notDeleted.Remove(notDeleted[i]);
            }

            <span class="hljs-keyword">return</span> notDeleted;
        }


        <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;summary&gt;</span></span>
        <span class="hljs-comment"><span class="hljs-doctag">///</span> Creates a snippet.</span>
        <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;/summary&gt;</span></span>
        <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;param name="type"&gt;</span>The type to make the default create for.<span class="hljs-doctag">&lt;/param&gt;</span></span>
        <span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag">&lt;param name="description"&gt;</span>The description of the snippet.<span class="hljs-doctag">&lt;/param&gt;</span></span>
        <span class="hljs-function"><span class="hljs-keyword">internal</span> <span class="hljs-keyword">void</span> <span class="hljs-title">CreateSnippet</span>(<span class="hljs-params">Type type,
                                       <span class="hljs-keyword">string</span> description = <span class="hljs-string">"DefaultDescription"</span></span>)</span>
        {

            <span class="hljs-keyword">string</span> snippet_structure = <span class="hljs-string">$@"&lt;?xml version=""1.0"" encoding=""utf-8""?&gt;
  &lt;CodeSnippets xmlns = """"&gt;  
     &lt;CodeSnippet Format = ""1.0.0""&gt;   
         &lt;Header&gt;    
            &lt;Title&gt;<span class="hljs-subst">{type.Name}</span>-<span class="hljs-subst">{type.Namespace}</span>&lt;/Title&gt;    
            &lt;Author&gt;AUTO-GENERATOR&lt;/Author&gt;
            &lt;Description&gt; <span class="hljs-subst">{description}</span>&lt;/Description&gt;
            &lt;Shortcut&gt; <span class="hljs-subst">{type.Name}</span> &lt;/Shortcut&gt;   
         &lt;/Header&gt;   
         &lt;Snippet&gt;  
           &lt;Code Language = ""CSharp""&gt;    
                 &lt;![CDATA[<span class="hljs-subst">{type.Name}</span> $obj$ = new <span class="hljs-subst">{type.Name}</span>();]]&gt;     
             &lt;/Code&gt;     
             &lt;Declarations&gt;      
                &lt;Literal&gt;      
                    &lt;ID&gt;obj&lt;/ID&gt;      
                    &lt;ToolTip&gt;variable name.&lt;/ToolTip&gt;         
                       &lt;Default&gt;<span class="hljs-subst">{type.Name.ToLower()}</span>&lt;/Default&gt;        
                   &lt;/Literal&gt;       
                &lt;/Declarations&gt;         
             &lt;/Snippet&gt;        
           &lt;/CodeSnippet&gt;
         &lt;/CodeSnippets&gt;"</span>;

            <span class="hljs-comment">//write the snippet into the snippets directory.</span>
            File.WriteAllText(SnippetLocation + type.Name + <span class="hljs-string">"-"</span> + type.Namespace + <span class="hljs-string">".snippet"</span>, snippet_structure);
        }
    }
}
</code></pre>
<p>Let's talk about this code:</p>
<ul>
<li>“Reader” is the namespace of the class we’ve built before.</li>
<li>TypeReader is the name of the class we’ve built before.</li>
<li>The file names of the Snippets will be written as <code>&lt;TypeName&gt;-&lt;NamespaceName&gt;.snippet</code></li>
</ul>
<h4 id="heading-the-constructor">The Constructor</h4>
<ul>
<li>The constructor accepts the path for the “My Code Snippets” directory from the user.</li>
</ul>
<h4 id="heading-the-createsnippet-method">The CreateSnippet method</h4>
<p>The “CreateSnippet” method creates a snippet with a common structure.</p>
<ul>
<li>Title — The <code>&lt;typeName&gt;-&lt;namespace&gt;</code></li>
<li>Author — AUTO-GENERATOR, we call all of them by the same name so we’ll know what snippets were created by the CodeSnippetGenerator and what were created by the user.</li>
<li>We create a structure of:</li>
</ul>
<pre><code class="lang-cs"><span class="hljs-function">TypeName <span class="hljs-title">typename</span>(<span class="hljs-params"><span class="hljs-keyword">in</span> small letters</span>)</span> = <span class="hljs-keyword">new</span> TypeName();
</code></pre>
<ul>
<li>We set the “shortcut” to be the type name also.</li>
</ul>
<h4 id="heading-the-removeallsnippets-method">The RemoveAllSnippets method</h4>
<p>The RemoveAllSnippets method removes all the snippets <strong>that the CodeSnippetGenerator</strong> created. </p>
<p>We know if files were created by the code snippet generator by checking if the Author tag contains “AUTO-GENERATOR”. </p>
<p>We try again to delete files that were not deleted the first time. If we can’t delete them at the second time we return a list of the file names that we couldn't delete.</p>
<h4 id="heading-the-updatesnippets-method">The UpdateSnippets method</h4>
<p>The UpdateSnippets method updates the snippets each run. On each run:</p>
<ul>
<li>We read the names of the types we use in our main program (not in the CodeSnippetGenerator class).</li>
<li>We read the names of the .snippet files we have from the previous run.</li>
<li>We make an array of filenames for each one of our types from our current run.</li>
<li>We see what snippet files we no longer need by comparing what names of snippet files we had in our previous run that don't exist in the filenames of the current run.</li>
<li>We remove these files.</li>
<li>Then we create a “.snippet” file for each type that doesn’t already have one.</li>
</ul>
<h2 id="heading-how-to-use-the-snippet-auto-generator-program">How to Use the Snippet Auto-Generator Program</h2>
<p>If you want to use the program, simply open a C# project and at the beginning of the main function write:</p>
<pre><code class="lang-cs"><span class="hljs-keyword">var</span> csg = <span class="hljs-keyword">new</span> CodeSnippetGenerator(<span class="hljs-string">"path of 'My Code Snippets'&gt;);
csg.UpdateSnippets(); //to create &amp; update the snippets in 
project.csg.RemoveAllSnippets(); //to remove the created snippets.</span>
</code></pre>
<p>Congratulations! You’ve now created your own CodeSnippetGenerator.</p>
<p>I hope these come in handy and save you time when you're writing your code. Thanks for reading :)</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ 5 Helpful Visual Studio Plugins for Ruby on Rails Developers ]]>
                </title>
                <description>
                    <![CDATA[ By Vishnu Chilamakuru In this article, I'll share some of the plugins that I use to make development with Ruby on Rails easier and more fun. Why use these tools? Development tools play a significant role in a developer's life. If you are a junior dev... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/visual-studio-plugins-for-ruby-on-rails-developers/</link>
                <guid isPermaLink="false">66d46171d1ffc3d3eb89de78</guid>
                
                    <category>
                        <![CDATA[ plugins ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Productivity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ruby on Rails ]]>
                    </category>
                
                    <category>
                        <![CDATA[ visual studio ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 03 Sep 2020 06:16:55 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/08/visual_studio_ruby_on_rails-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Vishnu Chilamakuru</p>
<p>In this article, I'll share some of the plugins that I use to make development with Ruby on Rails easier and more fun.</p>
<h2 id="heading-why-use-these-tools">Why use these tools?</h2>
<p>Development tools play a significant role in a developer's life. If you are a junior developer and are just getting started working on projects, then knowing about the appropriate tools is a must. </p>
<p>These tools can save you a lot of time and they allow you to code more efficiently and thus increase your productivity.</p>
<p>If you are Ruby on Rails developer who's looking for free development tools, I would recommend Visual Studio. It has a ton of plugins, like the ones mentioned below, and they have helped me increase my productivity a lot.</p>
<p><em>Note: All visual studio plugins are available on the</em> <a target="_blank" href="https://marketplace.visualstudio.com/"><em>Visual Studio Marketplace</em></a> <em>for free.</em></p>
<p>So let's dive in.</p>
<h2 id="heading-rubyhttpsmarketplacevisualstudiocomitemsitemnamerebornixruby"><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby">Ruby</a></h2>
<p>With ~1.3M downloads, this is one of the most popular plugins for Ruby. It provides enhanced Ruby language and debugging support. </p>
<p>With enhanced debugging support, developers can set breakpoints and inspect the local and global variables in debug mode. This helps to debug any issues easily and in quick time. </p>
<p>This plugin also supports code formatting via <strong><em>rubocop</em></strong> which is very much needed when you are working with team of developers to maintain consistent code format.</p>
<p>Ruby plugin has the following features:</p>
<blockquote>
<ul>
<li><p>Automatic Ruby environment detection with support for rvm, rbenv, chruby, and asdf  </p>
</li>
<li><p>Lint support via RuboCop, Standard, and Reek  </p>
</li>
<li><p>Format support via RuboCop, Standard, Rufo, and RubyFMT  </p>
</li>
<li><p>Basic Intellisense support  </p>
</li>
<li><p>Ruby debugging support  </p>
</li>
</ul>
<p>Source: <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby">Ruby</a></p>
</blockquote>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/Screenshot-2020-08-30-at-3.13.49-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-railshttpsmarketplacevisualstudiocomitemsitemnamebung87rails"><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=bung87.rails">Rails</a></h2>
<p>This is another popular plugin for Rails which provides enhanced Rails support. </p>
<p>ERB HTML templating is widely used in Rails ecosystem as views to render HTML pages for websites. The Rails plugin has support for the <code>.erb</code> syntax and also provides auto-completion for popular HTML tags like stylesheet, meta tags, asset tags, and so on. </p>
<p>This plugin also helps to switch between Rails views (<code>*.erb</code> files) easily. It also helps you see online documentation of any methods or commands easily side by side.</p>
<p>Here are some of the features this plugin supports:</p>
<blockquote>
<ul>
<li><p>Ruby on Rails “Asset Helpers” and “Tag Helpers” snippets.  </p>
</li>
<li><p>.erb syntax highlights.  </p>
</li>
<li><p>Navigation between related files through command.  </p>
</li>
<li><p>Go to Definition.  </p>
</li>
<li><p>View path suggestion, Model’s static method suggestion, and Model’s field suggestion.  </p>
</li>
<li><p>Open the online document to the side through command.  </p>
</li>
</ul>
<p>Source: <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=bung87.rails">Rails</a></p>
</blockquote>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/vscode-rails.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Image from <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=bung87.rails">VSCode Rails</a></em></p>
<h2 id="heading-ruby-solargraphhttpsmarketplacevisualstudiocomitemsitemnamecastwidesolargraph"><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=castwide.solargraph">Ruby Solargraph</a></h2>
<p>Ruby Solargraph is one of the most helpful plugins on this list, and provides IntelliSense, code completion, and inline documentation for Ruby. </p>
<p>Inline documentation helps you view all the allowed methods of the class/object, and also helps you easily understand the definition of each method and its arguments.</p>
<p>This is one of the plugins I have personally used many times to refer to a Ruby method's documentation, arguments for a method, and so on.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/vscode-solargraph-0.34.1.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Image from <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=castwide.solargraph">VSCode Solargraph</a></em></p>
<h2 id="heading-vscode-endwisehttpsgithubcomkaiwoodvscode-endwise"><a target="_blank" href="https://github.com/kaiwood/vscode-endwise">Vscode Endwise</a></h2>
<p>This is my favorite extension that can save you a lot of time and headaches. This extension automatically adds  <code>end</code> to all your Ruby code blocks.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/endwise.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Image from <a target="_blank" href="https://github.com/kaiwood/vscode-endwise">VSCode Endwise</a></em></p>
<h2 id="heading-rails-db-schemahttpsmarketplacevisualstudiocomitemsitemnameaki77rails-db-schema"><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=aki77.rails-db-schema">Rails Db Schema</a></h2>
<p>This plugin helps you define a DB schema and also enables auto-completion for Rails DB schemas. </p>
<p>While defining schemas or creating tables for any Entity, this plugin enables and autocompletes syntax for all your DDLs (Database definition language) like <code>create_table</code>, <code>create_index</code>, <code>delete_table</code>, <code>update_table</code>, and so on. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/definition.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Image from <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=aki77.rails-db-schema">VSCode DB Schema</a></em></p>
<p>It helps in autocomplete of all attributes of any database entity. For example, if <code>User</code> has <code>email</code>, <code>name</code>, and <code>date_of_birth</code> attributes, this plugin will automatically detect the definition of entity and autocompletes its attributes when you type <code>User</code>. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/autocompletion.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Image from <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=aki77.rails-db-schema">VSCode DB Schema</a></em></p>
<h2 id="heading-why-use-visual-studio">Why use Visual Studio?</h2>
<p>There are many other IDE options for Ruby on Rails developers like RubyMine (the enterprise version), Sublime, Vim, and so on. </p>
<p>But my personal favorite is Visual Studio as it has extensive plugin support for multiple languages like Golang, PHP, Node.js, and more. So it's the default IDE, especially for polyglot developers.</p>
<p>Even though visual studio lacks few features compared to RubyMine like getting support for the latest Rails version updates, it covers the majority of the features required for development via community plugins.</p>
<p>If this article was useful, please share it with your network. Also, follow me on <a target="_blank" href="https://twitter.com/vishnuchi">Twitter</a> to know when I publish my next article.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The (super) powers of MFractor and how they can make your life easier ]]>
                </title>
                <description>
                    <![CDATA[ By Łukasz Ławicki If you ask a Xamarin developer what could be changed in Xamarin development, they would for sure mention one of the following: build time performance app start time previewers removing bin/obj from IDE lack of Image wizard in Visua... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/the-super-power-of-mfractor-558deeb8ed66/</link>
                <guid isPermaLink="false">66c36288c6c49ae59cf21b05</guid>
                
                    <category>
                        <![CDATA[ Productivity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ visual studio ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Xamarin ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 30 Jan 2019 14:31:00 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*m8FRApkjXvrgg3OowObeEw.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Łukasz Ławicki</p>
<p>If you ask a Xamarin developer what could be changed in Xamarin development, they would for sure mention one of the following:</p>
<ul>
<li>build time</li>
<li>performance</li>
<li>app start time</li>
<li>previewers</li>
<li>removing bin/obj from IDE</li>
<li>lack of Image wizard in Visual Studio for Mac</li>
<li>no XAML Intellisense,</li>
</ul>
<p>and so on...and if I’m being honest, the answers above are right. But hey, we are the developers! If Microsoft won’t give us these features, let’s try to find workarounds or invent something on our own.</p>
<p>There are several libraries and IDE extensions that make our lives easier. For sure one of them is MFractor —a super powerful extension for Visual Studio for Mac.</p>
<h3 id="heading-so-what-is-mfractor">So what is MFractor?</h3>
<p>MFractor is an extension for Visual Studio for Mac. It was founded in 2015 in Australia. Being on the market for 3.5 years, it has gained people’s trust and love. “How did it do that?” — you might ask. It is because it extends Visual Studio for Mac with features that are missing on a daily basis.</p>
<ul>
<li>Do you want XAML Intellisense? Done. Just install MFractor.</li>
<li>Do you want to remove bin/obj folders within your IDE? MFractor can do it. (By the way — in my opinion, it seems silly that we either need extensions for this or that we need to delete them from time to time. Something is definitely not working…)</li>
<li><strong>And here comes the bomb:</strong> Do you want to have an image wizard in Visual Studio for Mac, so you can manage the resources?</li>
</ul>
<p>I knew you would want that! Have I already told you about MFractor? Och, I did!</p>
<p>Let’s make this clear: <strong>MFractor is a super powerful tool when you are developing apps with Visual Studio on your Mac.</strong></p>
<p>You might not believe my words, so let’s check how it works in real life.</p>
<h3 id="heading-installation">Installation</h3>
<p>It’s very easy. In VS4Mac, simply open <strong>Extensions<em>…</em></strong> under the Visual Studio menu, click <strong>Gallery</strong> and search for <strong>MFractor</strong>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*3KaeayISJSUFKXa3YA4wrg.png" alt="Image" width="800" height="534" loading="lazy"></p>
<p>Voilà. One thing to notice: you will have install instead of <strong>Disable/ Uninstall…</strong> Simply install it and follow the steps required and a pop-up will open. After you’ve installed it, let’s move on to the interesting part.</p>
<h3 id="heading-image-manager">Image manager</h3>
<p>Let’s start with this totally awesome feature. It came out quite recently, so it is still pretty fresh.</p>
<p>Let’s assume that you want to manage image assets within your project, but you really hate doing it manually.</p>
<p>Check out what MFractor is capable of:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*q_4qD5gd8jDy-9B5gnSjQg.png" alt="Image" width="800" height="1049" loading="lazy"></p>
<p>As you can see, you have a list of all icons included in the project with thumbnails. When you click on the item, you can see the image in a bigger size. Also, you may notice that there is a dropdown where you can select your project and check which icons are included in the project (SPYROtalks is the name of my project).</p>
<h4 id="heading-what-can-you-do-within-the-image-manager">What can you do within the image manager?</h4>
<p><strong>Import New Image Asset</strong></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*Cwqa92AX-6dubJH-BPFkig.png" alt="Image" width="800" height="564" loading="lazy"></p>
<p>Adding the asset is really easy.</p>
<ol>
<li>You simply select the image from your computer. MFractor should detect automatically what is the Image Density. If you don’t agree you can change it.</li>
<li>After you do it, you need to provide the <strong>Resource name</strong>. Fair enough, right?</li>
<li>Now, you need to decide to which projects you want to add the asset.</li>
</ol>
<p>Basically, that’s all you must provide. If you want, you can resize an image or optimise it. While writing this article I decided to check how good is the image optimisation. In order to check it, I took 10 photos and optimised all of them. Here are the results:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*7pOZo3uGONbRbwqAvxf5Og.png" alt="Image" width="658" height="416" loading="lazy">
<em>Results of optimisation</em></p>
<p>As you can see in the table above, in general, the results were pretty good. An average of 54% makes it a good result. What is interesting, though, is the fact that one image was bigger after optimisation than the others. Why? I don’t know.</p>
<h4 id="heading-delete-image">Delete image</h4>
<p>In Image manager, you can also delete assets. What is great and time-saving is the fact that it will remove all asset densities at once. No need to delete it 6 (or even more) times. Truly a time saver.</p>
<h4 id="heading-optimise-all-images">Optimise all images</h4>
<p>In case you forgot to optimise your asset when adding it, you can later optimise all images. Good to know.</p>
<p>If you want to learn more about image assets, go ahead and read Matthew’s article which is available on MFractor <a target="_blank" href="https://www.mfractor.com/blogs/news/simplified-image-asset-management-for-xamarin-apps">blog here</a>.</p>
<h3 id="heading-xaml-intellisense">XAML IntelliSense</h3>
<p>If you are not that experienced in developing with Xamarin.Forms, you might find developing XAML UIs a nightmare. On the other hand, even if you are an experienced Xamarin.Forms developer, you might get pretty frustrated when using XAML.</p>
<p>First of all, because of the lack of a previewer (there is one, but let’s be honest: it does not work for complex views), you are creating UI’s almost blind. You have to use your imagination. Wouldn’t it be better if we had a built-in LiveXAML or something like that? Unfortunately, it doesn’t look like Microsoft is gonna provide us with something at the moment. A pity.</p>
<p>Secondly, because of the lack of XAML IntelliSense. It would be nice to have it, so when you created bindings to your ViewModel you could select the property from the dropdown instead of typing it on your own. Who has never made a typo in the name of the property, compiled the code and then wondered why the heck it was not working?</p>
<h4 id="heading-mfractor-to-the-rescue">MFractor to the rescue!</h4>
<p>Another great feature of MFractor is XAML IntelliSense. It can suggest to you the names of the properties in ViewModel, so you can bind to them. Also, it can suggest the names of the images you have in resources and many more. Don’t believe me? Go ahead and check these gifs:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*SMz2x4MgrEzklBpRU9gfEw.gif" alt="Image" width="800" height="298" loading="lazy"></p>
<p>Just to explain: in my project, I have three icons: _Icon.png, Launcher<em>Foreground.png,</em> and _logo<em>spyrotalks.png.</em> As you can see, MFractor is giving me an option to choose one. Nice!</p>
<p>Let’s move on to bindings. As you may suspect, MFractor is suggesting the properties in a similar way that it is suggesting the images.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*Ny7GBRA2lTcVx_eBSZ7z4g.gif" alt="Image" width="477" height="250" loading="lazy"></p>
<p>As you can see in my ViewModel, I have 5 bindable properties. What I really like is the fact that with MFractor, is almost not possible to make a typo in the name of the property.</p>
<h4 id="heading-generate-viewmodel-property"><strong>Generate ViewModel property</strong></h4>
<p>Are you are a person that prefers to write Views first? If yes, I have good news for you: with MFractor you can generate ViewModel properties from your View.</p>
<p>When creating the View you may find that you’ve forgotten to create one property or another. With MFractor you can create them without changing the file. Nice, huh?</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*tiv0sQZIqsED0P3sSsdRkA.gif" alt="Image" width="800" height="484" loading="lazy"></p>
<h4 id="heading-go-to-a-usage-of-viewmodel-property"><strong>Go to a usage of ViewModel property</strong></h4>
<p>From time to time you might want to check where the property is being used. Unfortunately, when you look for references in Visual Studio, it won’t find the ones you have in XAML. Of course, as you may assume, MFractor can find those references for you.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*DKF1i0jXygiG5PfqTU1Cwg.gif" alt="Image" width="1033" height="625" loading="lazy"></p>
<h3 id="heading-mvvm-wizard">MVVM Wizard</h3>
<p>This is something that wasn’t stated at the beginning of this blog as it was not released yet. According to the marketing announcement in version 3.7.3 the <strong>MVVM Wizard</strong> will be available.</p>
<p>According to the tweet by Matthew Robbins (the founder of MFractor) you will be able to create both View &amp; ViewModels with (almost) one click.</p>
<p>What is nice about this feature is the fact that it gives you control over where you place the files and what are the base classes. It sounds promising, but I had some questions: will it support Xamarin.Native also? If we add XAML with BaseContentPage, will it work out of the box?</p>
<p>So I just installed version 3.7.3, and there is <strong>MVVM Manager</strong>. It looks like the one in the picture above. There are three ways to access it: from the MFractor menu, from Solution options, and with a <strong>Cmd + Shift +M</strong> shortcut. Right now, the manager works for Xamarin.Forms projects only.</p>
<p>If you want ViewModel to derive from BaseClass, you might need to write the class with a namespace before. Otherwise, you will need to import the class when the VM is created.</p>
<h4 id="heading-update-3101">UPDATE 31.01</h4>
<p>What you will read below is no longer valid (XAML issue). I have raised the issue above, and after 33h it was solved. Version 3.7.5 should have it fixed. As I have written in my tweet — this is how solving bugs should be done! End of update ;-)</p>
<p>The problem is with the XAML file. As I assumed, deriving from eg. BaseContentPage wouldn’t be that easy. When you want the View to derive from your BaseContentPage you need to feed the MVVM Manager with the following:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*1yGsBw8qPVqFUxilS1WTEQ.png" alt="Image" width="800" height="532" loading="lazy"></p>
<p>Is the code visible that we need? Not fully. It’s similar to the one that we want but not exactly the same. We need code like this:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*edLNzudQii71JenMrW0eSg.png" alt="Image" width="800" height="146" loading="lazy"></p>
<p>It is not a big change, but we need to handle it on our own. I can fully understand that this is not an easy task to achieve. I believe it’s still better to slightly adjust the created files than to create them from scratch.</p>
<p>If you are interested, on the MFractor <a target="_blank" href="https://www.mfractor.com/blogs/news/generating-viewmodels-in-xamarin-forms-with-the-mvvm-wizard">blog</a> you can read more about MVVM Manager.</p>
<h3 id="heading-binobj">bin/obj</h3>
<p>As I have stated at the beginning of this article, I am not sure what to think of bin/obj folders. Firstly, you have to delete them pretty often when developing a Xamarin app. I think it’s an issue.</p>
<p>Why do we have to do it? If it is a known issue (and based on my conversations with my colleagues, I believe it is), shouldn’t we be provided with an option to delete those folders within our IDE? Doing it manually takes so long. Sure, you can have a script to do it, but is it something we need to implement on our own?</p>
<p>Fortunately, MFractor has a feature that can delete those folders for you. How? Pretty simple. Check it out:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*egwuFt435DqROt58nB6sJg.gif" alt="Image" width="297" height="727" loading="lazy"></p>
<p>In here you have options: either delete Output folders (deletes bin/obj &amp; NuGet packages) or you can only Clear Nuget Packages.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>So what are the cons of using MFractor? Some might say that <strong>MFractor Professional</strong> price ($200 AUD per year) can be the issue. But hey! Is it that much for a lifetime license? I don’t think so. Especially when you take into consideration the number of hours being wasted because of, for example, a typo in your XAML or adding image assets.</p>
<p>Originally posted on my <a target="_blank" href="http://lukaszlawicki.pl/mfractor/">blog</a> ?</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to compile Sass files in Visual Studio and Webpack ]]>
                </title>
                <description>
                    <![CDATA[ By Esau Silva Sass is a very popular CSS pre-processor. The intent of this tutorial is to show you how to compile Sass files within Visual Studio using Webpack. Our discussion will include minification and autoprefixing for production. Visual Studio... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-compile-sass-files-in-visual-studio-and-webpack-6e45cdc1c14c/</link>
                <guid isPermaLink="false">66d45e3c9208fb118cc6cf8f</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Sass ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ visual studio ]]>
                    </category>
                
                    <category>
                        <![CDATA[ webpack ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 07 Sep 2018 16:38:25 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*-rQU7AOJC3p-ZbiEQnYYlw.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Esau Silva</p>
<p>Sass is a very popular CSS pre-processor. The intent of this tutorial is to show you how to compile Sass files within Visual Studio using Webpack. Our discussion will include minification and autoprefixing for production.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/3k12b5dvlT4iN20sLPdB9W064Z6R7tSYIuX7" alt="Image" width="800" height="197" loading="lazy">
<em>Visual Studio meets Sass</em></p>
<p>Sure, there are some plug-ins in the Visual Studio Marketplace, and it can be nice to just install a plug-in and forget about configuration. But what happens if the plug-in is not supported anymore and stops working with newer Visual Studio versions? Well, too bad. This is the case with one of the most popular compiler plug-ins on the market.</p>
<p>By configuring the compilation yourself, you will have total control over the output. Also, vendor prefixes will be added automatically to your CSS rules. How cool is that?</p>
<h4 id="heading-prerequisites">Prerequisites</h4>
<p>You will need to have Node installed, and you can grab it <a target="_blank" href="https://nodejs.org/en/">here</a>. That’s it really. You’ll also need npm, but it will also be installed with Node.</p>
<h3 id="heading-creating-the-project">Creating the Project</h3>
<p><strong>Note:</strong> We will be creating a .NET Core MVC app, but the same principles apply to any ASP.NET MVC app. You would just need to modify the Webpack configuration a little bit to output the CSS file to the <code>Content</code> directory.</p>
<p>Open Visual Studio and create a new <strong>ASP.NET Core Web Application</strong>, then select <strong>Web Application (Model-View-Controller)</strong>. I’m naming my project <em>netcore-sass-webpack</em>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/aiZk0QmUZvH0pLbYz4NJQDjsubLYGjSu3D7S" alt="Image" width="800" height="555" loading="lazy">
<em>Creating the project</em></p>
<p>Create a <code>Styles</code> folder within the root of the project. Inside it, create a Sass file and name it <code>site.scss</code>. Open this new Sass file and copy the following:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification\ 
for details on configuring this project to bundle and minify static web assets. */</span>
<span class="hljs-selector-tag">body</span> {
    <span class="hljs-attribute">padding-top</span>: <span class="hljs-number">50px</span>;
    <span class="hljs-attribute">padding-bottom</span>: <span class="hljs-number">20px</span>;
    <span class="hljs-attribute">background</span>: <span class="hljs-number">#D69655</span> <span class="hljs-built_in">url</span>(<span class="hljs-string">'../wwwroot/images/pattern.png'</span>) repeat;
}

<span class="hljs-comment">/* Wrapping element */</span>
<span class="hljs-comment">/* Set some basic padding to keep content from hitting the edges */</span>
<span class="hljs-selector-class">.body-content</span> {
    <span class="hljs-attribute">padding-left</span>: <span class="hljs-number">15px</span>;
    <span class="hljs-attribute">padding-right</span>: <span class="hljs-number">15px</span>;
}

<span class="hljs-comment">/* Carousel */</span>
<span class="hljs-selector-class">.carousel-caption</span> <span class="hljs-selector-tag">p</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">20px</span>;
    <span class="hljs-attribute">line-height</span>: <span class="hljs-number">1.4</span>;
}

<span class="hljs-comment">/* Make .svg files in the carousel display properly in older browsers */</span>
<span class="hljs-selector-class">.carousel-inner</span> <span class="hljs-selector-class">.item</span> <span class="hljs-selector-tag">img</span><span class="hljs-selector-attr">[src$=<span class="hljs-string">".svg"</span>]</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
}

<span class="hljs-comment">/* QR code generator */</span>
<span class="hljs-selector-id">#qrCode</span> {
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">15px</span>;
}

<span class="hljs-comment">/* Hide/rearrange for smaller screens */</span>
<span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">767px</span>) {
    <span class="hljs-comment">/* Hide captions */</span>
    <span class="hljs-selector-class">.carousel-caption</span> {
        <span class="hljs-attribute">display</span>: none;
    }
}
</code></pre>
<p>You will notice that this is the same CSS provided by Visual Studio when we created the project, with the exception of the <code>background</code> rule in the <code>body</code> tag. Now delete the provided CSS located under <code>wwwroot/css</code> (both files: <code>site.css</code> and <code>site.min.css</code>). Don’t worry, we will auto-generate these with Webpack.</p>
<p>Now, download <a target="_blank" href="https://github.com/esausilva/netcore-sass-webpack/tree/master/netcore-sass-webpack/wwwroot/images">pattern.png</a> and place it under <code>wwwroot/images</code>.</p>
<p>Create an empty JavaScript file under the root of the application and name it <code>webpack.config.js</code>. We will take care of this later. You should end up with the following project structure:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/jLrFCNq5AeHVD47jJDIveoOzJgDw6zkryxt3" alt="Image" width="305" height="567" loading="lazy">
<em>Project Structure</em></p>
<p><strong>Note:</strong> You don’t need to do the following two steps for every project, just once (unless you un-install and re-install Visual Studio).</p>
<p>You will need to provide Visual Studio with the Node installation path. Go back to your project and select <strong>Tools -&gt; Optio</strong>ns on the left pa<strong>ne Projects and Solutions -&gt; Web Package Mana</strong>gement and add the path to Node installation at the top of the l<code>ist ( C:\Program Files\</code>node<code>js or C:\Program Files (x86)\</code>nodejs, depending if you installed the x64 or x86 version).</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/J8sJYylsXyYm2gZ2V3Nma4bvABRfJdefnldJ" alt="Image" width="800" height="233" loading="lazy">
<em>Node path</em></p>
<p>Finally download <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=MadsKristensen.NPMTaskRunner">NPM Task Runner</a> and install it — but you will need to close Visual Studio first.</p>
<h3 id="heading-webpack-and-npm-dependencies">Webpack and NPM Dependencies</h3>
<p>Open <strong>Command Prompt</strong> and navigate to the root of the project and install the needed dependencies:</p>
<pre><code>cd netcore-sass-webpack\netcore-sass-webpack
npm init -y
npm i -D webpack webpack-cli node-sass postcss-loader postcss-preset-env sass-loader css-loader cssnano mini-css-extract-plugin cross-env file-loader
</code></pre><p>The first <code>npm</code> command initializes your <code>package.json</code> and the second installs your dependencies.</p>
<ul>
<li><strong>webpack, webpack-cli</strong> — Module bundler</li>
<li><strong>node-sass</strong> — Bindings for Node to LibSass; provides support for Sass</li>
<li><strong>postcss-loader, postcss-preset-env</strong> — PostCSS loader for Webpack to process autoprefixing and minification</li>
<li><strong>sass-loader, css-loader</strong> — Webpack needs specific loaders to support Sass and CSS</li>
<li><strong>cssnano</strong> — CSS minifier</li>
<li><strong>mini-css-extract-plugin</strong> — Extracts the CSS to a separate file</li>
<li><strong>cross-env</strong> — Provides support to Windows users for environment variables. We will use NODE_ENVenvironment variable</li>
<li><strong>file-loader</strong> — Provides support for files (images) in our CSS rules</li>
</ul>
<p>At this point you can re-open the project in Visual Studio. After the project finishes loading, open <code>package.json</code> and add the following scripts:</p>
<pre><code class="lang-js"><span class="hljs-string">"scripts"</span>: {
    <span class="hljs-string">"dev"</span>: <span class="hljs-string">"webpack --watch"</span>,
    <span class="hljs-string">"build"</span>: <span class="hljs-string">"cross-env NODE_ENV=production webpack"</span>
  },
</code></pre>
<ul>
<li><strong>dev</strong> — We will bind this script whenever the project opens, and Webpack will continually watch for changes to the source Sass files, compile them, and output the separate CSS file</li>
<li><strong>build</strong> — We will bind this script before each project build and will produce the production CSS file, including minification and autoprefixing</li>
</ul>
<p><strong>Note:</strong> The NPM scripts will run automatically using the <strong>Task Runner</strong> window. More on that later.</p>
<p>It is time to work on our Webpack configuration. Open <code>webpack.config.js</code> and copy the following:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">"path"</span>);
<span class="hljs-keyword">const</span> MiniCssExtractPlugin = <span class="hljs-built_in">require</span>(<span class="hljs-string">"mini-css-extract-plugin"</span>);
<span class="hljs-keyword">const</span> postcssPresetEnv = <span class="hljs-built_in">require</span>(<span class="hljs-string">"postcss-preset-env"</span>);
<span class="hljs-comment">// We are getting 'process.env.NODE_ENV' from the NPM scripts</span>
<span class="hljs-comment">// Remember the 'dev' script?</span>
<span class="hljs-keyword">const</span> devMode = process.env.NODE_ENV !== <span class="hljs-string">"production"</span>;
<span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-comment">// Tells Webpack which built-in optimizations to use</span>
  <span class="hljs-comment">// If you leave this out, Webpack will default to 'production'</span>
  <span class="hljs-attr">mode</span>: devMode ? <span class="hljs-string">"development"</span> : <span class="hljs-string">"production"</span>,
<span class="hljs-comment">// Webpack needs to know where to start the bundling process,</span>
  <span class="hljs-comment">// so we define the Sass file under './Styles' directory</span>
  <span class="hljs-attr">entry</span>: [<span class="hljs-string">"./Styles/site.scss"</span>],
<span class="hljs-comment">// This is where we define the path where Webpack will place</span>
  <span class="hljs-comment">// a bundled JS file. Webpack needs to produce this file,</span>
  <span class="hljs-comment">// but for our purposes you can ignore it</span>
  <span class="hljs-attr">output</span>: {
    <span class="hljs-attr">path</span>: path.resolve(__dirname, <span class="hljs-string">"wwwroot"</span>),
<span class="hljs-comment">// Specify the base path for all the styles within your</span>
    <span class="hljs-comment">// application. This is relative to the output path, so in</span>
    <span class="hljs-comment">// our case it will be './wwwroot/css'</span>
    <span class="hljs-attr">publicPath</span>: <span class="hljs-string">"/css"</span>,
<span class="hljs-comment">// The name of the output bundle. Path is also relative</span>
    <span class="hljs-comment">// to the output path, so './wwwroot/js'</span>
    <span class="hljs-attr">filename</span>: <span class="hljs-string">"js/sass.js"</span>
  },
  <span class="hljs-attr">module</span>: {
    <span class="hljs-comment">// Array of rules that tells Webpack how the modules (output)</span>
    <span class="hljs-comment">// will be created</span>
    <span class="hljs-attr">rules</span>: [
      {
        <span class="hljs-comment">// Look for Sass files and process them according to the</span>
        <span class="hljs-comment">// rules specified in the different loaders</span>
        <span class="hljs-attr">test</span>: <span class="hljs-regexp">/\.(sa|sc)ss$/</span>,
<span class="hljs-comment">// Use the following loaders from right-to-left, so it will</span>
        <span class="hljs-comment">// use sass-loader first and ending with MiniCssExtractPlugin</span>
        use: [
          {
            <span class="hljs-comment">// Extracts the CSS into a separate file and uses the</span>
            <span class="hljs-comment">// defined configurations in the 'plugins' section</span>
            <span class="hljs-attr">loader</span>: MiniCssExtractPlugin.loader
          },
          {
            <span class="hljs-comment">// Interprets CSS</span>
            <span class="hljs-attr">loader</span>: <span class="hljs-string">"css-loader"</span>,
            <span class="hljs-attr">options</span>: {
              <span class="hljs-attr">importLoaders</span>: <span class="hljs-number">2</span>
            }
          },
          {
            <span class="hljs-comment">// Use PostCSS to minify and autoprefix with vendor rules</span>
            <span class="hljs-comment">// for older browser compatibility</span>
            <span class="hljs-attr">loader</span>: <span class="hljs-string">"postcss-loader"</span>,
            <span class="hljs-attr">options</span>: {
              <span class="hljs-attr">ident</span>: <span class="hljs-string">"postcss"</span>,
<span class="hljs-comment">// We instruct PostCSS to autoprefix and minimize our</span>
              <span class="hljs-comment">// CSS when in production mode, otherwise don't do</span>
              <span class="hljs-comment">// anything.</span>
              <span class="hljs-attr">plugins</span>: devMode
                ? <span class="hljs-function">() =&gt;</span> []
                : <span class="hljs-function">() =&gt;</span> [
                    postcssPresetEnv({
                      <span class="hljs-comment">// Compile our CSS code to support browsers</span>
                      <span class="hljs-comment">// that are used in more than 1% of the</span>
                      <span class="hljs-comment">// global market browser share. You can modify</span>
                      <span class="hljs-comment">// the target browsers according to your needs</span>
                      <span class="hljs-comment">// by using supported queries.</span>
                      <span class="hljs-comment">// https://github.com/browserslist/browserslist#queries</span>
                      <span class="hljs-attr">browsers</span>: [<span class="hljs-string">"&gt;1%"</span>]
                    }),
                    <span class="hljs-built_in">require</span>(<span class="hljs-string">"cssnano"</span>)()
                  ]
            }
          },
          {
            <span class="hljs-comment">// Adds support for Sass files, if using Less, then</span>
            <span class="hljs-comment">// use the less-loader</span>
            <span class="hljs-attr">loader</span>: <span class="hljs-string">"sass-loader"</span>
          }
        ]
      },
      {
        <span class="hljs-comment">// Adds support to load images in your CSS rules. It looks for</span>
        <span class="hljs-comment">// .png, .jpg, .jpeg and .gif</span>
        <span class="hljs-attr">test</span>: <span class="hljs-regexp">/\.(png|jpe?g|gif)$/</span>,
        use: [
          {
            <span class="hljs-attr">loader</span>: <span class="hljs-string">"file-loader"</span>,
            <span class="hljs-attr">options</span>: {
              <span class="hljs-comment">// The image will be named with the original name and</span>
              <span class="hljs-comment">// extension</span>
              <span class="hljs-attr">name</span>: <span class="hljs-string">"[name].[ext]"</span>,
<span class="hljs-comment">// Indicates where the images are stored and will use</span>
              <span class="hljs-comment">// this path when generating the CSS files.</span>
              <span class="hljs-comment">// Example, in site.scss I have</span>
              <span class="hljs-comment">// url('../wwwroot/images/pattern.png') and when generating</span>
              <span class="hljs-comment">// the CSS file, file-loader will output as</span>
              <span class="hljs-comment">// url(../images/pattern.png), which is relative</span>
              <span class="hljs-comment">// to '/css/site.css'</span>
              <span class="hljs-attr">publicPath</span>: <span class="hljs-string">"../images"</span>,
<span class="hljs-comment">// When this option is 'true', the loader will emit the</span>
              <span class="hljs-comment">// image to output.path</span>
              <span class="hljs-attr">emitFile</span>: <span class="hljs-literal">false</span>
            }
          }
        ]
      }
    ]
  },
  <span class="hljs-attr">plugins</span>: [
    <span class="hljs-comment">// Configuration options for MiniCssExtractPlugin. Here I'm only</span>
    <span class="hljs-comment">// indicating what the CSS output file name should be and</span>
    <span class="hljs-comment">// the location</span>
    <span class="hljs-keyword">new</span> MiniCssExtractPlugin({
      <span class="hljs-attr">filename</span>: devMode ? <span class="hljs-string">"css/site.css"</span> : <span class="hljs-string">"css/site.min.css"</span>
    })
  ]
};
</code></pre>
<p>Refer to the comments in the code to understand the configuration. (More readable file <a target="_blank" href="https://github.com/esausilva/netcore-sass-webpack/blob/master/netcore-sass-webpack/webpack.config.js">here</a>.)</p>
<p>Now we need to create some bindings in <strong>Task Runner Explorer</strong>. Navigate to <strong>View -&gt; Other Windows -&gt; Task Runner Exp</strong>lorer. The window will show at the bottom and you will see the scripts you created in <code>package.json</code> listed there <strong>under</strong> Custom. You will also see some tasks <strong>under De</strong>faults, but you can just ignore them.</p>
<p>We need two bindings:</p>
<ul>
<li>Right click <strong>build -&gt; Bindings -&gt; Before</strong> Build — Visual Studio will run this task before each build. Remember this npm script runs Webpack for production and will optimize the CSS file.</li>
<li>Right click <strong>dev -&gt; Bindings -&gt; Projec</strong>t Open — Visual Studio will run this task when you open the project. Remember this npm script runs Webpack in watch mode and <em>will</em> watch for any changes in your Sass files and output the processed CSS file.</li>
</ul>
<p><strong>Task Runner Explorer</strong> should look like this:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/cEQsi3RjNiBTTQr1tAhSoAARAmhkc79kQRza" alt="Image" width="392" height="209" loading="lazy">
<em>Task Runner Explorer</em></p>
<p><strong>Note:</strong> For some reason, Visual Studio sometimes will fail to start the <strong>dev</strong> task upon opening the project. If that happens, just open the Task Explorer and run the task manually.</p>
<p>You can get the full code from the <a target="_blank" href="https://github.com/esausilva/netcore-sass-webpack">GitHub repository</a>.</p>
<h3 id="heading-final-thoughts">Final Thoughts</h3>
<p>And that’s all there is too it. Since you already have Visual Studio open, none of the tasks are running. Go ahead and <em>right click</em> the <strong>dev</strong> task and select run. You will see the task loading and when it finishes you will see that a <code>site.css</code> file was created under <code>wwwroot/css</code> directory. Open <code>site.scss</code>, make a change and save it. Now open <code>site.css</code>, you will see your change reflected there. Cool!!</p>
<p>Run your project by pressing <strong>Ctrl + F5</strong>, you will see a <code>site.min.css</code> file created under <code>wwwroot/css</code> directory. This file was created when Task Runner <em>ran</em> the <code>build</code> script before it built the project.</p>
<p>The final site should look like this:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/CBTg3rcS670jv5PSQzM35LZ9awQdUfzS2Nb3" alt="Image" width="800" height="527" loading="lazy">
<em>Final site</em></p>
<p>I know, I know, the background is very cheesey…but I needed an image to show the Webpack <code>file-loader</code> in action.</p>
<p>With this configuration, you can even add support to transpile modern JavaScript (ES6+) to ES5. Look into these: <code>@babel/core</code>, <code>babel-loader</code>, <code>@babel/preset-env</code>.</p>
<p>Thank you for reading, and I hope you enjoyed it. If you have any questions, suggestions, or corrections let me know in the comments below. Don’t forget to give this article a share, and you can follow me on <a target="_blank" href="https://twitter.com/_esausilva">Twitter</a>, <a target="_blank" href="https://github.com/esausilva/">GitHub</a>, <a target="_blank" href="https://medium.com/@_esausilva">Medium</a>, <a target="_blank" href="https://www.linkedin.com/in/esausilva/">LinkedIn</a>.</p>
<p>You can also visit my personal <a target="_blank" href="https://esausilva.com">blogging site</a>.</p>
<hr>
<p><strong>Update 8/25/19:</strong> I have been building a prayer web app called "<strong>My Quiet Time - A Prayer Journal</strong>". If you would like to stay in the loop please sign up through the following link: <a target="_blank" href="http://b.link/mqt">http://b.link/mqt</a>  </p>
<p>The app will be released before the end of the year, I have big plans for this app. To see some mockup screenshots follow the following link: <a target="_blank" href="http://pc.cd/Lpy7">http://pc.cd/Lpy7</a></p>
<p>My DMs on <a target="_blank" href="https://twitter.com/_esausilva">Twitter</a> are open if you have any questions regarding the app ?</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to create a cascading DropDownList in Blazor using EF Core ]]>
                </title>
                <description>
                    <![CDATA[ By Ankit Sharma Introduction In this article, we are going to create a cascading dropdown list in Blazor using Entity Framework Core database first approach. We will create two dropdown lists — Country and City. Upon selecting the value from the coun... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-create-a-cascading-dropdownlist-in-blazor-using-ef-core-d230bb5bff5f/</link>
                <guid isPermaLink="false">66d45da0246e57ac83a2c703</guid>
                
                    <category>
                        <![CDATA[ data ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                    <category>
                        <![CDATA[ visual studio ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 11 Jun 2018 22:21:22 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*-F0evvZudQwAMDUb9ygC8Q.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Ankit Sharma</p>
<h3 id="heading-introduction">Introduction</h3>
<p>In this article, we are going to create a cascading dropdown list in Blazor using Entity Framework Core database first approach. We will create two dropdown lists — <strong>Country</strong> and <strong>City</strong>. Upon selecting the value from the country dropdown, we will change the value of the City dropdown.</p>
<p>We will be using Visual Studio 2017 and SQL Server 2014.</p>
<p>Let’s take a look at the final product.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/R6rX0AxiRQV668mITyMfa7Zl6bUW8SE53IJj" alt="Image" width="650" height="363" loading="lazy"></p>
<h3 id="heading-prerequisites">Prerequisites</h3>
<ul>
<li>Install .NET Core 2.1 Preview 2 SDK from <a target="_blank" href="https://www.microsoft.com/net/download/dotnet-core/sdk-2.1.300-preview2">here</a></li>
<li>Install Visual Studio 2017 v15.7 or above from <a target="_blank" href="https://www.visualstudio.com/downloads/">here</a></li>
<li>Install ASP.NET Core Blazor Language Services extension from <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=aspnet.blazor">here</a></li>
<li>SQL Server 2008 or above</li>
</ul>
<p>Blazor framework is not supported by versions below Visual Studio 2017 v15.7.</p>
<h3 id="heading-source-code">Source Code</h3>
<p>Before proceeding, I would recommend that you get the source code from <a target="_blank" href="https://github.com/AnkitSharma-007/Blazor-CascadingDDL-EFCore">GitHub</a>.</p>
<h3 id="heading-creating-tables">Creating Tables</h3>
<p>We will be using two tables to store our data.</p>
<ol>
<li>Country: used to store the name of the Country. It contains two fields — CountryId and CountryName.</li>
<li>Cities: This contains the list of cities for the Countries we will insert in the Country table. It contains three fields — CityId, CountryId, and CityName. The CountryId column is a foreign key referring to CountryId in the Country table.</li>
</ol>
<p>Execute the following commands to create both tables:</p>
<pre><code>CREATE TABLE Country(CountryId VARCHAR(<span class="hljs-number">5</span>) PRIMARY KEY,CountryName VARCHAR(<span class="hljs-number">20</span>) NOT NULL)GOCREATE TABLE Cities(CityId VARCHAR(<span class="hljs-number">5</span>) PRIMARY KEY,CountryId VARCHAR(<span class="hljs-number">5</span>) FOREIGN KEY REFERENCES Country(CountryId),CityName VARCHAR(<span class="hljs-number">20</span>) NOT NULL)GO
</code></pre><p>Now we will put some data in both of the tables. Open the Country table and execute the following insert statement.</p>
<pre><code>INSERT INTO Country VALUES (<span class="hljs-string">'C1'</span>, <span class="hljs-string">'India'</span>)INSERT INTO Country VALUES (<span class="hljs-string">'C2'</span>, <span class="hljs-string">'China'</span>)INSERT INTO Country VALUES (<span class="hljs-string">'C3'</span>, <span class="hljs-string">'USA'</span>)
</code></pre><p>Then execute the following insert statements to insert data into the Cities table.</p>
<pre><code>INSERT INTO Cities VALUES (<span class="hljs-string">'P1'</span>,<span class="hljs-string">'C1'</span>,<span class="hljs-string">'New Delhi'</span>)INSERT INTO Cities VALUES (<span class="hljs-string">'P2'</span>,<span class="hljs-string">'C1'</span>,<span class="hljs-string">'Mumbai'</span>)INSERT INTO Cities VALUES (<span class="hljs-string">'P3'</span>,<span class="hljs-string">'C1'</span>,<span class="hljs-string">'Chennai'</span>)INSERT INTO Cities VALUES (<span class="hljs-string">'P4'</span>,<span class="hljs-string">'C1'</span>,<span class="hljs-string">'Hyderabad'</span>)INSERT INTO Cities VALUES (<span class="hljs-string">'P5'</span>,<span class="hljs-string">'C1'</span>,<span class="hljs-string">'Bengaluru'</span>)INSERT INTO Cities VALUES (<span class="hljs-string">'P6'</span>,<span class="hljs-string">'C2'</span>,<span class="hljs-string">'Beijing'</span>)INSERT INTO Cities VALUES (<span class="hljs-string">'P7'</span>,<span class="hljs-string">'C2'</span>,<span class="hljs-string">'Shanghai'</span>)INSERT INTO Cities VALUES (<span class="hljs-string">'P8'</span>,<span class="hljs-string">'C2'</span>,<span class="hljs-string">'Hong Kong'</span>)INSERT INTO Cities VALUES (<span class="hljs-string">'P9'</span>,<span class="hljs-string">'C2'</span>,<span class="hljs-string">'Macau'</span>)INSERT INTO Cities VALUES (<span class="hljs-string">'P10'</span>,<span class="hljs-string">'C3'</span>,<span class="hljs-string">'New York'</span>)INSERT INTO Cities VALUES (<span class="hljs-string">'P11'</span>,<span class="hljs-string">'C3'</span>,<span class="hljs-string">'Chicago'</span>)INSERT INTO Cities VALUES (<span class="hljs-string">'P12'</span>,<span class="hljs-string">'C3'</span>,<span class="hljs-string">'Las Vegas'</span>)
</code></pre><h3 id="heading-create-blazor-web-application">Create Blazor Web Application</h3>
<p>Open Visual Studio and select File &gt;&gt; New &gt;&gt; Project.</p>
<p>After selecting the project, a “New Project” dialog will open. Select .NET Core inside the Visual C# menu from the left panel. Then, select “ASP.NET Core Web Application” from the available project types. Name the project “BlazorDDL” and press OK.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/aA8aVK7FJ9e7thD2fBpNscpiI0ttTX-tLCdU" alt="Image" width="650" height="397" loading="lazy"></p>
<p>After clicking on OK, a new dialog will open asking you to select the project template. You can see two drop-down menus at the top left of the template window. Select “.NET Core” and “ASP.NET Core 2.0” from these dropdowns. Then, select the “Blazor (ASP .NET Core hosted)” template and press OK.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/DK6ivh2qgXWJpzHbnuPegwrxXeOAVEQjGpRn" alt="Image" width="650" height="457" loading="lazy"></p>
<p>Now, our Blazor solution will be created. You can see the folder structure in Solution Explorer as shown in the below image.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/lfVaeOOv4QxaWlf9lU8BzEOvajxIIZb-RoT0" alt="Image" width="247" height="484" loading="lazy"></p>
<p>You can see that we have three project files created inside this solution.</p>
<ol>
<li>BlazorDDL.Client: it has the client side code and contains the pages that will be rendered on the browser.</li>
<li>BlazorDDL.Server: it has the server side code, such as DB related operations and web API.</li>
<li>BlazorDDL.Shared: it contains the shared code that can be accessed by both client and server.</li>
</ol>
<h3 id="heading-scaffolding-the-model-to-the-application">Scaffolding the Model to the Application</h3>
<p>We are using Entity Framework core database first approach to create our models. We will create our model class in the “BlazorDDL.Shared” project so that it can be accessible to both the client and server project.</p>
<p>Navigate to Tools &gt;&gt; NuGet Package Manager &gt;&gt; Package Manager Console. Select “BlazorDDL.Shared” from the Default project dropdown. Refer to the image below:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/5pv33HzsBpS5pQ8O8CmSw-O2jsyhBaN8LO4W" alt="Image" width="650" height="86" loading="lazy"></p>
<p>First we will install the package for the database provider that we are targeting, which is SQL Server in this case. Run the following command:</p>
<pre><code>Install-Package Microsoft.EntityFrameworkCore.SqlServer
</code></pre><p>Since we are using Entity Framework Tools to create a model from the existing database, we will install the tools package as well. Run the following command:</p>
<pre><code>Install-Package Microsoft.EntityFrameworkCore.Tools
</code></pre><p>After you have installed both packages, we will scaffold our model from the database tables using the following command:</p>
<pre><code>Scaffold-DbContext <span class="hljs-string">"Your connection string here"</span> Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Tables Country, Cities
</code></pre><p>Do not forget to put your own connection string (inside “ ”). After this command gets executed successfully, you can see that a Models folder has been created and contains three class files: “myTestDBContext.cs”, _“_Cities.cs”, and “Country.cs”. And so we have successfully scaffolded our Models using EF core database first approach.</p>
<p>At this point in time, the Models folder will have the following structure.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/ZyxM9Q56JAl9a7NLVwOwAhoJBFz1f7aQxd6L" alt="Image" width="216" height="201" loading="lazy"></p>
<h3 id="heading-creating-the-data-access-layer-for-the-application">Creating the Data Access Layer for the Application</h3>
<p>Right click on “BlazorDDL.Server” project and then select Add &gt;&gt; New Folder and name the folder “DataAccess”. We will be adding our class to handle database-related operations inside this folder only.</p>
<p>Right click on the “DataAccess” folder and select Add &gt;&gt; Class. Name your class “DataAccessCl<em>ass</em>.cs”. This class will handle our database-related operations.</p>
<p>Open “DataAccessLayer.cs” and put the following code into it.</p>
<pre><code>using BlazorDDL.Shared.Models;using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;namespace BlazorDDL.Server.DataAcces{    public <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">DataAccessLayer</span>    </span>{        myTestDBContext db = <span class="hljs-keyword">new</span> myTestDBContext();        public IEnumerable&lt;Country&gt; GetAllCountries()        {            <span class="hljs-keyword">try</span>            {                <span class="hljs-keyword">return</span> db.Country.ToList();            }            <span class="hljs-keyword">catch</span>            {                <span class="hljs-keyword">throw</span>;            }        }        public IEnumerable&lt;Cities&gt; GetCityData(string id)        {            <span class="hljs-keyword">try</span>            {                List&lt;Cities&gt; lstCity = <span class="hljs-keyword">new</span> List&lt;Cities&gt;();                lstCity = (<span class="hljs-keyword">from</span> CityName <span class="hljs-keyword">in</span> db.Cities where CityName.CountryId == id select CityName).ToList();                <span class="hljs-keyword">return</span> lstCity;            }            <span class="hljs-keyword">catch</span>            {                <span class="hljs-keyword">throw</span>;            }        }    }}
</code></pre><p>Here we have defined two methods:</p>
<ol>
<li>GetAllCountries: it will fetch all the country data from the country table.</li>
<li>GetCityData: it will fetch the city data corresponding to the country id provided to it.</li>
</ol>
<p>Now our data access layer is complete. We will proceed to create our web API Controller.</p>
<h3 id="heading-adding-the-web-api-controller-to-the-application">Adding the web API Controller to the Application</h3>
<p>Right click on the “BlazorDDL.Server/Controllers” folder and select Add &gt;&gt; New Item. An “Add New Item” dialog box will open. Select “ASP.NET” from the left panel, then select “API Controller Class” from templates panel and name it “CountriesController.cs”. Press Add.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0U0myNn7E3ix92ez7eJ23-1mFPV9WQd3Y5E9" alt="Image" width="650" height="397" loading="lazy"></p>
<p>This will create our API “CountriesController” class.</p>
<p>We will call the methods of the “DataAccessLayer” class to fetch data and pass on the data to the client side.</p>
<p>Open the “CountriesController.cs” file and put the following code into it.</p>
<pre><code>using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using BlazorDDL.Server.DataAcces;using BlazorDDL.Shared.Models;using Microsoft.AspNetCore.Mvc;using Microsoft.AspNetCore.Http;namespace BlazorDDL.Server.Controllers{    public <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CountriesController</span> : <span class="hljs-title">Controller</span>    </span>{        DataAccessLayer objCountry= <span class="hljs-keyword">new</span> DataAccessLayer();        [HttpGet]        [Route(<span class="hljs-string">"api/Countries/GetCountryList"</span>)]        public IEnumerable&lt;Country&gt; GetCountryList()        {            <span class="hljs-keyword">return</span> objCountry.GetAllCountries();        }        [HttpGet]        [Route(<span class="hljs-string">"api/Countries/GetCities/{id}"</span>)]        public IEnumerable&lt;Cities&gt; GetCities(string id)        {            <span class="hljs-keyword">return</span> objCountry.GetCityData(id);        }    }}
</code></pre><p>At this point in time, our BlazorDDL.Server project has the following structure.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/CZyT1rhgPUQJDkNFnFSOru1uZhBIKGY8Gq9O" alt="Image" width="300" height="364" loading="lazy"></p>
<p>We are done with our backend logic. Therefore, we will now proceed to code our client side.</p>
<h3 id="heading-adding-razor-view-to-the-application">Adding Razor View to the Application</h3>
<p>Right click on the “BlazorDDL.Client/Page”<em>s</em> folder and then select Add &gt;&gt; New Item. An “Add New Item” dialog box will open. Select Web from the left panel, then select “Razor View” from the templates panel and name it “CountryData.c_s_html”.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/j8cycgQmG0qdEo2ix46ZdPdR0UmGqyn2mZiD" alt="Image" width="650" height="397" loading="lazy"></p>
<p>This will add a “CountryData.cshtml” page to our “BlazorDDL.Client/Pages” folder.</p>
<p>Open the “CountryData.cshtml” page and put the following code into it.</p>
<pre><code>@using BlazorDDL.Shared.Models@page <span class="hljs-string">"/country"</span>@inject HttpClient Http&lt;h1&gt;Country Data&lt;<span class="hljs-regexp">/h1&gt;&lt;p&gt;This component demonstrates cascading dropdownlist using EntityFrameWork Core&lt;/</span>p&gt;<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">hr</span> /&gt;</span></span>@<span class="hljs-keyword">if</span> (countryList == <span class="hljs-literal">null</span>){    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">em</span>&gt;</span>Loading...<span class="hljs-tag">&lt;/<span class="hljs-name">em</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>}<span class="hljs-keyword">else</span>{    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"row"</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"col-md-4"</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"Country"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"control-label"</span>&gt;</span>Country<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"col-md-4"</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">asp-for</span>=<span class="hljs-string">"Cities"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"control-label"</span>&gt;</span>Cities<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"row"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"padding-top:10px"</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"col-md-4"</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">select</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">onchange</span>=<span class="hljs-string">"@CountryClicked"</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">""</span>&gt;</span>-- Select Country --<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>                @foreach (var country in countryList)                {                    <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"@country.CountryId"</span>&gt;</span>@country.CountryName<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>                }            <span class="hljs-tag">&lt;/<span class="hljs-name">select</span>&gt;</span>        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"col-md-4"</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">select</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">onchange</span>=<span class="hljs-string">"@CityClicked"</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">""</span>&gt;</span>-- Select City --<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>                @if (cityList != null)                {                    @foreach (var city in cityList)                    {                        <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"@city.CityName"</span>&gt;</span>@city.CityName<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>                    }                }            <span class="hljs-tag">&lt;/<span class="hljs-name">select</span>&gt;</span>        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"row"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"padding-top:50px"</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"col-md-4"</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"control-label"</span>&gt;</span>Country Name: @countryName<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"col-md-4"</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"control-label"</span>&gt;</span>City Name: @cityName<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>}@functions {List&lt;Country&gt; countryList = <span class="hljs-keyword">new</span> List&lt;Country&gt;();List&lt;Cities&gt; cityList = <span class="hljs-keyword">new</span> List&lt;Cities&gt;();string countryId { get; set; }string countryName { get; set; }string cityName { get; set; }protected override <span class="hljs-keyword">async</span> Task OnInitAsync(){    countryList = <span class="hljs-keyword">await</span> Http.GetJsonAsync&lt;List&lt;Country&gt;&gt;(<span class="hljs-string">"api/Countries/GetCountryList"</span>);}protected <span class="hljs-keyword">async</span> <span class="hljs-keyword">void</span> CountryClicked(UIChangeEventArgs countryEvent){    cityList.Clear();    cityName = string.Empty;    countryId = countryEvent.Value.ToString();    countryName = countryList.FirstOrDefault(<span class="hljs-function"><span class="hljs-params">s</span> =&gt;</span> s.CountryId == countryId).CountryName;    cityList = <span class="hljs-keyword">await</span> Http.GetJsonAsync&lt;List&lt;Cities&gt;&gt;(<span class="hljs-string">"api/Countries/GetCities/"</span> + countryId);    <span class="hljs-built_in">this</span>.StateHasChanged();}<span class="hljs-keyword">void</span> CityClicked(UIChangeEventArgs cityEvent){    cityName = cityEvent.Value.ToString();    <span class="hljs-built_in">this</span>.StateHasChanged();}}
</code></pre><p>Let’s understand this code.</p>
<p>At the top, we have included BlazorDDL.Shared.Models namespace so that we can use our Country and Cities model class on this page. We define the route of this page using the @page directive. So, in this application, if we append “/country” to the base URL, then we will be redirected to this page. We are also injecting HttpClient service to enable the web API call.</p>
<p>Then we have defined the HTML section to display two Dropdown lists on our web page. We are calling the “CountryClicked” method on the “onchange” event of the Country dropdown. This method will call the “GetCites” web API method to fetch the city data from the Cities table corresponding to the countryid of the selected country.</p>
<p>We are also setting the value of the “countryName” property to the selected country. The “StateHasChanged” method is invoked to refresh the UI. This will ensure that the City dropdown list will get refreshed on changing the country dropdown.</p>
<p>Similarly, we have another dropdown list to display cities data corresponding to each country. On the “onchange” event of the Cities dropdown, we are setting the value of the “cityName” property to the selected city.</p>
<p>We are also displaying the selected country name and city name value on the webpage.</p>
<p>The @functions section contains all our properties and methods. We have defined two variables: countryList of type Country, and cityList of type City. These handle the countries and cities data, respectively. We have also declared three properties to handle the countryId, countryName, and cityName data.</p>
<p>Inside the “OnInitAsync” method, we are calling the GetCountryList web API method to populate countryList. This variable is used to bind the data to the Country dropdown list on page load.</p>
<h3 id="heading-adding-the-link-to-the-navigation-menu">Adding the Link to the Navigation menu</h3>
<p>The last step is to add the link to our “CountryData” page in the navigation menu. Open the “BlazorDDL.Client/Shared/NavMenu.cshtml” page and put the following code into it.</p>
<pre><code>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"top-row pl-4 navbar navbar-dark"</span>&gt;    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"navbar-brand"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/"</span>&gt;</span>BlazorDDL<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span></span>    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"navbar-toggler"</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">@ToggleNavMenu</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"navbar-toggler-icon"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>    <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>&lt;<span class="hljs-regexp">/div&gt;&lt;div class=@(collapseNavMenu ? "collapse" : null) onclick=@ToggleNavMenu&gt;    &lt;ul class="nav flex-column"&gt;        &lt;li class="nav-item px-3"&gt;            &lt;NavLink class="nav-link" href="/</span><span class="hljs-string">" Match=NavLinkMatch.All&gt;                &lt;span class="</span>oi oi-home<span class="hljs-string">" aria-hidden="</span><span class="hljs-literal">true</span><span class="hljs-string">"&gt;&lt;/span&gt; Home            &lt;/NavLink&gt;        &lt;/li&gt;        &lt;li class="</span>nav-item px<span class="hljs-number">-3</span><span class="hljs-string">"&gt;            &lt;NavLink class="</span>nav-link<span class="hljs-string">" href="</span>/counter<span class="hljs-string">"&gt;                &lt;span class="</span>oi oi-plus<span class="hljs-string">" aria-hidden="</span><span class="hljs-literal">true</span><span class="hljs-string">"&gt;&lt;/span&gt; Counter            &lt;/NavLink&gt;        &lt;/li&gt;        &lt;li class="</span>nav-item px<span class="hljs-number">-3</span><span class="hljs-string">"&gt;            &lt;NavLink class="</span>nav-link<span class="hljs-string">" href="</span>/fetchdata<span class="hljs-string">"&gt;                &lt;span class="</span>oi oi-list-rich<span class="hljs-string">" aria-hidden="</span><span class="hljs-literal">true</span><span class="hljs-string">"&gt;&lt;/span&gt; Fetch data            &lt;/NavLink&gt;        &lt;/li&gt;        &lt;li class="</span>nav-item px<span class="hljs-number">-3</span><span class="hljs-string">"&gt;            &lt;NavLink class="</span>nav-link<span class="hljs-string">" href="</span>/country<span class="hljs-string">"&gt;                &lt;span class="</span>oi oi-list-rich<span class="hljs-string">" aria-hidden="</span><span class="hljs-literal">true</span><span class="hljs-string">"&gt;&lt;/span&gt; Country            &lt;/NavLink&gt;        &lt;/li&gt;    &lt;/ul&gt;&lt;/div&gt;@functions {bool collapseNavMenu = true;void ToggleNavMenu(){    collapseNavMenu = !collapseNavMenu;}}</span>
</code></pre><p>Now we have completed our cascading dropdown list application.</p>
<h3 id="heading-execution-demo">Execution Demo</h3>
<p>Launch the application.</p>
<p>A web page will open as shown in the image below. The navigation menu on the left shows the navigation link for the CountryData page.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/r6L1EKqQvVQYBNuPYvZqLndvhr1y9LoqPpga" alt="Image" width="650" height="362" loading="lazy"></p>
<p>Click on “country” in the navigation menu. It will redirect to the CountryData view where you can see two dropdown s— Country and Cities — on the page. Notice the URL has “/<em>country</em> ” appended to it as we have defined it using the @page directive.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Fq5uDHelWT5tLTm5viD8CeSTfuO6oQtrOx88" alt="Image" width="650" height="362" loading="lazy"></p>
<p>Here you can see both the dropdown lists. The Country dropdown list is already populated with the country data. If we select any country name from this dropdown, then the city dropdown will also get populated with the corresponding city data. We can also see the selected country and city values in the labels below both drop down lists.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/kKA-ZvMJYGII82wAiK8QiKz8zsDdCcxoMN-K" alt="Image" width="650" height="350" loading="lazy"></p>
<h3 id="heading-hosting-the-application">Hosting the application</h3>
<p>To learn how to host a Blazor application using IIS , refer to <a target="_blank" href="http://ankitsharmablogs.com/deploying-a-blazor-application-on-iis/">Deploying a Blazor Application on IIS</a></p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>We have learned how to create cascading dropdown lists in Blazor using Entity Framework Core database first approach with the help of Visual Studio 2017 and SQL Server 2014. Please get the source code from <a target="_blank" href="https://github.com/AnkitSharma-007/Blazor-CascadingDDL-EFCore">GitHub</a> and play around to get a better understanding.</p>
<p>Get my book <a target="_blank" href="https://www.amazon.com/Blazor-Quick-Start-Guide-applications/dp/178934414X/ref=sr_1_1?ie=UTF8&amp;qid=1542438251&amp;sr=8-1&amp;keywords=Blazor-Quick-Start-Guide">Blazor Quick Start Guide</a> to learn more about Blazor.</p>
<p>You can check my other articles on Blazor <a target="_blank" href="http://ankitsharmablogs.com/category/blazor/">here</a></p>
<p>You can also find this article at <a target="_blank" href="https://www.c-sharpcorner.com/article/cascading-dropdownlist-in-blazor-using-ef-core/">C# Corner</a>.</p>
<h3 id="heading-see-also">See Also</h3>
<ul>
<li><a target="_blank" href="http://ankitsharmablogs.com/asp-net-core-getting-started-with-blazor/">ASP.NET Core — Getting Started With Blazor</a></li>
<li><a target="_blank" href="http://ankitsharmablogs.com/asp-net-core-crud-using-blazor-and-entity-framework-core/">ASP.NET Core — CRUD Using Blazor And Entity Framework Core</a></li>
<li><a target="_blank" href="http://ankitsharmablogs.com/asp-net-core-crud-using-angular-5-and-entity-framework-core/">ASP.NET Core — CRUD Using Angular 5 And Entity Framework Core</a></li>
<li><a target="_blank" href="http://ankitsharmablogs.com/asp-net-core-crud-with-react-js-and-entity-framework-core/">ASP.NET Core — CRUD With React.js And Entity Framework Core</a></li>
<li><a target="_blank" href="http://ankitsharmablogs.com/asp-net-core-using-highcharts-with-angular-5/">ASP.NET Core — Using Highcharts With Angular 5</a></li>
</ul>
<p><em>Originally published at</em> <a target="_blank" href="https://ankitsharmablogs.com/">https://ankitsharmablogs.com/</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to create an application using Blazor and Entity Framework Core ]]>
                </title>
                <description>
                    <![CDATA[ By Ankit Sharma Microsoft has recently announced the release of a new .NET web framework called Blazor. In this article, we are going to create a web application using Blazor with the help of Entity Framework Core. We will be creating a sample Employ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-create-an-application-using-blazor-and-entity-framework-core-1c1679d87c7e/</link>
                <guid isPermaLink="false">66d45da6787a2a3b05af4386</guid>
                
                    <category>
                        <![CDATA[ data ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                    <category>
                        <![CDATA[ visual studio ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 29 May 2018 23:13:09 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*QCtmxYqqBQJ_7fWmH61Tww.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Ankit Sharma</p>
<p>Microsoft has recently announced the release of a new .NET web framework called Blazor. In this article, we are going to create a web application using Blazor with the help of Entity Framework Core. We will be creating a sample Employee Record Management System and perform CRUD operations on it.</p>
<h3 id="heading-prerequisites">Prerequisites</h3>
<ul>
<li>Install .NET Core 2.1 Preview 2 SDK from <a target="_blank" href="https://www.microsoft.com/net/download/dotnet-core/sdk-2.1.300-preview2">here</a></li>
<li>Install a preview of Visual Studio 2017 v15.7 from <a target="_blank" href="https://www.visualstudio.com/vs/preview/">here</a></li>
<li>Install ASP.NET Core Blazor Language Services extension from <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=aspnet.blazor">here</a></li>
<li>SQL Server 2012 or above</li>
</ul>
<p>The Blazor framework is not supported by versions below Visual Studio 2017 v15.7.</p>
<p>Before proceeding further, I suggest you read my previous article on <a target="_blank" href="http://ankitsharmablogs.com/asp-net-core-getting-started-with-blazor/">getting started with Blazor</a>.</p>
<h3 id="heading-source-code">Source code</h3>
<p>Also, I would recommend that you get the source code from <a target="_blank" href="https://github.com/AnkitSharma-007/ASPCore.BlazorCrud">Github</a> before getting started.</p>
<h3 id="heading-creating-the-table">Creating the table</h3>
<p>We will be using a DB table to store all the records of the employees.</p>
<p>Open SQL Server and use the following script to create the <strong>tblEmployee</strong> table:</p>
<pre><code>Create table tblEmployee(            EmployeeId int IDENTITY(<span class="hljs-number">1</span>,<span class="hljs-number">1</span>) NOT NULL,            Name varchar(<span class="hljs-number">20</span>) NOT NULL,            City varchar(<span class="hljs-number">20</span>) NOT NULL,            Department varchar(<span class="hljs-number">20</span>) NOT NULL,            Gender varchar(<span class="hljs-number">6</span>) NOT NULL        )
</code></pre><p>Now, let’s move on to create our web application.</p>
<h3 id="heading-create-the-blazor-web-application">Create the Blazor web application</h3>
<p>Open Visual Studio and select File &gt;&gt; New &gt;&gt; Project.</p>
<p>After selecting the project, a “New Project” dialog will open. Select .NET Core inside Visual C# menu from the left panel.</p>
<p>Then, select “ASP.NET Core Web Application” from the available project types. Put the name of the project as <strong>BlazorCrud</strong> and press OK.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/zGPbNji-3eCLIIOUvtSMtoRsF5zr0zUoajr0" alt="Image" width="650" height="397" loading="lazy"></p>
<p>After clicking OK, a new dialog will open asking you to select the project template. You will see two drop-down menus at the top left of the template window. Select “.NET Core” and “ASP.NET Core 2.0” from these dropdowns. Then, select “Blazor (ASP .NET Core hosted)” template and press OK.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/YfbWL3ZmlR36U-JVcwWOJuFkW89Lw7Fy09W0" alt="Image" width="650" height="424" loading="lazy"></p>
<p>Now, our Blazor solution will be created. You can observe the folder structure in Solution Explorer as shown in the below image.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/vUXe0DvTLL5sdKJTteAZqSWCKnXE67Kp3-q7" alt="Image" width="239" height="476" loading="lazy"></p>
<p>You will see that we have 3 project files created inside this solution:</p>
<ol>
<li>BlazorCrud.Client — It has the client side code and contains the pages that will be rendered on the browser.</li>
<li>BlazorCrud.Server — It has the server side code, such as DB related operations and the web API.</li>
<li>BlazorCrud.Shared — It contains the shared code that can be accessed by both client and server.</li>
</ol>
<p>Execute the program. It will open the browser and you will see a page similar to the one shown below.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/3TiqY1os8SRNJEzJGkejhKBKVYjDDuN2GIzb" alt="Image" width="650" height="291" loading="lazy"></p>
<p>Here you can see a navigation menu on the left side, which contains the navigation to the pages in our application. By default, we have “Counter” and “Fetch Data” pages provided in our application. These default pages will not affect our application, but for the sake of this tutorial, we will delete the <strong>fetchdata</strong> and <strong>counter</strong> pages from <strong>BlazorCrud.Client/Pages</strong> folder.</p>
<h3 id="heading-adding-the-model-to-the-application">Adding the model to the application</h3>
<p>Right click on BlazorCrud.Shared project and then select Add &gt;&gt; New Folder and name the f<strong>older</strong> Models. We will be adding our model class in this folder only.</p>
<p>Right click on the Models folder and select Add &gt;&gt; Class. Name your <strong>class Emplo</strong>_ye_e.cs. This class will contain our Employee model properties. No<strong>w our BlazorCrud.</strong>Shared project has the following structure:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/82zqiyP54mNDcU7wAnUoodOR35OfmJvdoJGx" alt="Image" width="209" height="170" loading="lazy"></p>
<p>Open <strong>Employee.cs</strong> and put the following code in it:</p>
<pre><code>using System;  using System.Collections.Generic;  using System.ComponentModel.DataAnnotations;  using System.Text;    namespace BlazorCrud.Shared.Models  {      public <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Employee</span>      </span>{          public int EmployeeId { get; set; }          [Required]          public string Name { get; set; }          [Required]          public string Gender { get; set; }          [Required]          public string Department { get; set; }          [Required]          public string City { get; set; }      }  }
</code></pre><p>And so our model has been created. Now we will create our data access layer.</p>
<h3 id="heading-creating-the-data-access-layer-for-the-application">Creating the data access layer for the application</h3>
<p>Right click on BlazorCrud.Server project and then select Add &gt;&gt; New Folder and name the f<strong>older Data</strong>Access. We will be adding our classes to handle database-related operations inside this folder only.</p>
<p>Right click on the <strong>DataAccess</strong> folder and select Add &gt;&gt; Class. Name your <strong>class EmployeeCont</strong>_ex_t.cs. This is our Entity Framework DB context class that allows us to interact with the database. <strong>Open EmployeeCont</strong>_e_xt.cs and put the following code into it:</p>
<pre><code>using BlazorCrud.Shared.Models;  using Microsoft.EntityFrameworkCore;  using System;  using System.Collections.Generic;  using System.Linq;  using System.Threading.Tasks;    namespace BlazorCrud.Server.DataAccess  {      public <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">EmployeeContext</span> : <span class="hljs-title">DbContext</span>      </span>{          public virtual DbSet&lt;Employee&gt; tblEmployee { get; set; }            protected override <span class="hljs-keyword">void</span> OnConfiguring(DbContextOptionsBuilder optionsBuilder)          {              <span class="hljs-keyword">if</span> (!optionsBuilder.IsConfigured)              {                  optionsBuilder.UseSqlServer(@<span class="hljs-string">"Put Your Connection string here"</span>);              }          }      }  }
</code></pre><p>Do not forget to put in your own connection string.</p>
<p>Add one more class to <strong>DataAccess</strong> folder and name it <strong>EmployeeDataAccessLayer.cs</strong><em>.</em> This class will handle our CRUD related DB operations. Open <strong>EmployeeDataAccessLayer.cs</strong> and put the following code into it:</p>
<pre><code>using BlazorCrud.Shared.Models;  using Microsoft.EntityFrameworkCore;  using System;  using System.Collections.Generic;  using System.Linq;  using System.Threading.Tasks;    namespace BlazorCrud.Server.DataAccess  {      public <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">EmployeeDataAccessLayer</span>      </span>{          EmployeeContext db = <span class="hljs-keyword">new</span> EmployeeContext();            <span class="hljs-comment">//To Get all employees details           public IEnumerable&lt;Employee&gt; GetAllEmployees()          {              try              {                  return db.tblEmployee.ToList();              }              catch              {                  throw;              }          }            //To Add new employee record             public void AddEmployee(Employee employee)          {              try              {                  db.tblEmployee.Add(employee);                  db.SaveChanges();              }              catch              {                  throw;              }          }            //To Update the records of a particluar employee            public void UpdateEmployee(Employee employee)          {              try              {                  db.Entry(employee).State = EntityState.Modified;                  db.SaveChanges();              }              catch              {                  throw;              }          }            //Get the details of a particular employee            public Employee GetEmployeeData(int id)          {              try              {                  Employee employee = db.tblEmployee.Find(id);                  return employee;              }              catch              {                  throw;              }          }            //To Delete the record of a particular employee            public void DeleteEmployee(int id)          {              try              {                  Employee emp = db.tblEmployee.Find(id);                  db.tblEmployee.Remove(emp);                  db.SaveChanges();              }              catch              {                  throw;              }          }      }  }</span>
</code></pre><p>Now our data access layer is complete. Next, we will proceed to create our web API Controller.</p>
<h3 id="heading-adding-the-web-api-controller-to-the-application">Adding the web API controller to the application</h3>
<p>Right click on <strong>BlazorCrud.Server/Controllers</strong> folder and select Add &gt;&gt; New Item. An “Add New Item” dialog box will open. S<strong>elect A</strong>SP.NET from the left panel, then select “API Controller Class” from the templates panel and na<strong>me it EmployeeControl</strong>ler.cs. Press OK.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/RKROzzhcRCSFVHrkYQcltQmFt7xPha6jCZPM" alt="Image" width="650" height="397" loading="lazy"></p>
<p>This will create our API <strong>EmployeeController</strong> class.</p>
<p>We will call the methods of the <strong>EmployeeDataAccessLayer</strong> class to fetch data and pass on the data to the client side.</p>
<p>Open the <strong>EmployeeController.cs</strong> file and put the following code into it:</p>
<pre><code>using System;  using System.Collections.Generic;  using System.Linq;  using System.Threading.Tasks;  using BlazorCrud.Server.DataAccess;  using BlazorCrud.Shared.Models;  using Microsoft.AspNetCore.Mvc;    namespace BlazorCrud.Server.Controllers  {      public <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">EmployeeController</span> : <span class="hljs-title">Controller</span>      </span>{          EmployeeDataAccessLayer objemployee = <span class="hljs-keyword">new</span> EmployeeDataAccessLayer();            [HttpGet]          [Route(<span class="hljs-string">"api/Employee/Index"</span>)]          public IEnumerable&lt;Employee&gt; Index()          {              <span class="hljs-keyword">return</span> objemployee.GetAllEmployees();          }            [HttpPost]          [Route(<span class="hljs-string">"api/Employee/Create"</span>)]          public <span class="hljs-keyword">void</span> Create([FromBody] Employee employee)          {              <span class="hljs-keyword">if</span> (ModelState.IsValid)                  objemployee.AddEmployee(employee);          }            [HttpGet]          [Route(<span class="hljs-string">"api/Employee/Details/{id}"</span>)]          public Employee Details(int id)          {                <span class="hljs-keyword">return</span> objemployee.GetEmployeeData(id);          }            [HttpPut]          [Route(<span class="hljs-string">"api/Employee/Edit"</span>)]          public <span class="hljs-keyword">void</span> Edit([FromBody]Employee employee)          {              <span class="hljs-keyword">if</span> (ModelState.IsValid)                  objemployee.UpdateEmployee(employee);          }            [HttpDelete]          [Route(<span class="hljs-string">"api/Employee/Delete/{id}"</span>)]          public <span class="hljs-keyword">void</span> Delete(int id)          {              objemployee.DeleteEmployee(id);          }      }  }
</code></pre><p>At this point, our <strong>BlazorCrud.Server</strong> project has the following structure:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/JtmrDM7QtuDas0bq-OqihzMpn2T0PaakQjLg" alt="Image" width="255" height="293" loading="lazy"></p>
<p>We are done with our backend logic. So we will now proceed to code our client side.</p>
<h3 id="heading-adding-razor-view-to-the-application">Adding Razor View to the application</h3>
<p>Right click on the <strong>BlazorCrud.Client/Pages</strong> folder and then select Add &gt;&gt; New Item. An “Add New Item” dialog box will open, select Web from the left panel, then select “Razor View” from the templates panel and na<strong>me it FetchEmployee.</strong>_c_shtml.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/HqQn5jyacZB00aY6c9-e-GK7V7GZpqn77KUg" alt="Image" width="650" height="397" loading="lazy"></p>
<p>This will add a <strong>FetchEmployee.cshtml</strong> page to our <strong>BlazorCrud.Client/Pages</strong> folder. Similarly, add 3 more pages: <strong>AddEmployee.cshtml</strong><em>,</em> <strong>EditEmployee.cshtml,</strong> and <strong>DeleteEmployee.cshtml</strong><em>.</em></p>
<p>Now our <strong>BlazorCrud.Client</strong> project has the following structure:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/DlAVomYnrhDMD1JCP8qExF5wGNTTOUMDlr9z" alt="Image" width="225" height="367" loading="lazy"></p>
<p>Let’s add code to these pages.</p>
<h3 id="heading-fetchemployeecshtml">FetchEmployee.cshtml</h3>
<p>This page will display all the employee records present in the database. Additionally, we will also provide the action methods <strong>Edit</strong> and <strong>Delete</strong> on each record.</p>
<p>Open <strong>FetchEmployee.cshtml</strong> and put the following code in it:</p>
<pre><code>@using BlazorCrud.Shared.Models@page <span class="hljs-string">"/fetchemployee"</span>@inject HttpClient Http&lt;h1&gt;Employee Data&lt;<span class="hljs-regexp">/h1&gt;&lt;p&gt;This component demonstrates fetching Employee data from the server.&lt;/</span>p&gt;<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/addemployee"</span>&gt;</span>Create New<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>@<span class="hljs-keyword">if</span> (empList == <span class="hljs-literal">null</span>){    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">em</span>&gt;</span>Loading...<span class="hljs-tag">&lt;/<span class="hljs-name">em</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>}<span class="hljs-keyword">else</span>{    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">class</span>=<span class="hljs-string">'table'</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">thead</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>ID<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Name<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Gender<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Department<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>City<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>            <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>        <span class="hljs-tag">&lt;/<span class="hljs-name">thead</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">tbody</span>&gt;</span>            @foreach (var emp in empList)            {                <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>                    <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>@emp.EmployeeId<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>                    <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>@emp.Name<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>                    <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>@emp.Gender<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>                    <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>@emp.Department<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>                    <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>@emp.City<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>                    <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>                        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">'/editemployee/@emp.EmployeeId'</span>&gt;</span>Edit<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>  |                        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">'/delete/@emp.EmployeeId'</span>&gt;</span>Delete<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>                    <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>                <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>            }        <span class="hljs-tag">&lt;/<span class="hljs-name">tbody</span>&gt;</span>    <span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span></span>}@functions {Employee[] empList;protected override <span class="hljs-keyword">async</span> Task OnInitAsync(){    empList = <span class="hljs-keyword">await</span> Http.GetJsonAsync&lt;Employee[]&gt;    (<span class="hljs-string">"/api/Employee/Index"</span>);}}
</code></pre><p>Let’s understand this code. At the top, we have included the <strong>BlazorEFApp.Shared.Models</strong> namespace so that we can use our Employee model class in this page.</p>
<p>We are defining the route of this page using the @page directive. So, in this application, if we append “/fetchemployee” to the base URL, we will be redirected to this page. We are also injecting HttpClient service to enable the web API call.</p>
<p>Then we have defined the HTML part to display all the employees records in a tabular manner. We have also added two action links for <strong>Edit</strong> and <strong>Delete</strong> which will navigate to the <strong>EditEmployee.cshtml</strong> and <strong>DeleteEmployee.cshtml</strong> pages, respectively.</p>
<p>At the bottom of the page, we have a @functions section which contains our business logic. We have created an array variable <strong>empList</strong> of type Employee, and we and populate it inside <strong>OnInitAsync</strong> method by calling our web API. This will bind to our HTML table on the page load.</p>
<h3 id="heading-addemployeecshtml">AddEmployee.cshtml</h3>
<p>This page is used to create a new employee record.</p>
<p>Open <strong>AddEmployee.cshtml</strong> and put the following code into it:</p>
<pre><code>@using BlazorCrud.Shared.Models@page <span class="hljs-string">"/addemployee"</span>@inject HttpClient Http@inject Microsoft.AspNetCore.Blazor.Services.IUriHelper UriHelper&lt;h1&gt;Create&lt;<span class="hljs-regexp">/h1&gt;&lt;h3&gt;Employee&lt;/</span>h3&gt;<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">hr</span> /&gt;</span></span><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"row"</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"col-md-4"</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">form</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-group"</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"Name"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"control-label"</span>&gt;</span>Name<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"Name"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">bind</span>=<span class="hljs-string">"@emp.Name"</span> /&gt;</span>            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-group"</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">asp-for</span>=<span class="hljs-string">"Gender"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"control-label"</span>&gt;</span>Gender<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">select</span> <span class="hljs-attr">asp-for</span>=<span class="hljs-string">"Gender"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">bind</span>=<span class="hljs-string">"@emp.Gender"</span>&gt;</span>                    <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">""</span>&gt;</span>-- Select Gender --<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>                    <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Male"</span>&gt;</span>Male<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>                    <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Female"</span>&gt;</span>Female<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>                <span class="hljs-tag">&lt;/<span class="hljs-name">select</span>&gt;</span>            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-group"</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">asp-for</span>=<span class="hljs-string">"Department"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"control-label"</span>&gt;</span>Department<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">asp-for</span>=<span class="hljs-string">"Department"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">bind</span>=<span class="hljs-string">"@emp.Department"</span> /&gt;</span>            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-group"</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">asp-for</span>=<span class="hljs-string">"City"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"control-label"</span>&gt;</span>City<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">asp-for</span>=<span class="hljs-string">"City"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">bind</span>=<span class="hljs-string">"@emp.City"</span> /&gt;</span>            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-group"</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"btn btn-default"</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"@(async () =&gt; await CreateEmployee())"</span>&gt;</span>Save<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"btn"</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"@cancel"</span>&gt;</span>Cancel<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>        <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>@functions {Employee emp = <span class="hljs-keyword">new</span> Employee();protected <span class="hljs-keyword">async</span> Task CreateEmployee(){    <span class="hljs-keyword">await</span> Http.SendJsonAsync(HttpMethod.Post, <span class="hljs-string">"/api/Employee/Create"</span>, emp);    UriHelper.NavigateTo(<span class="hljs-string">"/fetchemployee"</span>);}<span class="hljs-keyword">void</span> cancel(){    UriHelper.NavigateTo(<span class="hljs-string">"/fetchemployee"</span>);}}
</code></pre><p>In this page the route is “/addemployee”.</p>
<p>We are also injecting the “Microsoft.AspNetCore.Blazor.Services.IUriHelper” service to enable URL redirection. The HTML part will generate a form to get input from the user. The attribute “bind” is used to bind the value entered in the textbox to the properties of the Employee object.</p>
<p>In the @functions section, we have defined two methods. The method <strong>CreateEmployee</strong> will be invoked on clicking the “Submit” button and will send a POST request to our API along with the Employee object emp.</p>
<p>The <strong>Cancel</strong> method will be invoked on clicking the cancel button and will redirect the user back to the <strong>FetchEmployee</strong> page.</p>
<h3 id="heading-editemployeecshtml">EditEmployee.cshtml</h3>
<p>This page is used to edit the details of an employee.</p>
<p>Open <strong>EditEmployee.cshtml</strong> and put the following code into it:</p>
<pre><code>@using BlazorCrud.Shared.Models@page <span class="hljs-string">"/editemployee/{empID}"</span>@inject HttpClient Http@inject Microsoft.AspNetCore.Blazor.Services.IUriHelper UriHelper&lt;h2&gt;Edit&lt;<span class="hljs-regexp">/h2&gt;&lt;h4&gt;Employees&lt;/</span>h4&gt;<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">hr</span> /&gt;</span></span><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"row"</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"col-md-4"</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">form</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-group"</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"Name"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"control-label"</span>&gt;</span>Name<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"Name"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">bind</span>=<span class="hljs-string">"@emp.Name"</span> /&gt;</span>            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-group"</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">asp-for</span>=<span class="hljs-string">"Gender"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"control-label"</span>&gt;</span>Gender<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">select</span> <span class="hljs-attr">asp-for</span>=<span class="hljs-string">"Gender"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">bind</span>=<span class="hljs-string">"@emp.Gender"</span>&gt;</span>                    <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">""</span>&gt;</span>-- Select Gender --<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>                    <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Male"</span>&gt;</span>Male<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>                    <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Female"</span>&gt;</span>Female<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>                <span class="hljs-tag">&lt;/<span class="hljs-name">select</span>&gt;</span>            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-group"</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">asp-for</span>=<span class="hljs-string">"Department"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"control-label"</span>&gt;</span>Department<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">asp-for</span>=<span class="hljs-string">"Department"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">bind</span>=<span class="hljs-string">"@emp.Department"</span> /&gt;</span>            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">" form-group"</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">asp-for</span>=<span class="hljs-string">"City"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"control-label"</span>&gt;</span>City<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">asp-for</span>=<span class="hljs-string">"City"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">bind</span>=<span class="hljs-string">"@emp.City"</span> /&gt;</span>            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-group"</span>&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Save"</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"@(async () =&gt; await UpdateEmployee())"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"btn btn-default"</span> /&gt;</span>                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Cancel"</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"@cancel"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"btn"</span> /&gt;</span>            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>        <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>@functions {[Parameter]string empID { get; set; }Employee emp = <span class="hljs-keyword">new</span> Employee();protected override <span class="hljs-keyword">async</span> Task OnInitAsync(){    emp = <span class="hljs-keyword">await</span> Http.GetJsonAsync&lt;Employee&gt;(<span class="hljs-string">"/api/Employee/Details/"</span> + Convert.ToInt32(empID));}protected <span class="hljs-keyword">async</span> Task UpdateEmployee(){    <span class="hljs-keyword">await</span> Http.SendJsonAsync(HttpMethod.Put, <span class="hljs-string">"api/Employee/Edit"</span>, emp);    UriHelper.NavigateTo(<span class="hljs-string">"/fetchemployee"</span>);}<span class="hljs-keyword">void</span> cancel(){    UriHelper.NavigateTo(<span class="hljs-string">"/fetchemployee"</span>);}}
</code></pre><p>In this page we have defined the route as “/editemployee/{empID}”. <strong>empID</strong> is an URL parameter of type string declared in the @functions section. We will use the [Parameter] attribute to mark the variable as a parameter. To navigate to this page, we need to pass the employee id in the URL which will be captured in the <strong>empID</strong> variable.</p>
<p>If we do not mark the variable with the [Parameter] attribute, we will get the following error: “Object of type ‘BlazorCrud.Client.Pages.EditEmployee’ has a property matching the name ’empID’, but it does not have [ParameterAttribute] applied.” This will not allow <strong>empID</strong> to bind to the employee id value passed in the parameter.</p>
<p>The HTML part is similar to that of the <strong>AddEmployee.cshtml</strong> page. The attribute “bind” is used for two-way binding, that is binding the textbox values to employee object properties, and vice versa.</p>
<p>Inside the @functions section, we are fetching the employee records in the <strong>OnInitAsync</strong> method based on the employeeID passed in the parameter. This will bind to the fields in the form on page load itself.</p>
<p>The <strong>UpdateEmployee</strong> method will send a PUT request to our API along with the Employee object emp. The <strong>Cancel</strong> method will be invoked on clicking the cancel button and will redirect the user back to the <strong>FetchEmployee</strong> page.</p>
<h3 id="heading-deleteemployeecshtml">DeleteEmployee.cshtml</h3>
<p>This page will be used to delete an employee record.</p>
<p>Open <strong>DeleteEmployee.cshtml</strong> and put the following code into it:</p>
<pre><code>@using BlazorCrud.Shared.Models@page <span class="hljs-string">"/delete/{empID}"</span>@inject HttpClient Http@inject Microsoft.AspNetCore.Blazor.Services.IUriHelper UriHelper&lt;h2&gt;Delete&lt;<span class="hljs-regexp">/h2&gt;&lt;h3&gt;Are you sure you want to delete employee with id : @empID&lt;/</span>h3&gt;<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">br</span> /&gt;</span></span><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"col-md-4"</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"table"</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Name<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>@emp.Name<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Gender<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>@emp.Gender<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Department<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>@emp.Department<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>City<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>            <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>@emp.City<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>        <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>    <span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-group"</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Delete"</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"@(async () =&gt; await Delete())"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"btn btn-default"</span> /&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Cancel"</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"@cancel"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"btn"</span> /&gt;</span>    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>@functions {[Parameter]string empID { get; set; }Employee emp = <span class="hljs-keyword">new</span> Employee();protected override <span class="hljs-keyword">async</span> Task OnInitAsync(){    emp = <span class="hljs-keyword">await</span> Http.GetJsonAsync&lt;Employee&gt;    (<span class="hljs-string">"/api/Employee/Details/"</span> + Convert.ToInt32(empID));}protected <span class="hljs-keyword">async</span> Task Delete(){    <span class="hljs-keyword">await</span> Http.DeleteAsync(<span class="hljs-string">"api/Employee/Delete/"</span> + Convert.ToInt32(empID));    UriHelper.NavigateTo(<span class="hljs-string">"/fetchemployee"</span>);}<span class="hljs-keyword">void</span> cancel(){    UriHelper.NavigateTo(<span class="hljs-string">"/fetchemployee"</span>);}}
</code></pre><p>The route for this page is also parameterized, since we are fetching the record of the employee on page load.</p>
<p>The HTML part will display the employee data and ask the user for confirmation to delete the employee record.</p>
<p>Inside the @functions section, we are fetching the employee records inthe <strong>OnInitAsync</strong> method based on the employeeID passed in the parameter. This will display the employee records as the page loads.</p>
<p>The <strong>Delete</strong> method will be invoked on clicking the “Delete” button, which will send a delete request to our API along with the employee ID of the employee to be deleted. On successful deletion, the user will be navigated back to the <strong>FetchEmployee</strong> page.</p>
<h3 id="heading-adding-a-link-to-the-navigation-menu">Adding a link to the Navigation menu</h3>
<p>The last step is to define the navigation menu for our application. Open the <strong>BlazorCrud.Client/Shared/ NavMenu.cshtml</strong> file and put the following code in it:</p>
<pre><code>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"top-row pl-4 navbar navbar-dark"</span>&gt;    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"navbar-brand"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/"</span>&gt;</span>BlazorCrud<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span></span>    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"navbar-toggler"</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">@ToggleNavMenu</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"navbar-toggler-icon"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>    <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>&lt;<span class="hljs-regexp">/div&gt;&lt;div class=@(collapseNavMenu ? "collapse" : null) onclick=@ToggleNavMenu&gt;    &lt;ul class="nav flex-column"&gt;        &lt;li class="nav-item px-3"&gt;            &lt;NavLink class="nav-link" href="/</span><span class="hljs-string">" Match=NavLinkMatch.All&gt;                &lt;span class="</span>oi oi-home<span class="hljs-string">" aria-hidden="</span><span class="hljs-literal">true</span><span class="hljs-string">"&gt;&lt;/span&gt; Home            &lt;/NavLink&gt;        &lt;/li&gt;        &lt;li class="</span>nav-item px<span class="hljs-number">-3</span><span class="hljs-string">"&gt;            &lt;NavLink class="</span>nav-link<span class="hljs-string">" href="</span>/fetchemployee<span class="hljs-string">"&gt;                &lt;span class="</span>oi oi-list-rich<span class="hljs-string">" aria-hidden="</span><span class="hljs-literal">true</span><span class="hljs-string">"&gt;&lt;/span&gt; Fetch employee            &lt;/NavLink&gt;        &lt;/li&gt;    &lt;/ul&gt;&lt;/div&gt;@functions {bool collapseNavMenu = true;void ToggleNavMenu(){    collapseNavMenu = !collapseNavMenu;}}</span>
</code></pre><p>And that’s it. We have created our first <strong>ASP.NET</strong> Core application using Blazor and Entity Framework Core.</p>
<h3 id="heading-execution-demo">Execution demo</h3>
<p>Launch the application.</p>
<p>A web page will open as shown in the image below. The navigation menu on the left will show the navigation link for the Home and Fetch Employee pages.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/cV9HHW5sPNGBrNhpjj2G44EmN1wM5yJl6hrd" alt="Image" width="650" height="329" loading="lazy"></p>
<p>Click on <strong>Fetch employee</strong> in the navigation menu. It will redirect to the <strong>FetchEmployee</strong> view and will display all the employee data on the page. Notice that the URL has “/fetchemployee” appended to it, as we have defined it using the @page directive.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/CmRK4F3HHkoZ5sSc3Z24Ql6YqXiyUTAEyRFV" alt="Image" width="650" height="329" loading="lazy"></p>
<p>Since we have not added any data, it is empty.</p>
<p>Click on <strong>CreateNew</strong> to navigate to <strong>AddEmployee</strong> view. Notice the URL has “/addemployee” appended to it, as we have defined it using the @page directive. Add a new Employee record as shown in the image below:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/nuRceVySlBWelVt1sdrknlR219XBQFrEKkyR" alt="Image" width="650" height="690" loading="lazy"></p>
<p>After inserting data in all the fields, click on the “Save” button. The new employee record will be created, and you will be redirected to the <strong>FetchEmployee</strong> view, which will display records of all the employees. Here, we can also see the action methods <strong>Edit</strong> and <strong>Delete</strong> corresponding to each record.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/GC6B6tuFby6eiofdFQjlNHxyjTeD48NvrDtq" alt="Image" width="650" height="323" loading="lazy"></p>
<p>If we want to edit an existing employee record, we just click on the <strong>Edit</strong> action link. It will open the <strong>Edit</strong> view as shown below. Here we can change the employee data. Notice that we have passed the employee id in the URL parameter.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/RSC3aHrWDT7cg2WdlXpOT9Bh6s0YqbriinOL" alt="Image" width="650" height="699" loading="lazy"></p>
<p>Here we have changed the City of employee Swati from New Delhi to Chennai. Click on “Save” to return to the FetchEmployee view to see the updated changes as highlighted in the image below:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/5Q4wzYh7cML-EqFzrTcKOxQY24f5G73yfdhk" alt="Image" width="650" height="349" loading="lazy"></p>
<p>Now, we will perform the Delete operation on the employee named Rahul. Click on the <strong>Delete</strong> action link which will open the <strong>Delete</strong> view asking for a confirmation to delete. Notice that we have passed the employee id in the URL parameter.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/GKJoohKLsrb7CNgy6I2t-kDh7K6qnM3VMDfO" alt="Image" width="650" height="349" loading="lazy"></p>
<p>Once we click on the Delete button, it will delete the employee record and we will be redirected to the <strong>FetchEmployee</strong> view. Here, we can see that the employee with name Rahul has been removed from our record.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/XLbblGjSRJsEqyUoo4-ZfFnAPIMhwNUQWHc1" alt="Image" width="650" height="349" loading="lazy"></p>
<h3 id="heading-hosting-the-application">Hosting the application</h3>
<p>To learn how to host a Blazor application using IIS, refer to <a target="_blank" href="http://ankitsharmablogs.com/deploying-a-blazor-application-on-iis/">Deploying a Blazor Application on IIS</a>.</p>
<h3 id="heading-see-also">See Also</h3>
<ul>
<li><a target="_blank" href="http://ankitsharmablogs.com/asp-net-core-crud-using-angular-5-and-entity-framework-core/">ASP.NET Core — CRUD Using Angular 5 And Entity Framework Core</a></li>
<li><a target="_blank" href="http://ankitsharmablogs.com/crud-operations-asp-net-core-using-angular-5-ado-net/">CRUD Operations With ASP.NET Core Using Angular 5 and ADO.NET</a></li>
<li><a target="_blank" href="http://ankitsharmablogs.com/getting-started-with-angular-5-using-visual-studio-code/">Getting Started With Angular 5 Using Visual Studio Code</a></li>
<li><a target="_blank" href="http://ankitsharmablogs.com/crud-operation-asp-net-core-mvc-using-visual-studio-code-ef/">CRUD Operation With ASP.NET Core MVC Using Visual Studio Code and EF</a></li>
<li><a target="_blank" href="http://ankitsharmablogs.com/crud-operation-with-asp-net-core-mvc-using-ado-net/">CRUD Operation With ASP.NET Core MVC Using ADO.NET and Visual Studio 2017</a></li>
<li><a target="_blank" href="http://ankitsharmablogs.com/crud-operation-with-asp-net-core-mvc-using-visual-studio-code-and-ado-net/">CRUD Operation With ASP.NET Core MVC using Visual Studio Code and ADO.NET</a></li>
</ul>
<h3 id="heading-conclusion">Conclusion</h3>
<p>We have created an ASP.NET Core application using the new web framework Blazor and Entity Framework Core with the help of Visual Studio 2017 and SQL Server 2012. We have also performed CRUD operations on our application.</p>
<p>You can also fork this application on <a target="_blank" href="https://github.com/AnkitSharma-007/ASPCore.BlazorCrud">Github</a>. Try this new framework and let me know what you think of it in the comments section below.</p>
<p>Get my book <a target="_blank" href="https://www.amazon.com/Blazor-Quick-Start-Guide-applications/dp/178934414X/ref=sr_1_1?ie=UTF8&amp;qid=1542438251&amp;sr=8-1&amp;keywords=Blazor-Quick-Start-Guide">Blazor Quick Start Guide</a> to learn more about Blazor.</p>
<p>You can also find this article at <a target="_blank" href="https://www.c-sharpcorner.com/article/asp-net-core-crud-using-blazor-and-entity-framework-core/">C# Corner</a>.</p>
<p>You can check my other articles on ASP .NET Core <a target="_blank" href="http://ankitsharmablogs.com/category/asp-net-core/">here</a></p>
<p>Originally published at <a target="_blank" href="https://ankitsharmablogs.com/">https://ankitsharmablogs.com/</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Favorite Visual Studio Code Extensions of 2017 ]]>
                </title>
                <description>
                    <![CDATA[ By Daniel Deutsch Here is a list of some extensions I come to enjoy with Visual Studio Code (VSCode). Since I work a lot in the front-end, most of these extensions will be useful for web developers. I have been working previously with Atom, Visual St... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/favorite-vs-code-extensions-2017-786ea235812f/</link>
                <guid isPermaLink="false">66c34a46a1d481faeda49b3f</guid>
                
                    <category>
                        <![CDATA[ editor ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ visual studio ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Visual Studio Code ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 15 Dec 2017 08:50:37 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/0*T_k_KvM8_mTaowQl." medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Daniel Deutsch</p>
<p>Here is a list of some extensions I come to enjoy with Visual Studio Code (VSCode). Since I work a lot in the front-end, most of these extensions will be useful for web developers. I have been working previously with Atom, Visual Studio and Webstorm but VSCode suits me best and is just incredible. The developer did a great job ( and still do! ). Try it for yourself and enjoy!</p>
<blockquote>
<p>_“To enjoy life, you don’t need fancy nonsense, but you do need to control your time and realize that most things just aren’t as serious as you make them out to be.” ― <a target="_blank" href="https://en.wikiquote.org/wiki/Timothy_Ferriss">Timothy Ferriss</a>_</p>
</blockquote>
<h3 id="heading-html-extensions">HTML Extensions</h3>
<h4 id="heading-auto-close-tag">Auto Close Tag</h4>
<p>Automatically add an HTML/XML close tag, same as Visual Studio IDE or Sublime Text does.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/ZLFNZjla4HzI94AlQNxR0clklBRvlDCSSBoX" alt="Image" width="800" height="521" loading="lazy"></p>
<p><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-close-tag">See more</a></p>
<h4 id="heading-auto-rename-tag">Auto Rename Tag</h4>
<p>Automatically rename a paired HTML/XML tag, same as Visual Studio IDE does.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/5lS4Jpanix2vwzO60kfeKNsKpmTrpPvIY2FR" alt="Image" width="800" height="521" loading="lazy"></p>
<p><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-rename-tag">See more</a></p>
<h4 id="heading-html-snippets">HTML Snippets</h4>
<p>This extension adds rich language support for the HTML Markup to VS Code, including: Full HTML5 Tags, Colorization and Snippets.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/iVkIkUJuKHCU2cbJZenkvPc1tQelxCsweAcF" alt="Image" width="800" height="566" loading="lazy"></p>
<p><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=abusaidm.html-snippets">See more</a></p>
<h3 id="heading-markdown-extensions">Markdown Extensions</h3>
<h4 id="heading-auto-open-markdown-preview">Auto-Open Markdown Preview</h4>
<p>This VS Code extension automatically shows Markdown preview whenever you open new Markdown file. If you feel annoying to type “Ctrl+K V” or “⌘+K V” (preview side-by-side) many times, this extension helps you.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=hnw.vscode-auto-open-markdown-preview">See more</a></p>
<h4 id="heading-markdown-toc">Markdown TOC</h4>
<p>Generate TOC (table of contents) of headlines from a parsed markdown file.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=AlanWalk.markdown-toc">See more</a></p>
<h4 id="heading-markdown-theme-kit">Markdown Theme Kit</h4>
<p>A set of themes based on SublimeText-Markdown/MarkdownEditing.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=ms-vscode.Theme-MarkdownKit">See more</a></p>
<h4 id="heading-code-spell-checker">Code Spell Checker</h4>
<p>A basic spell checker that works well with camelCase code.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker">See more</a></p>
<h3 id="heading-javascript-extensions">JavaScript Extensions</h3>
<h4 id="heading-babel-es6es7">Babel ES6/ES7</h4>
<p>Adds JavaScirpt Babel es6/es7 syntax coloring.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=dzannotti.vscode-babel-coloring">See more</a></p>
<h4 id="heading-debugger-for-chrome">Debugger for Chrome</h4>
<p>Debug your JavaScript code in the Chrome browser, or any other target that supports the Chrome Debugger protocol.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/vyZ7bM0dOPg1YEyVpGqaVsGW8A0a7rq3b1bU" alt="Image" width="800" height="500" loading="lazy"></p>
<p><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome">See more</a></p>
<h4 id="heading-eslint">ESLint</h4>
<p>Integrates ESLint into VS Code.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint">See more</a></p>
<h4 id="heading-javascript-es6-code-snippets">JavaScript (ES6) code snippets</h4>
<p>This extension contains code snippets for JavaScript in ES6 syntax for Vs Code editor (supports both JavaScript and TypeScript).<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=xabikos.JavaScriptSnippets">See more</a></p>
<h4 id="heading-code-spell-checker-1">Code Spell Checker</h4>
<p>A basic spell checker that works well with camelCase code.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=leizongmin.node-module-intellisense">See more</a></p>
<h4 id="heading-nodejs-modules-intellisense">Node.js Modules Intellisense</h4>
<p>Visual Studio Code plugin that autocompletes JavaScript / TypeScript modules in import statements.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/sCrQ2wKS-zxM7PiDbdX45pKq7cqI6Dihw5eU" alt="Image" width="639" height="390" loading="lazy"></p>
<p><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker">See more</a></p>
<h4 id="heading-react-nativereactredux-snippets-for-es6es7">React-Native/React/Redux snippets for ES6/ES7</h4>
<p><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=EQuimper.react-native-react-redux">See more</a></p>
<h4 id="heading-tslint">TSLint</h4>
<p>Integrates the tslint linter for the TypeScript language into VS Code.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=eg2.tslint">See more</a></p>
<h4 id="heading-vscode-styled-components">vscode-styled-components</h4>
<p>Syntax highlighting for styled-components<em>.</em><br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=jpoissonnier.vscode-styled-components">See more</a></p>
<h4 id="heading-graphql-for-vscode">GraphQL for VSCode</h4>
<p>GraphQL syntax highlighting, linting, auto-complete, and more!<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=kumar-harsh.graphql-for-vscode">See more</a></p>
<h4 id="heading-yarn">yarn</h4>
<p>yarn commands for VSCode.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=gamunu.vscode-yarn">See more</a></p>
<h3 id="heading-general-extensions">General Extensions</h3>
<h4 id="heading-color-highlight">Color Highlight</h4>
<p>vscode-ext-color-highlight. This extension styles css/web colors found in your document.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=naumovs.color-highlight">See more</a></p>
<h4 id="heading-custom-css-and-js-loader">Custom CSS and JS Loader</h4>
<p>Custom CSS to your VS Code. Based on Roberto Huertasm’s vscode-icons.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/xUYM4P6SmYxosSE4yQ6kNCkEnaDSOCT0fOR1" alt="Image" width="800" height="602" loading="lazy"></p>
<p><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=be5invis.vscode-custom-css">See more</a></p>
<h4 id="heading-editorconfig-for-vs-code">EditorConfig for VS Code</h4>
<p>EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs. The EditorConfig project consists of a file format for defining coding styles and a collection of text editor plugins that enable editors to read the file format and adhere to defined styles.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig">See more</a></p>
<h4 id="heading-file-templates">File Templates</h4>
<p>Visual Studio code extenstion that allows to quickly create new files based on defined templates.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=brpaz.file-templates">See more</a></p>
<h4 id="heading-git-history-git-log">Git History (git log)</h4>
<p>View git log along with the graph and details. View the history of a file (Git log) or the history of a line in a file (Git Blame). View a previous copy of the file. Compare a previous version with the version in the workspace or another. View commit log details for a selected commit. Compare commits.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/e5UGQg9a0F30-oTVtKQA5bnDKIZ8DCOatgVh" alt="Image" width="800" height="740" loading="lazy"></p>
<p><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory9">See more</a></p>
<h4 id="heading-guides">Guides</h4>
<p>A Visual Studio Code extension for more guide lines.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/xI4qAfwGK5qWdzNVlbXlGHrEY3DWiWIE1k7O" alt="Image" width="440" height="230" loading="lazy"></p>
<p><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=spywhere.guides">See more</a></p>
<h4 id="heading-material-icon-theme">Material Icon Theme</h4>
<p>The Material Icon Theme provides lots of icons based on Material Design for Visual Studio Code.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=PKief.material-icon-theme">See more</a></p>
<h4 id="heading-rainbow-brackets">Rainbow Brackets</h4>
<p>Provide rainbow colors for the round brackets, the square brackets and the squiggly brackets.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=2gua.rainbow-brackets">See more</a></p>
<h4 id="heading-prettier">Prettier</h4>
<p>VS Code package to format your JavaScript / TypeScript / CSS using Prettier.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode">See more</a></p>
<h4 id="heading-project-manager">Project Manager</h4>
<p>Manage your projects right inside Visual Studio Code. Easily access and switch between them.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=alefragnani.project-manager">See more</a></p>
<h4 id="heading-theme-seti-monokai">Theme — Seti-Monokai</h4>
<p>Seti Monokai color scheme.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=SmukkeKim.theme-setimonokai">See more</a></p>
<h4 id="heading-wakatime">WakaTime</h4>
<p>Metrics, insights, and time tracking automatically generated from your programming activity.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=WakaTime.vscode-wakatime">See more</a></p>
<h4 id="heading-settings-sync">Settings Sync</h4>
<p>Synchronize Settings, Snippets, Themes, File Icons, Launch, Keybindings, Workspaces and Extensions Across Multiple Machines Using GitHub Gist.<br><a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync">See more</a></p>
<p>Thanks for reading my article! Feel free to leave any feedback!</p>
<p>Daniel is a LL.M. student in business law, working as a software engineer and organizer of tech related events in Vienna. His current personal learning efforts focus on machine learning.</p>
<p>Connect on:</p>
<ul>
<li><a target="_blank" href="https://www.linkedin.com/in/createdd">LinkedIn</a></li>
<li><a target="_blank" href="https://github.com/Createdd">Github</a></li>
<li><a target="_blank" href="https://medium.com/@ddcreationstudi">Medium</a></li>
<li><a target="_blank" href="https://twitter.com/DDCreationStudi">Twitter</a></li>
<li><a target="_blank" href="https://steemit.com/@createdd">Steemit</a></li>
<li><a target="_blank" href="https://hashnode.com/@DDCreationStudio">Hashnode</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
