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


C# ReturnStatementSyntax.Ancestors方法代码示例

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


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

示例1: Go

        public static void Go(OutputWriter writer, ReturnStatementSyntax statement)
        {

            var slambda = statement.Ancestors().OfType<SimpleLambdaExpressionSyntax>().FirstOrDefault();
            var plambda = statement.Ancestors().OfType<ParenthesizedLambdaExpressionSyntax>().FirstOrDefault();
            var mlambda = statement.Ancestors().OfType<AnonymousMethodExpressionSyntax>().FirstOrDefault();


            var method = statement.Ancestors().OfType<MethodDeclarationSyntax>().FirstOrDefault();
            var property = statement.Ancestors().OfType<PropertyDeclarationSyntax>().FirstOrDefault();
            var indexer = statement.Ancestors().OfType<IndexerDeclarationSyntax>().FirstOrDefault();
            var converter = statement.Ancestors().OfType<ConversionOperatorDeclarationSyntax>().FirstOrDefault();
            var @operator = statement.Ancestors().OfType<OperatorDeclarationSyntax>().FirstOrDefault();

            ITypeSymbol returnTypeSymbol = null;

            if (method != null)
            {
                returnTypeSymbol = TypeProcessor.GetTypeInfo(method.ReturnType).Type;
            }

            if (property != null)
            {
                returnTypeSymbol = TypeProcessor.GetTypeInfo(property.Type).Type;
            }

            if (indexer != null)
            {
                returnTypeSymbol = TypeProcessor.GetTypeInfo(indexer.Type).Type;
            }

            if (converter != null)
            {
                returnTypeSymbol = TypeProcessor.GetTypeInfo(converter.Type).Type;
            }


            if (@operator != null)
            {
                returnTypeSymbol = TypeProcessor.GetTypeInfo(@operator.ReturnType).Type;
            }

            if (plambda != null)
            {
                returnTypeSymbol = TypeProcessor.GetTypeInfo(plambda).Type;
            }

            if (slambda != null)
            {
                returnTypeSymbol = TypeProcessor.GetTypeInfo(slambda).Type;
            }

            if (mlambda != null)
            {
                returnTypeSymbol = TypeProcessor.GetTypeInfo(statement.Expression).ConvertedType;
            }


            writer.WriteIndent();
            writer.Write("return");

            if (statement.Expression != null)
            {
                {

                    var rightExpressionType = TypeProcessor.GetTypeInfo(statement.Expression);

                    var boxRight = rightExpressionType.ConvertedType != null &&
                                   (rightExpressionType.Type != null && (rightExpressionType.Type!=rightExpressionType.ConvertedType) &&
                                    ((rightExpressionType.Type.IsValueType ||
                                      rightExpressionType.Type.TypeKind == TypeKind.TypeParameter) &&
                                     (rightExpressionType.ConvertedType.IsReferenceType)));
                    boxRight = boxRight && (rightExpressionType.Type != returnTypeSymbol);

                    if(!boxRight && returnTypeSymbol!=Context.Object)
					if (!Equals(returnTypeSymbol, rightExpressionType.Type) && !rightExpressionType.Type.IsSubclassOf(returnTypeSymbol))
                    {
                        writer.Write(" cast(" + TypeProcessor.ConvertType(returnTypeSymbol) + ")");
                    }

                   writer.Write (boxRight ? " BOX!(" + TypeProcessor.ConvertType(rightExpressionType.Type) + ")(" : " ");
                    Core.Write(writer, statement.Expression);

                    writer.Write(boxRight ? ")" : "");

                }
                

            }
            writer.Write(";\r\n");
        }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:91,代码来源:WriteReturnStatement.cs


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