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

C# Refactoring.TypeSystemAstBuilder类代码示例

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

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



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

示例1: GeneratePartialClassContextStub

		static string GeneratePartialClassContextStub(DebuggerCompletionContext context)
		{
			var compilation = SD.ParserService.GetCompilationForFile(context.FileName);
			var file = SD.ParserService.GetExistingUnresolvedFile(context.FileName);
			if (compilation == null || file == null)
				return "";
			var unresolvedMember = file.GetMember(context.Location);
			if (unresolvedMember == null)
				return "";
			var member = unresolvedMember.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly));
			if (member == null)
				return "";
			var builder = new TypeSystemAstBuilder();
			MethodDeclaration decl;
			if (unresolvedMember is IMethod) {
				// If it's a method, convert it directly (including parameters + type parameters)
				decl = (MethodDeclaration)builder.ConvertEntity(member);
			} else {
				// Otherwise, create a method anyways, and copy the parameters
				decl = new MethodDeclaration();
				if (member is IParameterizedMember) {
					foreach (var p in ((IParameterizedMember)member).Parameters) {
						decl.Parameters.Add(builder.ConvertParameter(p));
					}
				}
			}
			decl.Name = "__DebuggerStub__";
			decl.ReturnType = builder.ConvertType(member.ReturnType);
			decl.Modifiers = unresolvedMember.IsStatic ? Modifiers.Static : Modifiers.None;
			// Make the method look like an explicit interface implementation so that it doesn't appear in CC
			decl.PrivateImplementationType = new SimpleType("__DummyType__");
			decl.Body = GenerateBodyFromContext(builder, context);
			return WrapInType(unresolvedMember.DeclaringTypeDefinition, decl).ToString();
		}
开发者ID:dgrunwald,项目名称:SharpDevelop,代码行数:34,代码来源:DebuggerDotCompletion.cs


示例2: VisitForeachStatement

 public override void VisitForeachStatement(ForeachStatement foreachStatement)
 {
     base.VisitForeachStatement(foreachStatement);
     var rr = ctx.Resolve(foreachStatement) as ForEachResolveResult;
     if (rr == null)
         return;
     if (rr.ElementType.Kind == TypeKind.Unknown)
         return;
     if (ReflectionHelper.GetTypeCode(rr.ElementType) == TypeCode.Object)
         return;
     if (conversions == null) {
         conversions = CSharpConversions.Get(ctx.Compilation);
     }
     Conversion c = conversions.ImplicitConversion(rr.ElementType, rr.ElementVariable.Type);
     if (c.IsValid)
         return;
     var csResolver = ctx.GetResolverStateBefore(foreachStatement);
     var builder = new TypeSystemAstBuilder(csResolver);
     AstType elementType = builder.ConvertType(rr.ElementType);
     AstType variableType = foreachStatement.VariableType;
     string issueText = ctx.TranslateString("Collection element type '{0}' is not implicitly convertible to '{1}'");
     string fixText = ctx.TranslateString("Use type '{0}'");
     AddIssue(variableType, string.Format(issueText, elementType.GetText(), variableType.GetText()),
              new CodeAction(string.Format(fixText, elementType.GetText()),
                             script => script.Replace(variableType, elementType)));
 }
开发者ID:artifexor,项目名称:NRefactory,代码行数:26,代码来源:ExplicitConversionInForEachIssue.cs


示例3: CreateShortType

		public override AstType CreateShortType (IType fullType)
		{
			AstNode node = Unit.GetNodeAt(Location);
			CSharpResolver csResolver = resolver.GetResolverStateBefore(node);
			var builder = new TypeSystemAstBuilder (csResolver);
			return builder.ConvertType (fullType);
		}
开发者ID:Netring,项目名称:ILSpy,代码行数:7,代码来源:TestRefactoringContext.cs


