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


C# Expression.ToString方法代码示例

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


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

示例1: GetKeyFromExpression

        // ********************************************************************************************************************************
        /// <summary>
        /// Tries to infer the resource key being referenced from the given expression.
        /// </summary>
        static string GetKeyFromExpression(Expression expr, out bool isPrefixOnly)
        {
            isPrefixOnly = false;
            #if DEBUG
            LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver trying to get key from expression: "+expr.ToString());
            #endif

            IndexerExpression indexer = expr as IndexerExpression;
            if (indexer != null) {
                foreach (Expression index in indexer.Indexes) {
                    PrimitiveExpression p = index as PrimitiveExpression;
                    if (p != null) {
                        string key = p.Value as string;
                        if (key != null) {
                            #if DEBUG
                            LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver found key: "+key);
                            #endif
                            return key;
                        }
                    }
                }
            }

            InvocationExpression invocation = expr as InvocationExpression;
            if (invocation != null) {
                MemberReferenceExpression fre = invocation.TargetObject as MemberReferenceExpression;
                if (fre != null) {
                    if (fre.MemberName == "GetString" || fre.MemberName == "GetObject" || fre.MemberName == "GetStream") {
                        if (invocation.Arguments.Count > 0) {
                            PrimitiveExpression p = invocation.Arguments[0] as PrimitiveExpression;
                            if (p != null) {
                                string key = p.Value as string;
                                if (key != null) {
                                    #if DEBUG
                                    LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver found key: "+key);
                                    #endif
                                    return key;
                                }
                            }
                        }
                    } else if (fre.MemberName == "ApplyResources") {
                        if (invocation.Arguments.Count >= 2) {
                            PrimitiveExpression p = invocation.Arguments[1] as PrimitiveExpression;
                            if (p != null) {
                                string key = p.Value as string;
                                if (key != null) {
                                    #if DEBUG
                                    LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver found key prefix: "+key);
                                    #endif
                                    isPrefixOnly = true;
                                    return key;
                                }
                            }
                        }
                    }
                }
            }

            return null;
        }
开发者ID:ichengzi,项目名称:SharpDevelop,代码行数:64,代码来源:BclNRefactoryResourceResolver.cs

示例2: GetKeyFromExpression

		// ********************************************************************************************************************************
		
		/// <summary>
		/// Tries to infer the resource key being referenced from the given expression.
		/// </summary>
		static string GetKeyFromExpression(Expression expr)
		{
			#if DEBUG
			LoggingService.Debug("ResourceToolkit: ICSharpCodeCoreNRefactoryResourceResolver trying to get key from expression: "+expr.ToString());
			#endif
			
			InvocationExpression invocation = expr as InvocationExpression;
			if (invocation != null) {
				MemberReferenceExpression fre = invocation.TargetObject as MemberReferenceExpression;
				if (fre != null) {
					if (fre.MemberName == "GetString") {
						if (invocation.Arguments.Count > 0) {
							PrimitiveExpression p = invocation.Arguments[0] as PrimitiveExpression;
							if (p != null) {
								string key = p.Value as string;
								if (key != null) {
									#if DEBUG
									LoggingService.Debug("ResourceToolkit: ICSharpCodeCoreNRefactoryResourceResolver found key: "+key);
									#endif
									return key;
								}
							}
						}
					}
				}
			}
			
			return null;
		}
开发者ID:kingjiang,项目名称:SharpDevelopLite,代码行数:34,代码来源:ICSharpCodeCoreNRefactoryResourceResolver.cs

示例3: Resolve


