• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# NRefactory.Ast类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Ast类属于ICSharpCode.NRefactory命名空间,在下文中一共展示了Ast类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: loadCompilationUnit

        // DC

        //DC
        /*public void loadCode(string code)
        {
            code = (code.fileExists()) ? code.fileContents() : code;
            var parser = code.csharpAst();
            loadCompilationUnit(parser.CompilationUnit);
        }*/
        //DC
        public void loadCompilationUnit(NRefactoryAST.CompilationUnit compilationUnit)
        {
            cu = new DefaultCompilationUnit(defaultProjectContent);            
            compilationUnit.AcceptVisitor(this, null);
        }
开发者ID:pusp,项目名称:o2platform,代码行数:15,代码来源:MapAstToNRefactory.cs


示例2: ConvertModifier

		ModifierEnum ConvertModifier(AST.Modifiers m, ModifierEnum defaultVisibility)
		{
			ModifierEnum r = (ModifierEnum)m;
			if ((r & ModifierEnum.VisibilityMask) == ModifierEnum.None)
				return r | defaultVisibility;
			else
				return r;
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:8,代码来源:NRefactoryASTConvertVisitor.cs


示例3: ConvertTypeModifier

		ModifierEnum ConvertTypeModifier(AST.Modifiers m)
		{
			if (this.IsVisualBasic)
				return ConvertModifier(m, ModifierEnum.Public);
			if (currentClass.Count > 0)
				return ConvertModifier(m, ModifierEnum.Private);
			else
				return ConvertModifier(m, ModifierEnum.Internal);
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:9,代码来源:NRefactoryASTConvertVisitor.cs


示例4: CreateReturnType

		IReturnType CreateReturnType(NRefactoryAST.TypeReference reference)
		{
			return CreateReturnType(reference, null, TypeVisitor.ReturnTypeOptions.None);
		}
开发者ID:pusp,项目名称:o2platform,代码行数:4,代码来源:MapAstToNRefactory.cs


示例5: VisitEventDeclaration

		public override object VisitEventDeclaration(NRefactoryAST.EventDeclaration eventDeclaration, object data)
		{
			DomRegion region     = GetRegion(eventDeclaration.StartLocation, eventDeclaration.EndLocation);
			DomRegion bodyRegion = GetRegion(eventDeclaration.BodyStart,     eventDeclaration.BodyEnd);
			DefaultClass c = GetCurrentClass();
			
			IReturnType type;
			if (eventDeclaration.TypeReference.IsNull) {
				DefaultClass del = new DefaultClass(cu, ClassType.Delegate,
				                                    ConvertModifier(eventDeclaration.Modifier),
				                                    region, c);
				del.Modifiers |= ModifierEnum.Synthetic;
				CreateDelegate(del, eventDeclaration.Name + "EventHandler",
				               new NRefactoryAST.TypeReference("System.Void", true),
				               new NRefactoryAST.TemplateDefinition[0],
				               eventDeclaration.Parameters);
				type = del.DefaultReturnType;
			} else {
				type = CreateReturnType(eventDeclaration.TypeReference);
			}
			DefaultEvent e = new DefaultEvent(eventDeclaration.Name, type, ConvertModifier(eventDeclaration.Modifier), region, bodyRegion, c);
			ConvertAttributes(eventDeclaration, e);
			c.Events.Add(e);
			
			e.Documentation = GetDocumentation(region.BeginLine, eventDeclaration.Attributes);
			if (eventDeclaration.HasAddRegion) {
				e.AddMethod = new DefaultMethod(e.DeclaringType, "add_" + e.Name) {
					Parameters = { new DefaultParameter("value", e.ReturnType, DomRegion.Empty) },
					Region = GetRegion(eventDeclaration.AddRegion.StartLocation, eventDeclaration.AddRegion.EndLocation),
					BodyRegion = GetRegion(eventDeclaration.AddRegion.Block.StartLocation, eventDeclaration.AddRegion.Block.EndLocation)
				};
			}
			if (eventDeclaration.HasRemoveRegion) {
				e.RemoveMethod = new DefaultMethod(e.DeclaringType, "remove_" + e.Name) {
					Parameters = { new DefaultParameter("value", e.ReturnType, DomRegion.Empty) },
					Region = GetRegion(eventDeclaration.RemoveRegion.StartLocation, eventDeclaration.RemoveRegion.EndLocation),
					BodyRegion = GetRegion(eventDeclaration.RemoveRegion.Block.StartLocation, eventDeclaration.RemoveRegion.Block.EndLocation)
				};
			}
			return null;
		}
开发者ID:pusp,项目名称:o2platform,代码行数:41,代码来源:MapAstToNRefactory.cs


示例6: VisitPropertyDeclaration

		public override object VisitPropertyDeclaration(NRefactoryAST.PropertyDeclaration propertyDeclaration, object data)
		{
			DomRegion region     = GetRegion(propertyDeclaration.StartLocation, propertyDeclaration.EndLocation);
			DomRegion bodyRegion = GetRegion(propertyDeclaration.BodyStart,     propertyDeclaration.BodyEnd);
			
			IReturnType type = CreateReturnType(propertyDeclaration.TypeReference);
			DefaultClass c = GetCurrentClass();
			
			DefaultProperty property = new DefaultProperty(propertyDeclaration.Name, type, ConvertModifier(propertyDeclaration.Modifier), region, bodyRegion, GetCurrentClass());
			if (propertyDeclaration.HasGetRegion) {
				property.GetterRegion = GetRegion(propertyDeclaration.GetRegion.StartLocation, propertyDeclaration.GetRegion.EndLocation);
				property.CanGet = true;
				property.GetterModifiers = ConvertModifier(propertyDeclaration.GetRegion.Modifier, ModifierEnum.None);
			}
			if (propertyDeclaration.HasSetRegion) {
				property.SetterRegion = GetRegion(propertyDeclaration.SetRegion.StartLocation, propertyDeclaration.SetRegion.EndLocation);
				property.CanSet = true;
				property.SetterModifiers = ConvertModifier(propertyDeclaration.SetRegion.Modifier, ModifierEnum.None);
			}
			property.Documentation = GetDocumentation(region.BeginLine, propertyDeclaration.Attributes);
			ConvertAttributes(propertyDeclaration, property);
			c.Properties.Add(property);
            mapProperty(propertyDeclaration, property);
			return null;
		}
开发者ID:pusp,项目名称:o2platform,代码行数:25,代码来源:MapAstToNRefactory.cs


示例7: VisitDestructorDeclaration

		public override object VisitDestructorDeclaration(NRefactoryAST.DestructorDeclaration destructorDeclaration, object data)
		{
			DomRegion region     = GetRegion(destructorDeclaration.StartLocation, destructorDeclaration.EndLocation);
			DomRegion bodyRegion = GetRegion(destructorDeclaration.EndLocation, destructorDeclaration.Body != null ? destructorDeclaration.Body.EndLocation : RefParser.Location.Empty);
			
			DefaultClass c = GetCurrentClass();
			
			Destructor destructor = new Destructor(region, bodyRegion, c);
			ConvertAttributes(destructorDeclaration, destructor);
			c.Methods.Add(destructor);
			return null;
		}
开发者ID:pusp,项目名称:o2platform,代码行数:12,代码来源:MapAstToNRefactory.cs


示例8: VisitOperatorDeclaration

		public override object VisitOperatorDeclaration(NRefactoryAST.OperatorDeclaration operatorDeclaration, object data)
		{
			DefaultClass c  = GetCurrentClass();
			DomRegion region     = GetRegion(operatorDeclaration.StartLocation, operatorDeclaration.EndLocation);
			DomRegion bodyRegion = GetRegion(operatorDeclaration.EndLocation, operatorDeclaration.Body != null ? operatorDeclaration.Body.EndLocation : RefParser.Location.Empty);
			
			DefaultMethod method = new DefaultMethod(operatorDeclaration.Name, CreateReturnType(operatorDeclaration.TypeReference), ConvertModifier(operatorDeclaration.Modifier), region, bodyRegion, c);
			ConvertAttributes(operatorDeclaration, method);
			if(operatorDeclaration.Parameters != null)
			{
				foreach (NRefactoryAST.ParameterDeclarationExpression par in operatorDeclaration.Parameters) {
					method.Parameters.Add(CreateParameter(par, method));
				}
			}
			c.Methods.Add(method);
			return null;
		}
开发者ID:pusp,项目名称:o2platform,代码行数:17,代码来源:MapAstToNRefactory.cs


示例9: TranslateClassType

		ClassType TranslateClassType(NRefactoryAST.ClassType type)
		{
			switch (type) {
				case NRefactoryAST.ClassType.Enum:
					return ClassType.Enum;
				case NRefactoryAST.ClassType.Interface:
					return ClassType.Interface;
				case NRefactoryAST.ClassType.Struct:
					return ClassType.Struct;
				case NRefactoryAST.ClassType.Module:
					return ClassType.Module;
				default:
					return ClassType.Class;
			}
		}
开发者ID:pusp,项目名称:o2platform,代码行数:15,代码来源:MapAstToNRefactory.cs


示例10: VisitNamespaceDeclaration

		public override object VisitNamespaceDeclaration(NRefactoryAST.NamespaceDeclaration namespaceDeclaration, object data)
		{
			DefaultUsingScope oldNamespace = currentNamespace;
			foreach (string name in namespaceDeclaration.Name.Split('.')) {
				currentNamespace = new DefaultUsingScope {
					Parent = currentNamespace,
					NamespaceName = PrependCurrentNamespace(name),
				};
				currentNamespace.Parent.ChildScopes.Add(currentNamespace);
			}
			object ret = namespaceDeclaration.AcceptChildren(this, data);
			currentNamespace = oldNamespace;
			return ret;
		}
开发者ID:pusp,项目名称:o2platform,代码行数:14,代码来源:MapAstToNRefactory.cs


示例11: VisitAttributeSection

		public override object VisitAttributeSection(NRefactoryAST.AttributeSection attributeSection, object data)
		{
			if (GetCurrentClass() == null) {
				ClassFinder cf = new ClassFinder(new DefaultClass(cu, "DummyClass"), attributeSection.StartLocation.Line, attributeSection.StartLocation.Column);
				cu.Attributes.AddRange(VisitAttributes(new[] { attributeSection }, cf));
			}
			return null;
		}
开发者ID:pusp,项目名称:o2platform,代码行数:8,代码来源:MapAstToNRefactory.cs


示例12: ConvertAttributeArgument

		static object ConvertAttributeArgument(NRefactoryAST.Expression expression)
		{
			NRefactoryAST.PrimitiveExpression pe = expression as NRefactoryAST.PrimitiveExpression;
			if (pe != null)
				return pe.Value;
			else
				return null;
		}
开发者ID:pusp,项目名称:o2platform,代码行数:8,代码来源:MapAstToNRefactory.cs


示例13: ConvertAttributes

		void ConvertAttributes(NRefactoryAST.AttributedNode from, AbstractEntity to)
		{
			if (from.Attributes.Count == 0) {
				to.Attributes = DefaultAttribute.EmptyAttributeList;
			} else {
				ICSharpCode.NRefactory.Location location = from.Attributes[0].StartLocation;
				ClassFinder context;
				if (to is IClass) {
					context = new ClassFinder((IClass)to, location.Line, location.Column);
				} else {
					context = new ClassFinder(to.DeclaringType, location.Line, location.Column);
				}
				to.Attributes = VisitAttributes(from.Attributes, context);
			}
		}
开发者ID:pusp,项目名称:o2platform,代码行数:15,代码来源:MapAstToNRefactory.cs


示例14: VisitUsing

		public override object VisitUsing(NRefactoryAST.Using u, object data)
		{
			Debug.Assert(data is DefaultUsing);
			DefaultUsing us = (DefaultUsing)data;
			if (u.IsAlias) {
				IReturnType rt = CreateReturnType(u.Alias);
				if (rt != null) {
					us.AddAlias(u.Name, rt);
				}
			} else {
				us.Usings.Add(u.Name);
			}
			return data;
		}
开发者ID:pusp,项目名称:o2platform,代码行数:14,代码来源:MapAstToNRefactory.cs


示例15: VisitMethodDeclaration

		public override object VisitMethodDeclaration(NRefactoryAST.MethodDeclaration methodDeclaration, object data)
		{
			DomRegion region     = GetRegion(methodDeclaration.StartLocation, methodDeclaration.EndLocation);
			DomRegion bodyRegion = GetRegion(methodDeclaration.EndLocation, methodDeclaration.Body != null ? methodDeclaration.Body.EndLocation : RefParser.Location.Empty);
			DefaultClass currentClass = GetCurrentClass();
			
			DefaultMethod method = new DefaultMethod(methodDeclaration.Name, null, ConvertModifier(methodDeclaration.Modifier), region, bodyRegion, currentClass);
			method.IsExtensionMethod = methodDeclaration.IsExtensionMethod;
			method.Documentation = GetDocumentation(region.BeginLine, methodDeclaration.Attributes);
			ConvertTemplates(methodDeclaration.Templates, method);
			method.ReturnType = CreateReturnType(methodDeclaration.TypeReference, method, TypeVisitor.ReturnTypeOptions.None);
			ConvertAttributes(methodDeclaration, method);
			if (methodDeclaration.Parameters.Count > 0) {
				foreach (NRefactoryAST.ParameterDeclarationExpression par in methodDeclaration.Parameters) {
					method.Parameters.Add(CreateParameter(par, method));
				}
			} else {
				method.Parameters = DefaultParameter.EmptyParameterList;
			}
			if (methodDeclaration.HandlesClause.Count > 0) {
				foreach (string handlesClause in methodDeclaration.HandlesClause) {
					if (handlesClause.ToLowerInvariant().StartsWith("me."))
						method.HandlesClauses.Add(handlesClause.Substring(3));
					else if (handlesClause.ToLowerInvariant().StartsWith("mybase."))
						method.HandlesClauses.Add(handlesClause.Substring(7));
					else
						method.HandlesClauses.Add(handlesClause);
				}
			} else {
				method.HandlesClauses = EmptyList<string>.Instance;
			}
			
			currentClass.Methods.Add(method);
            mapMethod(methodDeclaration, method);
			return null;
		}
开发者ID:pusp,项目名称:o2platform,代码行数:36,代码来源:MapAstToNRefactory.cs


示例16: VisitDeclareDeclaration

		public override object VisitDeclareDeclaration(NRefactoryAST.DeclareDeclaration declareDeclaration, object data)
		{
			DefaultClass currentClass = GetCurrentClass();
			
			DomRegion region = GetRegion(declareDeclaration.StartLocation, declareDeclaration.EndLocation);
			DefaultMethod method = new DefaultMethod(declareDeclaration.Name, null, ConvertModifier(declareDeclaration.Modifier), region, DomRegion.Empty, currentClass);
			method.Documentation = GetDocumentation(region.BeginLine, declareDeclaration.Attributes);
			method.Modifiers |= ModifierEnum.Extern | ModifierEnum.Static;
			
			method.ReturnType = CreateReturnType(declareDeclaration.TypeReference, method, TypeVisitor.ReturnTypeOptions.None);
			ConvertAttributes(declareDeclaration, method);
			
			foreach (NRefactoryAST.ParameterDeclarationExpression par in declareDeclaration.Parameters) {
				method.Parameters.Add(CreateParameter(par, method));
			}
			
			currentClass.Methods.Add(method);
			return null;
		}
开发者ID:pusp,项目名称:o2platform,代码行数:19,代码来源:MapAstToNRefactory.cs


示例17: VisitTypeDeclaration

		public override object VisitTypeDeclaration(NRefactoryAST.TypeDeclaration typeDeclaration, object data)
		{
			DomRegion region = GetRegion(typeDeclaration.StartLocation, typeDeclaration.EndLocation);
			DomRegion bodyRegion = GetRegion(typeDeclaration.BodyStartLocation, typeDeclaration.EndLocation);
			
			DefaultClass c = new DefaultClass(cu, TranslateClassType(typeDeclaration.Type), ConvertTypeModifier(typeDeclaration.Modifier), region, GetCurrentClass());
			if (c.IsStatic) {
				// static classes are also abstract and sealed at the same time
				c.Modifiers |= ModifierEnum.Abstract | ModifierEnum.Sealed;
			}
			c.BodyRegion = bodyRegion;
			ConvertAttributes(typeDeclaration, c);
			c.Documentation = GetDocumentation(region.BeginLine, typeDeclaration.Attributes);
			
			DefaultClass outerClass = GetCurrentClass();
			if (outerClass != null) {
				outerClass.InnerClasses.Add(c);
				c.FullyQualifiedName = outerClass.FullyQualifiedName + '.' + typeDeclaration.Name;
			} else {
				c.FullyQualifiedName = PrependCurrentNamespace(typeDeclaration.Name);
				cu.Classes.Add(c);
			}
			c.UsingScope = currentNamespace;
			currentClass.Push(c);
			
			ConvertTemplates(outerClass, typeDeclaration.Templates, c); // resolve constrains in context of the class
			// templates must be converted before base types because base types may refer to generic types
			
			if (c.ClassType != ClassType.Enum && typeDeclaration.BaseTypes != null) {
				foreach (NRefactoryAST.TypeReference type in typeDeclaration.BaseTypes) {
					IReturnType rt = CreateReturnType(type, null, TypeVisitor.ReturnTypeOptions.BaseTypeReference);
					if (rt != null) {
						c.BaseTypes.Add(rt);
					}
				}
			}
			
			object ret = typeDeclaration.AcceptChildren(this, data);
			currentClass.Pop();
			
			if (c.ClassType == ClassType.Module) {
				foreach (DefaultField f in c.Fields) {
					f.Modifiers |= ModifierEnum.Static;
				}
				foreach (DefaultMethod m in c.Methods) {
					m.Modifiers |= ModifierEnum.Static;
				}
				foreach (DefaultProperty p in c.Properties) {
					p.Modifiers |= ModifierEnum.Static;
				}
				foreach (DefaultEvent e in c.Events) {
					e.Modifiers |= ModifierEnum.Static;
				}
			}

            mapType(typeDeclaration, c);

			return ret;
		}
开发者ID:pusp,项目名称:o2platform,代码行数:59,代码来源:MapAstToNRefactory.cs


示例18: VisitConstructorDeclaration

		public override object VisitConstructorDeclaration(NRefactoryAST.ConstructorDeclaration constructorDeclaration, object data)
		{
			DomRegion region     = GetRegion(constructorDeclaration.StartLocation, constructorDeclaration.EndLocation);
			DomRegion bodyRegion = GetRegion(constructorDeclaration.EndLocation, constructorDeclaration.Body != null ? constructorDeclaration.Body.EndLocation : RefParser.Location.Empty);
			DefaultClass c = GetCurrentClass();
			
			Constructor constructor = new Constructor(ConvertModifier(constructorDeclaration.Modifier), region, bodyRegion, GetCurrentClass());
			constructor.Documentation = GetDocumentation(region.BeginLine, constructorDeclaration.Attributes);
			ConvertAttributes(constructorDeclaration, constructor);
			if (constructorDeclaration.Parameters != null) {
				foreach (NRefactoryAST.ParameterDeclarationExpression par in constructorDeclaration.Parameters) {
					constructor.Parameters.Add(CreateParameter(par));
				}
			}
			c.Methods.Add(constructor);
            mapConstructor(constructorDeclaration, constructor);
			return null;
		}
开发者ID:pusp,项目名称:o2platform,代码行数:18,代码来源:MapAstToNRefactory.cs


示例19: ConvertConstraints

		void ConvertConstraints(NRefactoryAST.TemplateDefinition template, DefaultTypeParameter typeParameter)
		{
			foreach (NRefactoryAST.TypeReference typeRef in template.Bases) {
				if (typeRef == NRefactoryAST.TypeReference.NewConstraint) {
					typeParameter.HasConstructableConstraint = true;
				} else if (typeRef == NRefactoryAST.TypeReference.ClassConstraint) {
					typeParameter.HasReferenceTypeConstraint = true;
				} else if (typeRef == NRefactoryAST.TypeReference.StructConstraint) {
					typeParameter.HasValueTypeConstraint = true;
				} else {
					IReturnType rt = CreateReturnType(typeRef, typeParameter.Method, TypeVisitor.ReturnTypeOptions.None);
					if (rt != null) {
						typeParameter.Constraints.Add(rt);
					}
				}
			}
		}
开发者ID:pusp,项目名称:o2platform,代码行数:17,代码来源:MapAstToNRefactory.cs


示例20: VisitFieldDeclaration

		public override object VisitFieldDeclaration(NRefactoryAST.FieldDeclaration fieldDeclaration, object data)
		{
			DomRegion region = GetRegion(fieldDeclaration.StartLocation, fieldDeclaration.EndLocation);
			DefaultClass c = GetCurrentClass();
			ModifierEnum modifier = ConvertModifier(fieldDeclaration.Modifier,
			                                        (c.ClassType == ClassType.Struct && this.IsVisualBasic)
			                                        ? ModifierEnum.Public : ModifierEnum.Private);
			string doku = GetDocumentation(region.BeginLine, fieldDeclaration.Attributes);
			if (currentClass.Count > 0) {
				for (int i = 0; i < fieldDeclaration.Fields.Count; ++i) {
					NRefactoryAST.VariableDeclaration field = (NRefactoryAST.VariableDeclaration)fieldDeclaration.Fields[i];
					
					IReturnType retType;
					if (c.ClassType == ClassType.Enum) {
						retType = c.DefaultReturnType;
					} else {
						retType = CreateReturnType(fieldDeclaration.GetTypeForField(i));
						if (!field.FixedArrayInitialization.IsNull)
							retType = new ArrayReturnType(cu.ProjectContent, retType, 1);
					}
					DefaultField f = new DefaultField(retType, field.Name, modifier, region, c);
					ConvertAttributes(fieldDeclaration, f);
					f.Documentation = doku;
					if (c.ClassType == ClassType.Enum) {
						f.Modifiers = ModifierEnum.Const | ModifierEnum.Public;
					}
					
					c.Fields.Add(f);
                    mapField(fieldDeclaration, f);
				}
			}
            
			return null;
		}
开发者ID:pusp,项目名称:o2platform,代码行数:34,代码来源:MapAstToNRefactory.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Ast.ArrayCreateExpression类代码示例发布时间:2022-05-26
下一篇:
C# TreeNodes.ILSpyTreeNode类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap