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


C# NamespaceDeclaration.AddChild方法代码示例

本文整理汇总了C#中ICSharpCode.NRefactory.Ast.NamespaceDeclaration.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# NamespaceDeclaration.AddChild方法的具体用法?C# NamespaceDeclaration.AddChild怎么用?C# NamespaceDeclaration.AddChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.NRefactory.Ast.NamespaceDeclaration的用法示例。


在下文中一共展示了NamespaceDeclaration.AddChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisitCompilationUnit

		public override object VisitCompilationUnit(CompilationUnit compilationUnit, object data)
		{
			base.VisitCompilationUnit(compilationUnit, data);
			if (!string.IsNullOrEmpty(NamespacePrefixToAdd)) {
				for (int i = 0; i < compilationUnit.Children.Count; i++) {
					NamespaceDeclaration ns = compilationUnit.Children[i] as NamespaceDeclaration;
					if (ns != null) {
						ns.Name = NamespacePrefixToAdd + "." + ns.Name;
					}
					if (compilationUnit.Children[i] is TypeDeclaration || compilationUnit.Children[i] is DelegateDeclaration) {
						ns = new NamespaceDeclaration(NamespacePrefixToAdd);
						ns.AddChild(compilationUnit.Children[i]);
						compilationUnit.Children[i] = ns;
					}
				}
			}
			
			ToCSharpConvertVisitor v = new ToCSharpConvertVisitor();
			compilationUnit.AcceptVisitor(v, data);
			if (projectContent != null && projectContent.DefaultImports != null) {
				int index = 0;
				foreach (string u in projectContent.DefaultImports.Usings) {
					compilationUnit.Children.Insert(index++, new UsingDeclaration(u));
				}
			}
			return null;
		}
开发者ID:SiGhTfOrbACQ,项目名称:O2.Platform.Projects,代码行数:27,代码来源:VBNetToCSharpConvertVisitor.cs

示例2: Setup

		public void Setup()
		{
			mocks = new MockRepository();
			typeResolver = mocks.DynamicMock<ITypeResolver>();
			visitor = new TypeInspectionVisitor(typeResolver);

			type = new TypeDeclaration(Modifiers.Public, new List<AttributeSection>()) {Name = "SomeType"};
			@namespace = new NamespaceDeclaration("SomeNamespace");
			@namespace.AddChild(type);
			type.Parent = @namespace;
		}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:11,代码来源:TypeInspectionVisitorTests.cs

示例3: CreateTypeDeclarations

        private void CreateTypeDeclarations(string jarFile)
        {
            LoadClasses(Path.GetFullPath(jarFile));

            foreach (string package in classes.Keys)
            {
                if (!IsIncluded(package))
                    continue;
                Console.WriteLine(package);
                IDictionary types = new Hashtable();
                IList packageClasses = (IList) classes[package];
                foreach (ClassFile cf in packageClasses)
                {
                    if (cf.IsPublic)
                    {
                        TypeDeclaration type = GetTypeDeclaration(cf);
                        types.Add(type.Name, type);
                    }
                }

                foreach (TypeDeclaration type in types.Values)
                {
                    if (type.Name.IndexOf("$") == -1)
                    {
                        NamespaceDeclaration nameSpace = new NamespaceDeclaration(package);
                        type.Parent = nameSpace;
                        nameSpace.AddChild(type);

                        CompilationUnit cu = new CompilationUnit();
                        cu.Children.Add(nameSpace);
                        compilationUnits.Add(cu);
                    }
                    else
                    {
                        string parentName = type.Name.Substring(0, type.Name.IndexOf("$"));
                        TypeDeclaration parent = (TypeDeclaration) types[GetTypeName(parentName)];
                        if (parent != null)
                        {
                            type.Name = GetTypeName(type.Name);
                            parent.AddChild(type);
                        }
                    }
                }
            }
        }
开发者ID:sourcewarehouse,项目名称:janett,代码行数:45,代码来源:JavaArchiveToCodeSkeleton.cs

