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


C# CSharpCompilation.ClassifyConversion方法代码示例

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


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

示例1: CheckDependencies

        private ImmutableArray<Diagnostic> CheckDependencies(CSharpCompilation compilation, IList<Tuple<AttributeData, ISymbol>> dependencies, INamedTypeSymbol recognizerType)
        {
            string[] ruleNames = GetRuleNames(recognizerType);
            int[] ruleVersions = GetRuleVersions(recognizerType, ruleNames);
            RuleRelations relations = ExtractRuleRelations(recognizerType);
            ImmutableArray<Diagnostic>.Builder errors = ImmutableArray.CreateBuilder<Diagnostic>();
            foreach (var dependency in dependencies)
            {
                if (ruleNames == null)
                {
                    Location location = GetRecognizerTypeLocation(dependency.Item1);
                    errors.Add(Diagnostic.Create(AnalysisError, location, "could not read rule names from generated parser"));
                    continue;
                }

                if (ruleVersions == null)
                {
                    Location location = GetRecognizerTypeLocation(dependency.Item1);
                    errors.Add(Diagnostic.Create(AnalysisError, location, "could not read rule versions from generated parser"));
                    continue;
                }

                if (relations == null)
                {
                    Location location = GetRecognizerTypeLocation(dependency.Item1);
                    errors.Add(Diagnostic.Create(AnalysisError, location, "could not read the ATN from the generated parser"));
                    continue;
                }

                if (!compilation.ClassifyConversion(recognizerType, GetRecognizerType(dependency.Item1)).IsImplicit)
                {
                    Location location = GetRecognizerTypeLocation(dependency.Item1);
                    errors.Add(Diagnostic.Create(AnalysisError, location, string.Format("could not convert '{0}' to '{1}'", recognizerType, GetRecognizerType(dependency.Item1))));
                    continue;
                }

                // this is the rule in the dependency set with the highest version number
                int effectiveRule = GetRule(dependency.Item1);
                if (effectiveRule < 0 || effectiveRule >= ruleVersions.Length)
                {
                    Location location = GetRuleLocation(dependency.Item1);
                    errors.Add(Diagnostic.Create(UnknownRule, location, GetRule(dependency.Item1), GetRecognizerType(dependency.Item1)));
                    continue;
                }

                Dependents dependents = Dependents.Self | (GetDependents(dependency.Item1) ?? Dependents.Parents);
                bool containsUnimplemented = ReportUnimplementedDependents(errors, dependency, ruleNames, dependents);
                bool[] @checked = new bool[ruleNames.Length];
                int highestRequiredDependency = CheckDependencyVersion(errors, dependency, ruleNames, ruleVersions, effectiveRule, null);
                if ((dependents & Dependents.Parents) != 0)
                {
                    bool[] parents = relations.parents[GetRule(dependency.Item1)];
                    for (int parent = Array.IndexOf(parents, true, 0); parent >= 0; parent = Array.IndexOf(parents, true, parent + 1))
                    {
                        if (parent >= ruleVersions.Length)
                        {
                            errors.Add(Diagnostic.Create(AnalysisError, GetLocation(dependency.Item1), "parent index out of range during analysis"));
                            continue;
                        }

                        if (@checked[parent])
                            continue;

                        @checked[parent] = true;
                        int required = CheckDependencyVersion(errors, dependency, ruleNames, ruleVersions, parent, "parent");
                        highestRequiredDependency = Math.Max(highestRequiredDependency, required);
                    }
                }

                if ((dependents & Dependents.Children) != 0)
                {
                    bool[] children = relations.children[GetRule(dependency.Item1)];
                    for (int child = Array.IndexOf(children, true, 0); child >= 0; child = Array.IndexOf(children, true, child + 1))
                    {
                        if (child >= ruleVersions.Length)
                        {
                            errors.Add(Diagnostic.Create(AnalysisError, GetLocation(dependency.Item1), "child index out of range during analysis"));
                            continue;
                        }

                        if (@checked[child])
                            continue;

                        @checked[child] = true;
                        int required = CheckDependencyVersion(errors, dependency, ruleNames, ruleVersions, child, "child");
                        highestRequiredDependency = Math.Max(highestRequiredDependency, required);
                    }
                }

                if ((dependents & Dependents.Ancestors) != 0)
                {
                    bool[] ancestors = relations.GetAncestors(GetRule(dependency.Item1));
                    for (int ancestor = Array.IndexOf(ancestors, true, 0); ancestor >= 0; ancestor = Array.IndexOf(ancestors, true, ancestor + 1))
                    {
                        if (ancestor >= ruleVersions.Length)
                        {
                            errors.Add(Diagnostic.Create(AnalysisError, GetLocation(dependency.Item1), "ancestor index out of range during analysis"));
                            continue;
                        }

//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:RuleDependencyAnalyzer,代码行数:101,代码来源:DiagnosticAnalyzer.cs


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