示例4: EnumMemberCompletionData

		public EnumMemberCompletionData(IType enumType, IEntity member, TypeSystemAstBuilder builder) : base(enumType.Name + "." + member.Name)
		{
			this.enumType = enumType;
			this.member = member;
			this.Image = ClassBrowserIconService.Const;
			this.CompletionText = builder.ConvertType(enumType).ToString() + "." + member.Name;
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:7,代码来源:EnumMemberCompletionData.cs


示例5: GetShortType

		protected string GetShortType (IType type)
		{
			if (builder == null) {
				var ctx = ext.CSharpUnresolvedFile.GetTypeResolveContext (ext.UnresolvedFileCompilation, ext.Document.Editor.Caret.Location) as CSharpTypeResolveContext;
				var state = new CSharpResolver (ctx);
				builder = new TypeSystemAstBuilder (state);
				var dt = state.CurrentTypeDefinition;
				var declaring = ctx.CurrentTypeDefinition != null ? ctx.CurrentTypeDefinition.DeclaringTypeDefinition : null;
				if (declaring != null) {
					while (dt != null) {
						if (dt.Equals (declaring)) {
							builder.AlwaysUseShortTypeNames = true;
							break;
						}
						dt = dt.DeclaringTypeDefinition;
					}
				}
			}
			try {
				return GLib.Markup.EscapeText (builder.ConvertType(type).ToString (ext.FormattingPolicy.CreateOptions ()));
			} catch (Exception e) {
				LoggingService.LogError ("Exception while getting short type.", e);
				return "";
			}
		}
开发者ID:segaman,项目名称:monodevelop,代码行数:25,代码来源:AbstractParameterDataProvider.cs


示例6: GeneratePartialClassContextStub

		static string GeneratePartialClassContextStub(ICodeContext context)
		{
			var member = context.CurrentMember;
			if (member == null)
				return "";
			var builder = new TypeSystemAstBuilder();
			MethodDeclaration decl;
			if (member is IMethod) {
				// If it's a method, convert it directly (including parameters + type parameters)
				decl = (MethodDeclaration)builder.ConvertEntity(member);
			} else {
				// Otherwise, create a method anyways, and copy the parameters
				decl = new MethodDeclaration();
				if (member is IParameterizedMember) {
					foreach (var p in ((IParameterizedMember)member).Parameters) {
						decl.Parameters.Add(builder.ConvertParameter(p));
					}
				}
			}
			decl.Name = "__DebuggerStub__";
			decl.ReturnType = builder.ConvertType(member.ReturnType);
			decl.Modifiers = member.IsStatic ? Modifiers.Static : Modifiers.None;
			// Make the method look like an explicit interface implementation so that it doesn't appear in CC
			decl.PrivateImplementationType = new SimpleType("__DummyType__");
			decl.Body = GenerateBodyFromContext(builder, context.LocalVariables.ToArray());
			return WrapInType(context.CurrentTypeDefinition, decl).ToString();
		}
开发者ID:kinpro,项目名称:SharpDevelop,代码行数:27,代码来源:CSharpLanguageBinding.cs


示例7: Complete

		public override void Complete(CompletionContext context)
		{
			if (declarationBegin > context.StartOffset) {
				base.Complete(context);
				return;
			}
			
			TypeSystemAstBuilder b = new TypeSystemAstBuilder(contextAtCaret);
			b.ShowTypeParameterConstraints = false;
			b.GenerateBody = true;
			
			var entityDeclaration = b.ConvertEntity(this.Entity);
			entityDeclaration.Modifiers &= ~(Modifiers.Virtual | Modifiers.Abstract);
			entityDeclaration.Modifiers |= Modifiers.Override;
			
			if (!this.Entity.IsAbstract) {
				// modify body to call the base method
				if (this.Entity.SymbolKind == SymbolKind.Method) {
					var baseCall = new BaseReferenceExpression().Invoke(this.Entity.Name, ParametersToExpressions(this.Entity));
					var body = entityDeclaration.GetChildByRole(Roles.Body);
					body.Statements.Clear();
					if (((IMethod)this.Entity).ReturnType.IsKnownType(KnownTypeCode.Void))
						body.Statements.Add(new ExpressionStatement(baseCall));
					else
						body.Statements.Add(new ReturnStatement(baseCall));
				} else if (this.Entity.SymbolKind == SymbolKind.Indexer || this.Entity.SymbolKind == SymbolKind.Property) {
					Expression baseCall;
					if (this.Entity.SymbolKind == SymbolKind.Indexer)
						baseCall = new BaseReferenceExpression().Indexer(ParametersToExpressions(this.Entity));
					else
						baseCall = new BaseReferenceExpression().Member(this.Entity.Name);
					var getterBody = entityDeclaration.GetChildByRole(PropertyDeclaration.GetterRole).Body;
					if (!getterBody.IsNull) {
						getterBody.Statements.Clear();
						getterBody.Add(new ReturnStatement(baseCall.Clone()));
					}
					var setterBody = entityDeclaration.GetChildByRole(PropertyDeclaration.SetterRole).Body;
					if (!setterBody.IsNull) {
						setterBody.Statements.Clear();
						setterBody.Add(new AssignmentExpression(baseCall.Clone(), new IdentifierExpression("value")));
					}
				}
			}
			
			var document = context.Editor.Document;
			StringWriter w = new StringWriter();
			var formattingOptions = FormattingOptionsFactory.CreateSharpDevelop();
			var segmentDict = SegmentTrackingOutputFormatter.WriteNode(w, entityDeclaration, formattingOptions, context.Editor.Options);
			
			using (document.OpenUndoGroup()) {
				string newText = w.ToString().TrimEnd();
				document.Replace(declarationBegin, context.EndOffset - declarationBegin, newText);
				var throwStatement = entityDeclaration.Descendants.FirstOrDefault(n => n is ThrowStatement);
				if (throwStatement != null) {
					var segment = segmentDict[throwStatement];
					context.Editor.Select(declarationBegin + segment.Offset, segment.Length);
				}
				CSharpFormatterHelper.Format(context.Editor, declarationBegin, newText.Length, formattingOptions);
			}
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:60,代码来源:OverrideCompletionData.cs


示例8: Complete

		public override void Complete(CompletionContext context)
		{
			if (declarationBegin > context.StartOffset) {
				base.Complete(context);
				return;
			}
			
			TypeSystemAstBuilder b = new TypeSystemAstBuilder(contextAtCaret);
			b.GenerateBody = true;
			
			var entityDeclaration = b.ConvertEntity(this.Entity);
			entityDeclaration.Modifiers &= ~Modifiers.VisibilityMask; // remove visiblity
			entityDeclaration.Modifiers |= Modifiers.Partial;
			
			var document = context.Editor.Document;
			StringWriter w = new StringWriter();
			var formattingOptions = CSharpFormattingPolicies.Instance.GetProjectOptions(contextAtCaret.Compilation.GetProject());
			var segmentDict = SegmentTrackingOutputFormatter.WriteNode(
				w, entityDeclaration, formattingOptions.OptionsContainer.GetEffectiveOptions(), context.Editor.Options);
			
			using (document.OpenUndoGroup()) {
				string newText = w.ToString().TrimEnd();
				document.Replace(declarationBegin, context.EndOffset - declarationBegin, newText);
				var throwStatement = entityDeclaration.Descendants.FirstOrDefault(n => n is ThrowStatement);
				if (throwStatement != null) {
					var segment = segmentDict[throwStatement];
					context.Editor.Select(declarationBegin + segment.Offset, segment.Length);
				}
				CSharpFormatterHelper.Format(context.Editor, declarationBegin, newText.Length, formattingOptions.OptionsContainer);
			}
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:31,代码来源:PartialCompletionData.cs


示例9: CSharpCompletionDataFactory

		public CSharpCompletionDataFactory(CSharpCompletionContext completionContext, CSharpResolver contextAtCaret)
		{
			Debug.Assert(completionContext != null);
			Debug.Assert(contextAtCaret != null);
			this.completionContext = completionContext;
			this.contextAtCaret = contextAtCaret;
			this.builder = new TypeSystemAstBuilder(contextAtCaret);
		}
开发者ID:kristjan84,项目名称:SharpDevelop,代码行数:8,代码来源:CSharpCompletionDataFactory.cs


示例10: CSharpResolver

        public static string GetOverrideTargetName
            (IMember m, CSharpTypeResolveContext resolveContext) {
            var builder = new TypeSystemAstBuilder
                (new CSharpResolver(resolveContext));

			return builder.ConvertEntity(m).ToString()
                // Builder automatically adds a trailing newline
                .TrimEnd(Environment.NewLine.ToCharArray());
        }
开发者ID:jcd-as,项目名称:omnisharp-server,代码行数:9,代码来源:GetOverrideTargetsResponse.cs


示例11: SignatureMarkupCreator

		public SignatureMarkupCreator (CSharpResolver resolver, CSharpFormattingOptions formattingOptions)
		{
			this.colorStyle = SyntaxModeService.GetColorStyle (MonoDevelop.Ide.IdeApp.Preferences.ColorScheme);

			this.resolver = resolver;
			this.astBuilder = new TypeSystemAstBuilder (resolver) {
				ConvertUnboundTypeArguments = true,
				UseAliases = false
			};
			this.formattingOptions = formattingOptions;
		}
开发者ID:Chertolom,项目名称:monodevelop,代码行数:11,代码来源:SignatureMarkupCreator.cs


示例12: ImportCompletionData

		public ImportCompletionData(ITypeDefinition typeDef, CSharpResolver contextAtCaret, bool useFullName)
			: base(typeDef)
		{
			this.Description = "using " + typeDef.Namespace + ";";
			if (useFullName) {
				var astBuilder = new TypeSystemAstBuilder(contextAtCaret);
				insertionText = astBuilder.ConvertType(typeDef).ToString();
			} else {
				insertionText = typeDef.Name;
				insertUsing = typeDef.Namespace;
			}
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:12,代码来源:ImportCompletionData.cs


示例13: MemberCompletionData

            public MemberCompletionData(IType type, IEntity member, TypeSystemAstBuilder builder)
            {
                DeclarationCategory = DeclarationCategory.Enumeration_Member;

                Type = type;
                Member = member;

                string typeName = builder.ConvertType(type).GetText();
                SetDefaultText(typeName + "." + member.Name);

                Documentation = member.Documentation;
            }
开发者ID:uluhonolulu,项目名称:QCCodingServices.NET,代码行数:12,代码来源:MemberCompletionData.cs


示例14: InsertEventHandler

		public override void InsertEventHandler(ITypeDefinition target, string name, IEvent eventDefinition, bool jumpTo)
		{
			IUnresolvedTypeDefinition match = null;
			
			foreach (var part in target.Parts) {
				if (match == null || EntityModelContextUtils.IsBetterPart(part, match, ".cs"))
					match = part;
			}
			
			if (match == null) return;
			
			var view = SD.FileService.OpenFile(new FileName(match.Region.FileName), jumpTo);
			var editor = view.GetRequiredService<ITextEditor>();
			var last = match.Members.LastOrDefault() ?? (IUnresolvedEntity)match;
			editor.Caret.Location = last.BodyRegion.End;
			var context = SDRefactoringContext.Create(editor, CancellationToken.None);
			
			var node = context.RootNode.GetNodeAt<EntityDeclaration>(last.Region.Begin);
			var resolver = context.GetResolverStateAfter(node);
			var builder = new TypeSystemAstBuilder(resolver);
			var delegateDecl = builder.ConvertEntity(eventDefinition.ReturnType.GetDefinition()) as DelegateDeclaration;
			if (delegateDecl == null) return;
			var throwStmt = new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException")));
			var decl = new MethodDeclaration() {
				ReturnType = delegateDecl.ReturnType.Clone(),
				Name = name,
				Body = new BlockStatement() {
					throwStmt
				}
			};
			var param = delegateDecl.Parameters.Select(p => p.Clone()).OfType<ParameterDeclaration>().ToArray();
			decl.Parameters.AddRange(param);
			
			using (Script script = context.StartScript()) {
				// FIXME : will not work properly if there are no members.
				if (last == match) {
					throw new NotImplementedException();
					// TODO InsertWithCursor not implemented!
					//script.InsertWithCursor("Insert event handler", Script.InsertPosition.End, decl).RunSynchronously();
				} else {
					// TODO does not jump correctly...
					script.InsertAfter(node, decl);
					editor.JumpTo(throwStmt.StartLocation.Line, throwStmt.StartLocation.Column);
				}
			}
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:46,代码来源:CSharpCodeGenerator.cs


示例15: TypeCompletionData

            public TypeCompletionData(ICSharpCode.NRefactory.TypeSystem.IType type, bool fullName, bool isInAttributeContext, TypeSystemAstBuilder builder, bool addForTypeCreation)
            {
                Type = type;
                FullName = fullName;
                IsInAttributeContext = isInAttributeContext;

                // Confirm that this doesn't also include other types, such as enums, structs, etc.
                //DeclarationCategory = DeclarationCategory.Class;
                DeclarationCategory = type.Kind.ResolveDeclarationCategoryFromTypeKind();

                string typeName = fullName ? builder.ConvertType(type).GetText() : type.Name;
                if (isInAttributeContext && typeName.EndsWith("Attribute") && typeName.Length > "Attribute".Length)
                {
                    typeName = typeName.Substring(0, typeName.Length - "Attribute".Length);
                }
                SetDefaultText(typeName);

                // for documentation, see type.GetDefinition().Documentation
                Documentation = type.GetDefinition().Documentation;
            }
开发者ID:uluhonolulu,项目名称:QCCodingServices.NET,代码行数:20,代码来源:TypeCompletionData.cs


示例16: ConvertSymbol

        public string ConvertSymbol(ISymbol symbol)
        {
            var stringWriter = new StringWriter();
            var astBuilder = new TypeSystemAstBuilder();
            astBuilder.AlwaysUseShortTypeNames = true;
            AstNode node = astBuilder.ConvertSymbol(symbol);
            var writer = new TextWriterTokenWriter (stringWriter);
            var rt = node.GetChildByRole (Roles.Type);
            if (!rt.IsNull)
            {
                rt.AcceptVisitor (new CSharpOutputVisitor (stringWriter, FormattingOptionsFactory.CreateMono()));

            }

            IProperty property = symbol as IProperty;
            if (property != null)
            {
                writer.Space ();
                writer.WriteToken (Roles.LBrace, "{");
                writer.Space ();
                if (property.CanGet)
                {
                    writer.WriteKeyword (PropertyDeclaration.GetKeywordRole, "get");
                    writer.WriteToken (Roles.Semicolon, ";");
                    writer.Space ();
                }
                if (property.CanSet)
                {
                    writer.WriteKeyword (PropertyDeclaration.SetKeywordRole, "set");
                    writer.WriteToken (Roles.Semicolon, ";");
                    writer.Space ();
                }
                writer.WriteToken (Roles.RBrace, "}");
            }
            return stringWriter.ToString();

            }
开发者ID:jcd-as,项目名称:omnisharp-server,代码行数:37,代码来源:ReturnTypeAmbience.cs


示例17: GeneratePartialClassContextStub

		static string GeneratePartialClassContextStub(FileName fileName, TextLocation currentLocation, StackFrame context)
		{
			var compilation = SD.ParserService.GetCompilationForFile(fileName);
			var file = SD.ParserService.GetExistingUnresolvedFile(fileName);
			if (compilation == null || file == null)
				return "";
			var member = file.GetMember(currentLocation);
			if (member == null)
				return "";
			var builder = new TypeSystemAstBuilder();
			EntityDeclaration decl = builder.ConvertEntity(member.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly)));
			decl.Name = "__DebuggerStub_" + decl.Name;
			decl.Modifiers &= (Modifiers.Static);
			switch (member.SymbolKind) {
				case SymbolKind.Property:
					break;
				case SymbolKind.Indexer:
					break;
				case SymbolKind.Event:
					break;
				case SymbolKind.Method:
					GenerateBodyFromContext(builder, context, (MethodDeclaration)decl);
					break;
				case SymbolKind.Operator:
					break;
				case SymbolKind.Constructor:
					break;
				case SymbolKind.Destructor:
					break;
				case SymbolKind.Accessor:
					break;
				default:
					throw new ArgumentOutOfRangeException();
			}
			return WrapInType(member.DeclaringTypeDefinition, decl.ToString());
		}
开发者ID:pentp,项目名称:SharpDevelop,代码行数:36,代码来源:DebuggerDotCompletion.cs


示例18: OverrideContext

        /// <summary>
        ///   Takes an editing context. Inserts an override
        ///   declaration of the chosen member in the context. Returns
        ///   the new context.
        /// </summary>
        /// <remarks>
        ///   The text editor cursor stays in the same line and column
        ///   it originally was.
        /// </remarks>
        public RunOverrideTargetResponse RunOverrideTarget
            (RunOverrideTargetRequest request) {
            var overrideContext = new OverrideContext(request, _parser);
            var refactoringContext = OmniSharpRefactoringContext.GetContext
                (overrideContext.BufferParser, request);

            var memberToOverride = overrideContext.GetOverridableMembers()
                .First(ot => {
                    var memberSignature =
                     GetOverrideTargetsResponse.GetOverrideTargetName
                      (ot, overrideContext.CompletionContext.ResolveContext);

                    return memberSignature == request.OverrideTargetName;});

            var builder = new TypeSystemAstBuilder
                (new CSharpResolver
                 (overrideContext.CompletionContext.ResolveContext))
                 // Will generate a "throw new
                 // NotImplementedException();" statement in the
                 // bodies
                 {GenerateBody = true};

            var newEditorContents = runOverrideTargetWorker
                ( request
                , refactoringContext
                , overrideContext.CompletionContext.ParsedContent
                , script: new OmniSharpScript(refactoringContext, _config)
                , memberDeclaration:
                    builder.ConvertEntity(memberToOverride));

            return new RunOverrideTargetResponse
                ( fileName : request.FileName
                , buffer   : newEditorContents.Text
                , line     : request.Line
                , column   : request.Column);
        }
开发者ID:gamwang,项目名称:vimrc,代码行数:45,代码来源:OverrideHandler.cs


示例19: GetValueAndUpdateUI

		/// <summary> Get the value of the node and update the UI text fields. </summary>
		/// <remarks> This should be only called once so the Value is not cached. </remarks>
		void GetValueAndUpdateUI()
		{
			try {
				Stopwatch watch = new Stopwatch();
				watch.Start();
				
				// Do not keep permanent reference
				Value val = this.getValue();
				
				if (val == null) {
					Value = string.Empty;
					Type  = string.Empty;
					GetChildren = null;
					VisualizerCommands = null;
					return;
				}
				
				// Note that the child collections are lazy-evaluated
				if (val.IsNull) {
					this.GetChildren = null;
				} else if (val.Type.IsPrimitiveType() || val.Type.IsKnownType(KnownTypeCode.String)) { // Must be before IsClass
					this.GetChildren = null;
				} else if (val.Type.Kind == TypeKind.Array) { // Must be before IsClass
					var dimBase = val.ArrayBaseIndicies;		// Eval now
					var dimSize = val.ArrayDimensions;		// Eval now
					if (val.ArrayLength > 0) {
						this.GetChildren = () => GetArrayChildren(dimBase, dimSize);
					}
				} else if (val.Type.Kind == TypeKind.Class || val.Type.Kind == TypeKind.Struct) {
					if (val.Type.IsKnownType(typeof(List<>))) {
						if ((int)val.GetFieldValue("_size").PrimitiveValue > 0)
							this.GetChildren = () => GetIListChildren(this.GetValue);
					} else {
						this.GetChildren = () => GetObjectChildren(val.Type);
					}
				} else if (val.Type.Kind == TypeKind.Pointer) {
					if (val.Dereference() != null) {
						this.GetChildren = () => new[] { new ValueNode(ClassBrowserIconService.LocalVariable, "*" + this.Name, () => GetValue().Dereference()) };
					}
				}
				
				// Do last since it may expire the object
				if (val.IsNull) {
					fullValue = "null";
				} else if (val.Type.IsInteger()) {
					var i = val.PrimitiveValue;
					if (DebuggingOptions.Instance.ShowIntegersAs == ShowIntegersAs.Decimal) {
						fullValue = i.ToString();
					} else {
						string hex = string.Format("0x{0:X4}", i);
						if (hex.Length > 6 ) hex = string.Format("0x{0:X8}", i);
						if (hex.Length > 10) hex = string.Format("0x{0:X16}", i);
						if (DebuggingOptions.Instance.ShowIntegersAs == ShowIntegersAs.Hexadecimal) {
							fullValue = hex;
						} else {
							fullValue = string.Format("{0} ({1})", i, hex);
						}
					}
				} else if (val.Type.Kind == TypeKind.Pointer) {
					fullValue = String.Format("0x{0:X}", val.PointerAddress);
				} else if (val.Type.IsKnownType(KnownTypeCode.String)) {
					fullValue = '"' + val.InvokeToString(WindowsDebugger.EvalThread).Replace("\n", "\\n").Replace("\t", "\\t").Replace("\r", "\\r").Replace("\0", "\\0").Replace("\b", "\\b").Replace("\a", "\\a").Replace("\f", "\\f").Replace("\v", "\\v").Replace("\"", "\\\"") + '"';
				} else if (val.Type.IsKnownType(KnownTypeCode.Char)) {
					fullValue = "'" + val.InvokeToString(WindowsDebugger.EvalThread).Replace("\n", "\\n").Replace("\t", "\\t").Replace("\r", "\\r").Replace("\0", "\\0").Replace("\b", "\\b").Replace("\a", "\\a").Replace("\f", "\\f").Replace("\v", "\\v").Replace("\"", "\\\"") + "'";
				} else if ((val.Type.Kind == TypeKind.Class || val.Type.Kind == TypeKind.Struct)) {
					fullValue = val.FormatByDebuggerDisplayAttribute(WindowsDebugger.EvalThread);
					if (fullValue == null)
						fullValue = val.InvokeToString(WindowsDebugger.EvalThread);
				} else if (val.Type.Kind == TypeKind.Enum) {
					var primitiveValue = val.PrimitiveValue;
					var builder = new TypeSystemAstBuilder();
					builder.AlwaysUseShortTypeNames = true;
					AstNode node = builder.ConvertConstantValue(val.Type, primitiveValue);
					fullValue = node + "=" + primitiveValue;
				} else {
					fullValue = val.AsString();
				}
				
				this.error = null;
				this.Value = (fullValue.Length > 256) ? fullValue.Substring(0, 256) + "..." : fullValue;
				this.Type = val.Type.Name;
				
				if (!val.IsNull) {
					this.VisualizerCommands = VisualizerDescriptors.GetAllDescriptors()
						.Where(descriptor => descriptor.IsVisualizerAvailable(val.Type))
						.Select(descriptor => descriptor.CreateVisualizerCommand(this.Name, this.GetValue))
						.ToList();
				}
				
				LoggingService.InfoFormatted("Evaluated node '{0}' in {1} ms", this.Name, watch.ElapsedMilliseconds);
				
			} catch (GetValueException e) {
				error = e;
				this.Value = e.Message;
				this.Type  = string.Empty;
				this.GetChildren = null;
				this.VisualizerCommands = null;
			} finally {
//.........这里部分代码省略.........
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:101,代码来源:ValueNode.cs


示例20: WriteTypeDeclarationName

 void WriteTypeDeclarationName(ITypeDefinition typeDef, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
 {
     var astBuilder = new TypeSystemAstBuilder();
     EntityDeclaration node = astBuilder.ConvertEntity(typeDef);
     if (typeDef.DeclaringTypeDefinition != null)
     {
         WriteTypeDeclarationName(typeDef.DeclaringTypeDefinition, writer, formattingPolicy);
         writer.WriteToken(Roles.Dot, ".");
     }
     writer.WriteIdentifier(node.NameToken);
     WriteTypeParameters(writer, node.GetChildrenByRole(Roles.TypeParameter));
 }
开发者ID:jcd-as,项目名称:omnisharp-server,代码行数:12,代码来源:SnippetGenerator.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Resolver.CSharpAstResolver类代码示例发布时间:2022-05-26
下一篇:
C# Refactoring.BaseRefactoringContext类代码示例发布时间: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