How to rename a "using Directive" C#
c#, excel
Solution
You can create an alias like this:
// for whole namespace
using Excel = Microsoft.Office.Interop.Excel;
// use like this
Excel.ApplicationClass excel = /* ... */;
// or for single type
using ExcelApp = Microsoft.Office.Interop.Excel.ApplicationClass;
// use like this
ExcelApp excel = /* ... */;
Problem
How would you rename a "Using Directive" Using C#? Because some times You copy a class from somewhere (Example below) ``` //Other Code Excel.ApplicationClass excel; Excel.Workbooks workbooks; Excel.Workbook workbook; Excel.Worksheet worksheet; Excel.Sheets worksheets; //Other Code ``` and instead of renaming everything to ``` //Other Code Microsoft.Office.Interop.Excel.ApplicationClass excel; Microsoft.Office.Interop.Excel.Workbooks workbooks; Microsoft.Office.Interop.Excel.Workbook workbook; Microsoft.Office.Interop.Excel.Worksheet worksheet; Microsoft.Office.Interop.Excel.Sheets worksheets; //Other Code ``` So having something like ``` Using Microsoft.Office.Interop.Excel.ApplicationClass as 'Excel' ```