Is there any way to get a List
which contains all \'usings\' within a namespace/class?
For instance
using System;
using System
Here's a rough untested attempt to get you started:
IEnumerable GetNamespacesUsed(string fileName)
{
var lines = System.IO.File.ReadAllLines(fileName);
var usingLines = lines.Where(
x => x.StartsWith("using ") && !x.StartsWith("using ("));
foreach (var line in usingLines)
{
if (line.Contains("="))
yield return line.Substring(line.IndexOf("="), line.Length - 1);
else
yield return line.Substring(line.Length - 1);
}
}
The line.Length - 1
may not be correct to cut off the semicolon on the end. You'll need to test it to find out what it should be. Also, this assumes your code is formatted in a fairly standard way. If it's not, it won't work.