Working with GitHub Repositories and Visual Studio 2015

Read full blog post on the Infragistics Blog

GitHub is one of the most popular code sharing platforms, following the GIT algorithm for version control. In this blog post, we will learn how to work with a GitHub repository and Visual Studio 2015, and will answer the following questions:

1. How to sync or share a project from Visual Studio to a GitHub Repository

2. How to clone a GitHub Repository in Visual Studio

Syncing or Sharing project from Visual Studio in GitHub Repository

To share the project, let’s take the following steps:

Step 1: Start with creating a Repository on GitHub. To do that navigate to https://github.com/ and click on the + sign to create a new repository. In this example, I am assuming that you have already created an account in GitHub.

image

Next you need to provide information including:

  • Name of the repository
  • Description of the repository
  • Whether repository is public or private
  • Whether to initialize the repository with a README.

image

Make sure not to initialize the repository with a README. If you do so, you will encounter errors while syncing the project to the repository. Once the repository is created, click on Clone or the Download dropdown and copy the web URL as shown in the image below. We’ll need the GitHub repository URL later in Visual Studio.

image

Step 2: Install Git for Windows on the machine. You can download this here: https://git-scm.com/download/win. After downloading, follow the screens to install completely.

Step 3: Open the Visual Studio solution you want to publish to this GitHub repository in Visual Studio. In the Visual Studio Solution Explorer, right click on the solution and click on Add Solution to Source Control.

image

 

Read full blog post on the Infragistics Blog

What is the Extension Method in C#?

Read full article on Infragistics blog

I often get questions about the Extension Method in C#. The Extension Method was introduced in C# Version 3.0. and allows us to add functionalities in an existing class without modifying it, extending it, or re-compiling it.

Essentially, the Extension Method allows us to add a new method to an existing class:

  • · Without modifying it or adding code
  • · Without extending it or creating a new derived type
  • · Without recompiling the class

image

Extension methods are a special kind of static method but can be called on objects like an instance method. So, an extension method can be used in the same way as normal instance methods.

Steps to create an Extension Method

Step 1: Define a static visible class which will contain the Extension Method or Extension Methods. Make sure the class is visible to the client code by applying the appropriate accede modifier.

Step 2: Create a static method with at least the same visibility level as the containing class.

Step 3: The first parameter of the Extension Method always specifies the type method operates on. Make sure the type name is preceded with the “this” modifier.

Step 4: In the calling code, add the namespace that contains Extension Method class.

Step 5: Use the Extension Method on the type in the same instance method can be used. Keep in mind that we do not need to pass the first parameter because that denotes the type, however we should pass the second parameter onwards to call the extension method.

Read full article on Infragistics blog