本文整理汇总了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");
}