Posts

Showing posts from December, 2022

Simple Walkthrough on Visual Studio Code Snippets

Image
  I guess most of the Software Developers might have used or aware of  the Code Snippet feature in Visual Studio which helps us to write  code much faster. Did any of us try to explore how Code  Snippets work or in other words how the shortcut gets converted to extensive code? Let’s explore in this post how Code Snippet work and try to see where  the code is defined for a particular Code Snippet. Exploring Existing Code Snippets First lets try to see all the existing snippets which comes by default in  Visual Studio. This can be seen by opening the Code Snippets  Manager by invoking the shortcut key(CTRL + K,CTRL +   B)  or go to Tools -> Code Snippets Manager as shown in the figure below: Once the Code Snippets Manager comes up, it will list down the  available Code Snippets which are preloaded with the manager as  shown below: Locating Code Snippet File To Understand the structure of the Code Snippet let us try...

Visual Studio Extension Development | Code Analyzer - A Complete Guide

Image
  Isn't it really cool if we could customize the Intellisense/Analyzer rule so that we can add our own analyzer rules and code fixes for the same? Yes, its possible with the help of Visual Studio Extension development toolkit. Lets walk through the steps involved for creating your own code analyzer with code fixes as visual studio extension project and then let us see the analyzer in action. Installing Necessary Toolset for Visual Studio Extension Development First step is to install the necessary tool set from the Visual Studio Installer. For this demo I am using Visual Studio 2022. Launch the Visual Studio Installer from the programs and Select the Visual Studio Extension Development from other Toolsets if not already checked as shown in the figure below and click on Modify   Creating New Analyzer Project with Code Fix in Visual Studio Once its successfully installed and updated, Project templates would be available from the Extension. Create a new project with the " Analyze...

More About Null Pointer Exception in C++

Image
  We all might have encountered with the "infamous" Null Pointer Exception or Access Violation Exception during our development in C++.These seems to be pretty annoying especially when the code becomes complex and involves different modules. Here we are going to have a closer look at Null Pointer case and try to understand or decode what causes this exception with an example. Must Read : Memory Leak in C++ Understanding Null Pointer Exception Scenario Below code presents an example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 class Classic { public: string getName() const { return m_name; } void print() { cout << "Print called" ; } private: string m_name; }; int main () { Classic * c = nullptr; c -> print(); // did not throw exception string name = c -> getName(); //Threw null pointer exception cin.get(); return 0 ; } As shown in above code a Class Classic is defined with ...

Easy way to do Dynamic Type Casting using Reflection in C#. | Converting Type variable to Type

Image
  Some times we might have come across situations where in we are provided with the type information of the object to be instantiated at runtime. In those cases we use the type information to create an object using Reflection, but unfortunately we will not be able to type cast to the desired type since the type information is available to us as a variable. In those cases we can make use of a generic Cast method and invoke that method during runtime with the help of Reflection. This is also called as Dynamic Type Casting using Reflection. We can see this with the help of an C# code example as shown below: Code Example for Dynamic Type Casting 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 using System ; using System .Collections; using System .Collections.Generic; using System .IO; using System .Li...