• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# CSharp.Location类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Location类属于Microsoft.CodeAnalysis.CSharp命名空间,在下文中一共展示了Location类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: VerifyDiagnosticLocation

        private static void VerifyDiagnosticLocation(DiagnosticAnalyzer analyzer, Diagnostic diagnostic, Location actual, DiagnosticResultLocation expected)
        {
            var actualSpan = actual.GetLineSpan();

            Assert.True(actualSpan.Path == expected.Path || (actualSpan.Path != null && actualSpan.Path.Contains("Test0.") && expected.Path.Contains("Test.")),
                string.Format("Expected diagnostic to be in file \"{0}\" was actually in file \"{1}\"\r\n\r\nDiagnostic:\r\n    {2}\r\n",
                    expected.Path, actualSpan.Path, FormatDiagnostics(analyzer, diagnostic)));

            var actualLinePosition = actualSpan.StartLinePosition;

            // Only check line position if there is an actual line in the real diagnostic
            if (actualLinePosition.Line > 0)
            {
                if (actualLinePosition.Line + 1 != expected.Line)
                {
                    Assert.True(false,
                        string.Format("Expected diagnostic to be on line \"{0}\" was actually on line \"{1}\"\r\n\r\nDiagnostic:\r\n    {2}\r\n",
                            expected.Line, actualLinePosition.Line + 1, FormatDiagnostics(analyzer, diagnostic)));
                }
            }

            // Only check column position if there is an actual column position in the real diagnostic
            if (actualLinePosition.Character > 0)
            {
                if (actualLinePosition.Character + 1 != expected.Column)
                {
                    Assert.True(false,
                        string.Format("Expected diagnostic to start at column \"{0}\" was actually at column \"{1}\"\r\n\r\nDiagnostic:\r\n    {2}\r\n",
                            expected.Column, actualLinePosition.Character + 1, FormatDiagnostics(analyzer, diagnostic)));
                }
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:32,代码来源:DiagnosticAnalyzerTests.Extensions.cs


示例2: Add

 internal static CSDiagnosticInfo Add(this DiagnosticBag diagnostics, ErrorCode code, Location location, ImmutableArray<Symbol> symbols, params object[] args)
 {
     var info = new CSDiagnosticInfo(code, args, symbols, ImmutableArray<Location>.Empty);
     var diag = new CSDiagnostic(info, location);
     diagnostics.Add(diag);
     return info;
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:7,代码来源:DiagnosticBagExtensions.cs


示例3: GetDiagnosticReport

        // Take a warning and return the final deposition of the given warning,
        // based on both command line options and pragmas.
        // If you update this method, also update DiagnosticItemSource.GetEffectiveSeverity. 
        internal static ReportDiagnostic GetDiagnosticReport(DiagnosticSeverity severity, bool isEnabledByDefault, string id, int diagnosticWarningLevel, Location location, string category, int warningLevelOption, ReportDiagnostic generalDiagnosticOption, IDictionary<string, ReportDiagnostic> specificDiagnosticOptions)
        {
            // Read options (e.g., /nowarn or /warnaserror)
            ReportDiagnostic report = ReportDiagnostic.Default;
            var isSpecified = specificDiagnosticOptions.TryGetValue(id, out report);
            if (!isSpecified)
            {
                report = isEnabledByDefault ? ReportDiagnostic.Default : ReportDiagnostic.Suppress;
            }

            // Compute if the reporting should be suppressed.
            if (diagnosticWarningLevel > warningLevelOption  // honor the warning level
                || report == ReportDiagnostic.Suppress)                // check options (/nowarn)
            {
                return ReportDiagnostic.Suppress;
            }

            // If location is available, check out pragmas
            if (location != null &&
                location.SourceTree != null &&
                ((SyntaxTree)location.SourceTree).GetPragmaDirectiveWarningState(id, location.SourceSpan.Start) == ReportDiagnostic.Suppress)
            {
                return ReportDiagnostic.Suppress;
            }

            // Unless specific warning options are defined (/warnaserror[+|-]:<n> or /nowarn:<n>, 
            // follow the global option (/warnaserror[+|-] or /nowarn).
            if (report == ReportDiagnostic.Default)
            {
                switch (generalDiagnosticOption)
                {
                    case ReportDiagnostic.Error:
                        // If we've been asked to do warn-as-error then don't raise severity for anything below warning (info or hidden).
                        if (severity == DiagnosticSeverity.Warning)
                        {
                            // In the case where /warnaserror+ is followed by /warnaserror-:<n> on the command line,
                            // do not promote the warning specified in <n> to an error.
                            if (!isSpecified && (report == ReportDiagnostic.Default))
                            {
                                return ReportDiagnostic.Error;
                            }
                        }
                        break;
                    case ReportDiagnostic.Suppress:
                        // When doing suppress-all-warnings, don't lower severity for anything other than warning and info.
                        // We shouldn't suppress hidden diagnostics here because then features that use hidden diagnostics to
                        // display a lightbulb would stop working if someone has suppress-all-warnings (/nowarn) specified in their project.
                        if (severity == DiagnosticSeverity.Warning || severity == DiagnosticSeverity.Info)
                        {
                            return ReportDiagnostic.Suppress;
                        }
                        break;
                    default:
                        break;
                }
            }

            return report;
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:62,代码来源:CSharpDiagnosticFilter.cs


示例4: ReportUnsafeIfNotAllowed

        /// <returns>True if a diagnostic was reported, or would have been reported if not for
        /// the suppress flag.</returns>
        private bool ReportUnsafeIfNotAllowed(Location location, TypeSymbol sizeOfTypeOpt, DiagnosticBag diagnostics)
        {
            var diagnosticInfo = GetUnsafeDiagnosticInfo(sizeOfTypeOpt);
            if (diagnosticInfo == null || this.Flags.Includes(BinderFlags.SuppressUnsafeDiagnostics))
            {
                return false;
            }

            diagnostics.Add(new CSDiagnostic(diagnosticInfo, location));
            return true;
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:13,代码来源:Binder_Unsafe.cs


示例5: EnsureSingleDefinition

        internal override bool EnsureSingleDefinition(Symbol symbol, string name, Location location, DiagnosticBag diagnostics)
        {
            ParameterSymbol existingDeclaration;
            var map = this.definitionMap;
            if (map != null && map.TryGetValue(name, out existingDeclaration))
            {
                return InMethodBinder.ReportConflictWithParameter(existingDeclaration, symbol, name, location, diagnostics);
            }

            return false;
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:11,代码来源:WithPrimaryConstructorParametersBinder.cs


示例6: WithLocation

        internal override Diagnostic WithLocation(Location location)
        {
            if (location == null)
            {
                throw new ArgumentNullException(nameof(location));
            }

            if (location != this.Location)
            {
                return new CSDiagnostic(this.Info, location);
            }

            return this;
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:14,代码来源:CSDiagnostic.cs


示例7: GetUnsafeDiagnostic

 private Diagnostic GetUnsafeDiagnostic(Location location, TypeSymbol sizeOfTypeOpt)
 {
     if (this.IsIndirectlyInIterator)
     {
         // Spec 8.2: "An iterator block always defines a safe context, even when its declaration
         // is nested in an unsafe context."
         return new CSDiagnostic(new CSDiagnosticInfo(ErrorCode.ERR_IllegalInnerUnsafe), location);
     }
     else if (!this.InUnsafeRegion)
     {
         return ReferenceEquals(sizeOfTypeOpt, null)
             ? new CSDiagnostic(new CSDiagnosticInfo(ErrorCode.ERR_UnsafeNeeded), location)
             : new CSDiagnostic(new CSDiagnosticInfo(ErrorCode.ERR_SizeofUnsafe, sizeOfTypeOpt), location);
     }
     else
     {
         return null;
     }
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:19,代码来源:Binder_Unsafe.cs


示例8: AppendUseSiteDiagnostics

        internal static bool AppendUseSiteDiagnostics(
            Location location,
            HashSet<DiagnosticInfo> useSiteDiagnostics,
            DiagnosticBag diagnostics)
        {
            if (useSiteDiagnostics.IsNullOrEmpty())
            {
                return false;
            }

            bool haveErrors = false;

            foreach (var info in useSiteDiagnostics)
            {
                if (info.Severity == DiagnosticSeverity.Error)
                {
                    haveErrors = true;
                }

                Error(diagnostics, info, location);
            }

            return haveErrors;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:24,代码来源:Binder_UseSiteDiagnostics.cs


示例9: EnterIncludeElement

            private bool EnterIncludeElement(Location location)
            {
                if (this.inProgressIncludeElementNodes == null)
                {
                    this.inProgressIncludeElementNodes = new HashSet<Location>();
                }

                return this.inProgressIncludeElementNodes.Add(location);
            }
开发者ID:riversky,项目名称:roslyn,代码行数:9,代码来源:DocumentationCommentCompiler.IncludeElementExpander.cs


示例10: LeaveIncludeElement

 private bool LeaveIncludeElement(Location location)
 {
     Debug.Assert(this.inProgressIncludeElementNodes != null);
     bool result = this.inProgressIncludeElementNodes.Remove(location);
     Debug.Assert(result);
     return result;
 }
开发者ID:riversky,项目名称:roslyn,代码行数:7,代码来源:DocumentationCommentCompiler.IncludeElementExpander.cs


示例11: MakeCommentMessage

 private string MakeCommentMessage(Location location, MessageID messageId)
 {
     if (location.IsInSource)
     {
         // TODO: use culture from compilation instead of invariant culture?
         return ErrorFacts.GetMessage(messageId, CultureInfo.InvariantCulture);
     }
     else
     {
         return null;
     }
 }
开发者ID:riversky,项目名称:roslyn,代码行数:12,代码来源:DocumentationCommentCompiler.IncludeElementExpander.cs


示例12: CompareSourceLocations

        internal override int CompareSourceLocations(Location loc1, Location loc2)
        {
            Debug.Assert(loc1.IsInSource);
            Debug.Assert(loc2.IsInSource);

            var comparison = CompareSyntaxTreeOrdering(loc1.SourceTree, loc2.SourceTree);
            if (comparison != 0)
            {
                return comparison;
            }

            return loc1.SourceSpan.Start - loc2.SourceSpan.Start;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:13,代码来源:CSharpCompilation.cs


示例13: ReportUseSiteDiagnosticForSynthesizedAttribute

        /// <summary>
        /// Report diagnostics that should be reported when using a synthesized attribute. 
        /// </summary>
        internal static void ReportUseSiteDiagnosticForSynthesizedAttribute(
            CSharpCompilation compilation,
            WellKnownMember attributeMember,
            DiagnosticBag diagnostics,
            Location location = null,
            CSharpSyntaxNode syntax = null)
        {
            Debug.Assert((location != null) ^ (syntax != null));

            // Dev11 reports use-site diagnostics when an optional attribute is found but is bad for some other reason 
            // (comes from an unified assembly). When the symbol is not found no error is reported. See test VersionUnification_UseSiteDiagnostics_OptionalAttributes.
            bool isOptional = WellKnownMembers.IsSynthesizedAttributeOptional(attributeMember);

            GetWellKnownTypeMember(compilation, attributeMember, diagnostics, location, syntax, isOptional);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:18,代码来源:Binder.cs


示例14: Error

 internal static void Error(DiagnosticBag diagnostics, ErrorCode code, Location location)
 {
     diagnostics.Add(new CSDiagnostic(new CSDiagnosticInfo(code), location));
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:4,代码来源:Binder.cs


示例15: MethodGroupConversionDoesNotExistOrHasErrors

        /// <summary>
        /// This method is a wrapper around MethodGroupConversionHasErrors.  As a preliminary step,
        /// it checks whether a conversion exists.
        /// </summary>
        private bool MethodGroupConversionDoesNotExistOrHasErrors(
            BoundMethodGroup boundMethodGroup,
            NamedTypeSymbol delegateType,
            Location delegateMismatchLocation,
            DiagnosticBag diagnostics,
            out Conversion conversion)
        {
            if (ReportDelegateInvokeUseSiteDiagnostic(diagnostics, delegateType, delegateMismatchLocation))
            {
                conversion = Conversion.NoConversion;
                return true;
            }

            HashSet<DiagnosticInfo> useSiteDiagnostics = null;
            conversion = Conversions.GetMethodGroupConversion(boundMethodGroup, delegateType, ref useSiteDiagnostics);
            diagnostics.Add(delegateMismatchLocation, useSiteDiagnostics);
            if (!conversion.Exists)
            {
                // No overload for '{0}' matches delegate '{1}'
                diagnostics.Add(ErrorCode.ERR_MethDelegateMismatch, delegateMismatchLocation, boundMethodGroup.Name, delegateType);
                return true;
            }
            else
            {
                Debug.Assert(conversion.IsValid); // i.e. if it exists, then it is valid.
                // Only cares about nullness and type of receiver, so no need to worry about BoundTypeOrValueExpression.
                return this.MethodGroupConversionHasErrors(boundMethodGroup.Syntax, conversion, boundMethodGroup.ReceiverOpt, conversion.IsExtensionMethod, delegateType, diagnostics);
            }
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:33,代码来源:Binder_Conversions.cs


示例16: RecordBindingDiagnostics

 /// <remarks>
 /// Respects the DocumentationMode at the source location.
 /// </remarks>
 private void RecordBindingDiagnostics(DiagnosticBag bindingDiagnostics, Location sourceLocation)
 {
     if (!bindingDiagnostics.IsEmptyWithoutResolution && ((SyntaxTree)sourceLocation.SourceTree).ReportDocumentationCommentDiagnostics())
     {
         foreach (Diagnostic diagnostic in bindingDiagnostics.AsEnumerable())
         {
             // CONSIDER: Dev11 actually uses the originating location plus the offset into the cref/name,
             // but that just seems silly.
             diagnostics.Add(diagnostic.WithLocation(sourceLocation));
         }
     }
 }
开发者ID:riversky,项目名称:roslyn,代码行数:15,代码来源:DocumentationCommentCompiler.IncludeElementExpander.cs


示例17: RecordSyntaxDiagnostics

 /// <remarks>
 /// Respects the DocumentationMode at the source location.
 /// </remarks>
 private void RecordSyntaxDiagnostics(CSharpSyntaxNode treelessSyntax, Location sourceLocation)
 {
     if (treelessSyntax.ContainsDiagnostics && ((SyntaxTree)sourceLocation.SourceTree).ReportDocumentationCommentDiagnostics())
     {
         // NOTE: treelessSyntax doesn't have its own SyntaxTree, so we have to access the diagnostics
         // via the Dummy tree.
         foreach (Diagnostic diagnostic in CSharpSyntaxTree.Dummy.GetDiagnostics(treelessSyntax))
         {
             diagnostics.Add(diagnostic.WithLocation(sourceLocation));
         }
     }
 }
开发者ID:riversky,项目名称:roslyn,代码行数:15,代码来源:DocumentationCommentCompiler.IncludeElementExpander.cs


示例18: ReportUnassignedOutParameter

        protected override void ReportUnassignedOutParameter(
            ParameterSymbol parameter,
            SyntaxNode node,
            Location location)
        {
            if (node != null && node is ReturnStatementSyntax && RegionContains(node.Span))
            {
                _dataFlowsIn.Add(parameter);
            }

            base.ReportUnassignedOutParameter(parameter, node, location);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:12,代码来源:DataFlowsInWalker.cs


示例19: MethodGroupIsCompatibleWithDelegate

        /// <summary>
        /// This method implements the checks in spec section 15.2.
        /// </summary>
        private bool MethodGroupIsCompatibleWithDelegate(BoundExpression receiverOpt, bool isExtensionMethod, MethodSymbol method, NamedTypeSymbol delegateType, Location errorLocation, DiagnosticBag diagnostics)
        {
            Debug.Assert(delegateType.TypeKind == TypeKind.Delegate);
            Debug.Assert((object)delegateType.DelegateInvokeMethod != null && !delegateType.DelegateInvokeMethod.HasUseSiteError,
                         "This method should only be called for valid delegate types.");

            MethodSymbol delegateMethod = delegateType.DelegateInvokeMethod;

            Debug.Assert(!isExtensionMethod || (receiverOpt != null));

            // - Argument types "match", and
            var delegateParameters = delegateMethod.Parameters;
            var methodParameters = method.Parameters;
            int numParams = delegateParameters.Length;

            if (methodParameters.Length != numParams + (isExtensionMethod ? 1 : 0))
            {
                // This can happen if "method" has optional parameters.
                Debug.Assert(methodParameters.Length > numParams + (isExtensionMethod ? 1 : 0));
                Error(diagnostics, ErrorCode.ERR_MethDelegateMismatch, errorLocation, method, delegateType);
                return false;
            }

            HashSet<DiagnosticInfo> useSiteDiagnostics = null;

            // If this is an extension method delegate, the caller should have verified the
            // receiver is compatible with the "this" parameter of the extension method.
            Debug.Assert(!isExtensionMethod ||
                (Conversions.ConvertExtensionMethodThisArg(methodParameters[0].Type, receiverOpt.Type, ref useSiteDiagnostics).Exists && useSiteDiagnostics.IsNullOrEmpty()));

            useSiteDiagnostics = null;

            for (int i = 0; i < numParams; i++)
            {
                var delegateParameterType = delegateParameters[i].Type;
                var methodParameterType = methodParameters[isExtensionMethod ? i + 1 : i].Type;

                if (!Conversions.HasIdentityOrImplicitReferenceConversion(delegateParameterType, methodParameterType, ref useSiteDiagnostics))
                {
                    // No overload for '{0}' matches delegate '{1}'
                    Error(diagnostics, ErrorCode.ERR_MethDelegateMismatch, errorLocation, method, delegateType);
                    diagnostics.Add(errorLocation, useSiteDiagnostics);
                    return false;
                }
            }

            // - Return types "match"
            var returnsMatch =
                method.ReturnsVoid && delegateMethod.ReturnsVoid ||
                Conversions.HasIdentityOrImplicitReferenceConversion(method.ReturnType, delegateMethod.ReturnType, ref useSiteDiagnostics);
            if (!returnsMatch)
            {
                Error(diagnostics, ErrorCode.ERR_BadRetType, errorLocation, method, method.ReturnType);
                diagnostics.Add(errorLocation, useSiteDiagnostics);
                return false;
            }

            diagnostics.Add(errorLocation, useSiteDiagnostics);

            if (method.IsConditional)
            {
                // CS1618: Cannot create delegate with '{0}' because it has a Conditional attribute
                Error(diagnostics, ErrorCode.ERR_DelegateOnConditional, errorLocation, method);
                return false;
            }

            var sourceMethod = method as SourceMemberMethodSymbol;
            if ((object)sourceMethod != null && sourceMethod.IsPartialWithoutImplementation)
            {
                // CS0762: Cannot create delegate from method '{0}' because it is a partial method without an implementing declaration
                Error(diagnostics, ErrorCode.ERR_PartialMethodToDelegate, errorLocation, method);
                return false;
            }

            return true;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:79,代码来源:Binder_Conversions.cs


示例20: ValidateLambdaParameterNameConflictsInScope

 private bool ValidateLambdaParameterNameConflictsInScope(Location location, string name, DiagnosticBag diagnostics)
 {
     return ValidateNameConflictsInScope(null, location, name, diagnostics);
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:4,代码来源:Binder_NameConflicts.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CSharp.Symbol类代码示例发布时间:2022-05-26
下一篇:
C# CSharp.ExecutableCodeBinder类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap