当前位置: 首页>>代码示例>>C#>>正文


C# ICompilationUnit.GetAllUsings方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:SergeTruth,项目名称:OxyChart,代码行数:27,代码来源:CtrlSpaceResolveHelper.cs

示例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;
		}
开发者ID:XQuantumForceX,项目名称:Reflexil,代码行数:45,代码来源:NRefactoryRefactoringProvider.cs


注:本文中的ICompilationUnit.GetAllUsings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。