//.........这里部分代码省略.........
                if (methrr != null) {
                    if ((methrr.Name == "GetString" || methrr.Name == "GetObject" || methrr.Name == "GetStream" || methrr.Name == "ApplyResources") &&
                        (resolveResult = NRefactoryAstCacheService.ResolveNextOuterExpression(ref expressionResult, caretLine, caretColumn, fileName, fileContent, expressionFinder)) != null) {

                        return ResolveResource(resolveResult, expr);

                    } else {

                        return null;

                    }
                }

            }

            // Do not use "else if" here.
            // '(' is also the IndexerExpressionStartToken for VB,
            // so the "else" block further down might still apply.

            if (charTyped == null) {

                // A MemberResolveResult with a complete expression
                // must only be considered a valid resource reference
                // when Resolve is not invoked from code completion
                // (i.e. charTyped == null) because this indicates
                // that the resource reference is already before the typed character
                // and we are not interested in the following expression.
                // This may happen when typing something like:
                // Something.GetString("...")[

                MemberResolveResult mrr = resolveResult as MemberResolveResult;
                if (mrr != null) {

                    if (mrr.ResolvedMember is IMethod &&
                        (mrr.ResolvedMember.Name == "GetString" || mrr.ResolvedMember.Name == "GetObject" || mrr.ResolvedMember.Name == "GetStream" || mrr.ResolvedMember.Name == "ApplyResources")) {

                        // Something.GetString("...")
                        // This is a MemberResolveResult and we need the reference to "Something".
                        // The expression finder may only remove the string literal, so
                        // we have to call Resolve again in this case to resolve
                        // the method reference.

                        if ((resolveResult = NRefactoryAstCacheService.ResolveNextOuterExpression(ref expressionResult, caretLine, caretColumn, fileName, fileContent, expressionFinder)) != null) {

                            if (resolveResult is MethodGroupResolveResult) {
                                return this.Resolve(expressionResult, expr, resolveResult, caretLine, caretColumn, fileName, fileContent, expressionFinder, '(');
                            } else {
                                return ResolveResource(resolveResult, expr);
                            }

                        } else {

                            return null;

                        }

                    } else if (expr is IndexerExpression &&
                               IsResourceManager(mrr.ResolvedMember.DeclaringType.DefaultReturnType, fileName)) {

                        // Something["..."] is an IndexerExpression.
                        // We need the reference to Something and this is
                        // the next outer expression.

                        if ((resolveResult = NRefactoryAstCacheService.ResolveNextOuterExpression(ref expressionResult, caretLine, caretColumn, fileName, fileContent, expressionFinder)) != null) {
                            return ResolveResource(resolveResult, expr);
                        } else {
                            return null;
                        }

                    }

                }

            } else {

                // This request is triggered from code completion.
                // The only case that has not been caught above is:
                // Something[
                // The reference to "Something" is already in this expression.
                // So we have to test the trigger character against the
                // indexer expression start token of the file's language.

                LanguageProperties lp = NRefactoryResourceResolver.GetLanguagePropertiesForFile(fileName);
                if (lp != null &&
                    !String.IsNullOrEmpty(lp.IndexerExpressionStartToken) &&
                    lp.IndexerExpressionStartToken[0] == charTyped) {

                    #if DEBUG
                    LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver: Indexer expression start typed, ResolveResult: "+resolveResult.ToString());
                    LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver: -> Expression: "+expr.ToString());
                    #endif

                    return ResolveResource(resolveResult, expr);

                }

            }

            return null;
        }
开发者ID:ichengzi,项目名称:SharpDevelop,代码行数:101,代码来源:BclNRefactoryResourceResolver.cs

示例4: Resolve

		/// <summary>
		/// Resolves an expression in the current node's context.
		/// </summary>
		/// <param name="expression">The expression to be resolved.</param>
		/// <param name="context">The ExpressionContext.</param>
		public ResolveResult Resolve(Expression expression, ExpressionContext context)
		{
			if (!this.PositionAvailable) {
				LoggingService.Info("ResourceToolkit: PositionTrackingAstVisitor: Resolve failed due to position information being unavailable. Expression: "+expression.ToString());
				return null;
			}
			
			#if DEBUG
			LoggingService.Debug("ResourceToolkit: PositionTrackingAstVisitor: Using this parent node for resolve: "+this.parentNodes.Peek().ToString());
			#endif
			
			return NRefactoryAstCacheService.ResolveLowLevel(this.fileName, this.fileContent, this.CurrentNodeStartLocation.Y, this.CurrentNodeStartLocation.X+1, this.compilationUnit, null, expression, context);
		}
开发者ID:kingjiang,项目名称:SharpDevelopLite,代码行数:18,代码来源:PositionTrackingAstVisitor.cs


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