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


C# ImmutableArray.Reverse方法代码示例

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


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

示例1: TestSemanticModelAPI

        private static void TestSemanticModelAPI(
            CSharpCompilation compilation, 
            SyntaxTree tree, 
            ImmutableArray<SemanticModelInfo> infos, 
            ImmutableArray<Diagnostic> diagnostics, 
            bool backwards)
        {
            SemanticModel semanticModel = compilation.GetSemanticModel(tree);

            SymbolInfo symInfo;
            TypeInfo typeInfo;

            foreach (var info in backwards ? infos.Reverse() : infos)
            {
                info.Clear();

                switch (info.Node.Kind)
                {
                    case SyntaxKind.Parameter:
                        var parameterDecl = (ParameterSyntax)info.Node;
                        var param = (ParameterSymbol)semanticModel.GetDeclaredSymbol(parameterDecl);

                        Assert.Equal(parameterDecl.Identifier.ValueText, param.Name);
                        Assert.Equal(parameterDecl.Identifier.GetLocation(), param.Locations[0]);

                        info.SymInfo = new SymbolInfo(param);
                        break;

                    case SyntaxKind.VariableDeclarator:
                        var declarator = (VariableDeclaratorSyntax)info.Node;
                        var local = (LocalSymbol)semanticModel.GetDeclaredSymbol(declarator);

                        if ((object)local != null)
                        {
                            Assert.Equal(declarator.Identifier.ValueText, local.Name);
                            Assert.Equal(declarator.Identifier.GetLocation(), local.Locations[0]);
                        }
                        else if (declarator.Identifier.IsMissing)
                        {
                            break;
                        }
                        else
                        {
                            Assert.Equal(SyntaxKind.DeclarationExpression, declarator.Parent.Kind);
                            Assert.True(diagnostics.Where(d => d.Code == (int)ErrorCode.ERR_DeclarationExpressionOutOfContext &&
                                                          d.Location == declarator.Parent.GetLocation()).Any());
                            break;
                        }

                        info.SymInfo = new SymbolInfo(local);

                        if (declarator.Parent.Kind == SyntaxKind.DeclarationExpression)
                        {
                            Assert.Equal(LocalDeclarationKind.RegularVariable, local.DeclarationKind);

                            var declExpr = (DeclarationExpressionSyntax)declarator.Parent;
                            symInfo = semanticModel.GetSymbolInfo(declExpr);
                            Assert.Same(local, symInfo.Symbol);

                            typeInfo = semanticModel.GetTypeInfo(declExpr);
                            Assert.Equal(local.Type, typeInfo.Type);
                        }

                        Assert.True(semanticModel.LookupNames(declarator.Identifier.Position).Contains(local.Name));

                        var declDiagnostics = diagnostics.Where(d => d.Location == declarator.Identifier.GetLocation()).ToArray();

                        bool duplicate = declDiagnostics.Where(d => d.Code == (int)ErrorCode.ERR_LocalDuplicate).Any();
                        bool overrides = declDiagnostics.Where(d => d.Code == (int)ErrorCode.ERR_LocalIllegallyOverrides).Any();

                        Assert.False(duplicate && overrides);

                        if (duplicate)
                        {
                            Assert.NotEqual(local, semanticModel.LookupSymbols(declarator.Identifier.Position, name: local.Name).Single());
                        }
                        else
                        {
                            Assert.Same(local, semanticModel.LookupSymbols(declarator.Identifier.Position, name: local.Name).Single());
                        }

                        break;

                    case SyntaxKind.CatchDeclaration:
                        var catchDecl = (CatchDeclarationSyntax)info.Node;
                        local = (LocalSymbol)semanticModel.GetDeclaredSymbol(catchDecl);
                        Assert.Equal(catchDecl.Identifier.ValueText, local.Name);
                        Assert.Equal(catchDecl.Identifier.GetLocation(), local.Locations[0]);

                        info.SymInfo = new SymbolInfo(local);
                        break;

                    case SyntaxKind.ForEachStatement:
                        var loop = (ForEachStatementSyntax)info.Node;
                        local = (LocalSymbol)semanticModel.GetDeclaredSymbol(loop);
                        Assert.Equal(loop.Identifier.ValueText, local.Name);
                        Assert.Equal(loop.Identifier.GetLocation(), local.Locations[0]);

                        info.SymInfo = new SymbolInfo(local);
                        break;
//.........这里部分代码省略.........
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:101,代码来源:DeclarationExpressionsTests.cs


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