本文整理汇总了C#中ICompilationUnit.GetAllUsings方法的典型用法代码示例。如果您正苦于以下问题:C# ICompilationUnit.GetAllUsings方法的具体用法?C# ICompilationUnit.GetAllUsings怎么用?C# ICompilationUnit.GetAllUsings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICompilationUnit
的用法示例。
在下文中一共展示了ICompilationUnit.GetAllUsings方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddImportedNamespaceContents
public static void AddImportedNamespaceContents(ArrayList result, ICompilationUnit cu, IClass callingClass)
{
IProjectContent projectContent = cu.ProjectContent;
projectContent.AddNamespaceContents(result, "", projectContent.Language, true);
foreach (IUsing u in cu.GetAllUsings()) {
AddUsing(result, u, projectContent);
}
AddUsing(result, projectContent.DefaultImports, projectContent);
if (callingClass != null) {
string[] namespaceParts = callingClass.Namespace.Split('.');
for (int i = 1; i <= namespaceParts.Length; i++) {
foreach (object member in projectContent.GetNamespaceContents(string.Join(".", namespaceParts, 0, i))) {
if (!result.Contains(member))
result.Add(member);
}
}
IClass currentClass = callingClass;
do {
foreach (IClass innerClass in currentClass.GetCompoundClass().GetAccessibleTypes(currentClass)) {
if (!result.Contains(innerClass))
result.Add(innerClass);
}
currentClass = currentClass.DeclaringType;
} while (currentClass != null);
}
}
示例2: FindUnusedUsingDeclarations
public override IList<IUsing> FindUnusedUsingDeclarations(IDomProgressMonitor progressMonitor, string fileName, string fileContent, ICompilationUnit cu)
{
IClass @class = cu.Classes.Count == 0 ? null : cu.Classes[0];
HashSet<PossibleTypeReference> references = FindPossibleTypeReferences(progressMonitor, fileContent, new ParseInformation(cu));
if (references == null) return new IUsing[0];
HashSet<IUsing> usedUsings = new HashSet<IUsing>();
foreach (PossibleTypeReference tr in references) {
if (tr.ExtensionMethod != null) {
// the invocation of an extension method can implicitly use a using
StringComparer nameComparer = cu.ProjectContent.Language.NameComparer;
// go through all usings in all nested child scopes
foreach (IUsing import in cu.GetAllUsings()) {
foreach (string i in import.Usings) {
if (nameComparer.Equals(tr.ExtensionMethod.DeclaringType.Namespace, i)) {
usedUsings.Add(import);
}
}
}
} else {
// normal possible type reference
SearchTypeRequest request = new SearchTypeRequest(tr.Name, tr.TypeParameterCount, @class, cu, 1, 1);
SearchTypeResult response = cu.ProjectContent.SearchType(request);
if (response.UsedUsing != null) {
usedUsings.Add(response.UsedUsing);
}
}
}
List<IUsing> unusedUsings = new List<IUsing>();
foreach (IUsing import in cu.GetAllUsings()) {
if (!usedUsings.Contains(import)) {
if (import.HasAliases) {
foreach (string key in import.Aliases.Keys) {
if (references.Contains(new PossibleTypeReference(key)))
goto checkNextImport;
}
}
unusedUsings.Add(import); // this using is unused
}
checkNextImport:;
}
return unusedUsings;
}