示例4: Parse

		// Steps to load the designer:
		// - Parse main file
		// - Find other files containing parts of the form
		// - Parse all files and look for fields (for controls) and InitializeComponents method
		// - Create CodeDom objects for fields and InitializeComponents statements
		// - If debug build and Ctrl pressed, output CodeDom to console
		// - Return CodeDom objects to the .NET designer
		protected override CodeCompileUnit Parse()
		{
			LoggingService.Debug("NRefactoryDesignerLoader.Parse()");
			
			lastTextContent = this.Generator.ViewContent.DesignerCodeFileContent;
			
			ParseInformation parseInfo = ParserService.GetParseInformation(this.Generator.ViewContent.DesignerCodeFile.FileName);
			
			IClass formClass;
			bool isFirstClassInFile;
			IList<IClass> parts = FindFormClassParts(parseInfo, out formClass, out isFirstClassInFile);
			
			const string missingReferenceMessage = "Your project is missing a reference to '${Name}' - please add it using 'Project > Add Reference'.";
			
			if (formClass.ProjectContent.GetClass("System.Drawing.Point", 0) == null) {
				throw new FormsDesignerLoadException(StringParser.Parse(missingReferenceMessage, new StringTagPair("Name", "System.Drawing")));
			}
			if (formClass.ProjectContent.GetClass("System.Windows.Forms.Form", 0) == null) {
				throw new FormsDesignerLoadException(StringParser.Parse(missingReferenceMessage, new StringTagPair("Name" , "System.Windows.Forms")));
			}
			
			List<KeyValuePair<string, CompilationUnit>> compilationUnits = new List<KeyValuePair<string, CompilationUnit>>();
			bool foundInitMethod = false;
			foreach (IClass part in parts) {
				string fileName = part.CompilationUnit.FileName;
				if (fileName == null) continue;
				bool found = false;
				foreach (KeyValuePair<string, CompilationUnit> entry in compilationUnits) {
					if (FileUtility.IsEqualFileName(fileName, entry.Key)) {
						found = true;
						break;
					}
				}
				if (found) continue;
				
				ITextBuffer fileContent;
				if (FileUtility.IsEqualFileName(fileName, this.Generator.ViewContent.PrimaryFileName)) {
					fileContent = this.Generator.ViewContent.PrimaryFileContent;
				} else if (FileUtility.IsEqualFileName(fileName, this.Generator.ViewContent.DesignerCodeFile.FileName)) {
					fileContent = new StringTextBuffer(this.Generator.ViewContent.DesignerCodeFileContent);
				} else {
					fileContent = ParserService.GetParseableFileContent(fileName);
				}
				
				ICSharpCode.NRefactory.IParser p = ICSharpCode.NRefactory.ParserFactory.CreateParser(language, fileContent.CreateReader());
				p.Parse();
				if (p.Errors.Count > 0) {
					throw new FormsDesignerLoadException("Syntax errors in " + fileName + ":\r\n" + p.Errors.ErrorOutput);
				}
				
				// Try to fix the type names to fully qualified ones
				FixTypeNames(p.CompilationUnit, part.CompilationUnit, ref foundInitMethod);
				compilationUnits.Add(new KeyValuePair<string, CompilationUnit>(fileName, p.CompilationUnit));
			}
			
			if (!foundInitMethod)
				throw new FormsDesignerLoadException("The InitializeComponent method was not found. Designer cannot be loaded.");
			
			CompilationUnit combinedCu = new CompilationUnit();
			NamespaceDeclaration nsDecl = new NamespaceDeclaration(formClass.Namespace);
			combinedCu.AddChild(nsDecl);
			TypeDeclaration formDecl = new TypeDeclaration(Modifiers.Public, null);
			nsDecl.AddChild(formDecl);
			formDecl.Name = formClass.Name;
			foreach (KeyValuePair<string, CompilationUnit> entry in compilationUnits) {
				foreach (object o in entry.Value.Children) {
					TypeDeclaration td = o as TypeDeclaration;
					if (td != null && td.Name == formDecl.Name) {
						foreach (INode node in td.Children)
							formDecl.AddChild(node);
						formDecl.BaseTypes.AddRange(td.BaseTypes);
					}
					if (o is NamespaceDeclaration) {
						foreach (object o2 in ((NamespaceDeclaration)o).Children) {
							td = o2 as TypeDeclaration;
							if (td != null && td.Name == formDecl.Name) {
								foreach (INode node in td.Children)
									formDecl.AddChild(node);
								formDecl.BaseTypes.AddRange(td.BaseTypes);
							}
						}
					}
				}
			}
			
			CodeDomVisitor visitor = new CodeDomVisitor();
			visitor.EnvironmentInformationProvider = new ICSharpCode.SharpDevelop.Dom.NRefactoryResolver.NRefactoryInformationProvider(formClass.ProjectContent);
			visitor.VisitCompilationUnit(combinedCu, null);
			
			// output generated CodeDOM to the console :
			#if DEBUG
			if ((Control.ModifierKeys & Keys.Control) == Keys.Control) {
				CodeDomVerboseOutputGenerator outputGenerator = new CodeDomVerboseOutputGenerator();
//.........这里部分代码省略.........
开发者ID:nylen,项目名称:SharpDevelop,代码行数:101,代码来源:NRefactoryDesignerLoader.cs


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