Introduction
- References
- Impact
- Test
- Changes

Let's see a brief expiation of these three features of CodeLens as listed above.
References
References is on of the features of CodeLens that shows how many times a specific method/property/class is being used in the code files. Suppose we have a method named GetEmployeeDetails() that returns the information of an employee, like name, designation, organization, salary and so on. If we call this method inside the project code, the reference count will be increased from zero to the number of times we used this method. Let's see it through an example code.
Example: In the following example the GetEmployeeDetails() method is showing 1 reference because it is called/use only one time inside the Main method.

Program Code: (References)
- class EmployeeInfo
- {
- //Public Properties
- public string FullName { get; set; }
- public string Designation { get; set; }
- public string Organization { get; set; }
- public double Salary { get; set; }
- public string Email { get; set; }
- static void Main(string[] args)
- {
- // Calling GetEmployeeDetails() method
- EmployeeInfo employee = new EmployeeInfo();
- employee.GetEmployeeDetails("Ranjan Kumar","Software Developer","MCN Solutions Pvt. Ltd.","[email protected]",52000.00);
- }
- //Get Employee Details
- public void GetEmployeeDetails(string _name,string _designation,string _organization,string _email,double _salary)
- {
- FullName = _name;
- Designation = _designation;
- Organization = _organization;
- Email = _email;
- Salary = _salary;
- string data = "Name\t:" + FullName + "\nDesignation\t: " + Designation + "\nEmail\t: " + Email + "\nSalary\t: " + Salary;
- Console.WriteLine("Employee Detrails:\n\n" + data);
- Console.ReadLine();
- }
- }
To see the referencing code double-click on References (2 References), an indicator popup will be shown just above CodeLens. It will show where this method is being used.

If we want to see the graphical representation of references, it is possible. To do that double-click on references of CodeLens then a popup box will be shown. In the bottom of the popup box we will see a link named Show on Code Map. Now click on this link and a graphical view of CodeLens will be shown in the CodeMap1.dgml file.

Impact
Impact is nothing, it's the view of references that indicates the changes to a method that is referenced one or more times. If any changes occur inside the method, the CodeLens starts to blink which indicates that if we change anything inside this method, it will impact these places.

Test: Test is the important part of CodeLens that indicates whether this method was unit tested or not. For example if a method having 1 is passed in CodeLens then this method is tested by Unit Testing.
To do unit testing with a project, we have attached a UnitTest project with this article, download this file to see it practically. For the moment see the following example code of Unit Testing.
Create a Console Application using Git Version Control and do the following:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace CodeLensExampleProject
- {
- class EmployeeInfo
- {
- //Public Properties
- public string FullName { get; set; }
- public string Designation { get; set; }
- public string Organization { get; set; }
- public double Salary { get; set; }
- public string Email { get; set; }
- static void Main(string[] args)
- {
- // Calling GetEmployeeDetails() method
- EmployeeInfo employee = new EmployeeInfo();
- employee.GetEmployeeDetails("Ranjan Kumar","Software Developer","MCN Solutions Pvt. Ltd.","[email protected]",52000.00);
- ErrorHandler erh = new ErrorHandler();
- }
- public void SetAndGetEmployeeDetails()
- {
- EmployeeInfo employee1 = new EmployeeInfo();
- employee1.GetEmployeeDetails("Suraj Kumar", "Web Designer", "MCN Solutions Pvt. Ltd.", "[email protected]", 38000.00);
- }
- //Get Employee Details
- public void GetEmployeeDetails(string _name,string _designation,string _organization,string _email,double _salary)
- {
- FullName = _name;
- Designation = _designation;
- Organization = _organization;
- Email = _email;
- Salary = _salary;
- string empDetails = "Name\t:" + FullName + "\nDesignation\t: " + Designation + "\nEmail\t: " + Email + "\nSalary\t: " + Salary;
- Console.WriteLine("Employee Detrails:\n\n" + empDetails);
- Console.ReadLine();
- }
- ErrorHandler obj1 = new ErrorHandler();
- }
- //Error Handling Class
- public class ErrorHandler
- {
- public void HanldeError()
- {
- //changes
- }
- }
- }
Step 2
Now add a UnitTest Project to this Console Application and do the following code.
- using System;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using CodeLensExampleProject;
- namespace UnitTest
- {
- [TestClass]
- public class UnitTest1
- {
- [TestMethod]
- public void TestMethod1()
- {
- ErrorHandler erh = new ErrorHandler();
- erh.HanldeError();
- }
- }
- }

In this article we saw what is CodeLens does and how to use it with Git or Team Foundation Version Control (TFVC) version control as well as how to test it using unit testing.

Kuppurasu NagarajPosted Apr 24, 2016, 12:41 PM
Nice Sharing..
Guest UserPosted Nov 26, 2014, 3:57 AM
I'm sure we dont need Resharper and other similar tools after using it!
Guest UserPosted Nov 26, 2014, 3:57 AM
Code Lens feature is cool!
Anupam SinghPosted Nov 26, 2014, 2:41 AM
Hi Praveen, nice review, can you share how does it update "author" link.
ali zolfiPosted Nov 26, 2014, 12:15 AM
good feature , thanks for code and sharing
Saineshwar BageriPosted Nov 25, 2014, 11:16 PM
nice one
Manish Kumar ChoudharyPosted Nov 25, 2014, 11:05 PM
nice feature ..
Nimit JoshiPosted Nov 25, 2014, 10:51 PM
Well Done Praveen.. Excellent Article.
Rajeev RanjanPosted Nov 25, 2014, 10:40 PM
The way you describe these things, specially your diagrams/images( most of the part describes itself) is awsm. Just keep it up Praveen Kumar
Jeetendra GundPosted Nov 25, 2014, 10:03 PM
nice article, thanks for sharing
Vithal WadjePosted Nov 25, 2014, 9:39 PM
good feature