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

C# Syntax.AttributeSyntax类代码示例

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

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



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

示例1: TryGetThreadStaticAttribute

        private static bool TryGetThreadStaticAttribute(SyntaxList<AttributeListSyntax> attributeLists, SemanticModel semanticModel, out AttributeSyntax threadStaticAttribute)
        {
            threadStaticAttribute = null;

            if (!attributeLists.Any())
            {
                return false;
            }

            foreach (var attributeList in attributeLists)
            {
                foreach (var attribute in attributeList.Attributes)
                {
                    var attributeType = semanticModel.GetTypeInfo(attribute).Type;

                    if (attributeType != null &&
                        attributeType.ToDisplayString() == ThreadStaticAttributeName)
                    {
                        threadStaticAttribute = attribute;
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:ozgurkayaist,项目名称:sonarlint-vs,代码行数:26,代码来源:ThreadStaticNonStaticField.cs


示例2: ExtractMethodsFromAttributes

        private static List<TestCase> ExtractMethodsFromAttributes(TestFixtureDetails testFixture, ISemanticModel semanticModel,
            AttributeSyntax attribute)
        {
            List<TestCase> methodTestCases=new List<TestCase>();

            if (attribute.Name.ToString() == "Test")
            {
                var testCase = ExtractTest(attribute, testFixture);
                if (testCase != null)
                    methodTestCases.Add(testCase);
            }
            else if (attribute.Name.ToString() == "TestCase")
            {
                var testCase = ExtractTestCase(attribute, testFixture, semanticModel);
                if (testCase != null)
                    methodTestCases.Add(testCase);
            }
            else if (attribute.Name.ToString() == "SetUp")
                testFixture.TestSetUpMethodName = GetAttributeMethod(attribute).Identifier.ValueText;
            else if (attribute.Name.ToString() == "TestFixtureSetUp")
                testFixture.TestFixtureSetUpMethodName = GetAttributeMethod(attribute).Identifier.ValueText;
            else if (attribute.Name.ToString() == "TearDown")
                testFixture.TestTearDownMethodName = GetAttributeMethod(attribute).Identifier.ValueText;
            else if (attribute.Name.ToString() == "TestFixtureTearDown")
                testFixture.TestFixtureTearDownMethodName = GetAttributeMethod(attribute).Identifier.ValueText;

            return methodTestCases;
        }
开发者ID:pzielinski86,项目名称:RuntimeTestCoverage,代码行数:28,代码来源:NUnitTestExtractor.cs


示例3: CompareAttributes

            private bool CompareAttributes(
                AttributeSyntax oldAttribute,
                AttributeSyntax newAttribute,
                SyntaxNode newNodeParent,
                CodeModelEventQueue eventQueue)
            {
                Debug.Assert(oldAttribute != null && newAttribute != null);

                bool same = true;

                if (!CompareNames(oldAttribute.Name, newAttribute.Name))
                {
                    EnqueueChangeEvent(newAttribute, newNodeParent, CodeModelEventType.Rename, eventQueue);
                    same = false;
                }

                // If arguments have changed enqueue a element changed (arguments changed) node
                if (!CompareAttributeArguments(oldAttribute.ArgumentList, newAttribute.ArgumentList))
                {
                    EnqueueChangeEvent(newAttribute, newNodeParent, CodeModelEventType.ArgChange, eventQueue);
                    same = false;
                }

                return same;
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:25,代码来源:CSharpCodeModelService.CodeModelEventCollector.cs


示例4: ReportDiagnostic

 private static void ReportDiagnostic(SyntaxNodeAnalysisContext context, AttributeSyntax matchingNode)
 {
     context.ReportDiagnostic(
         Diagnostic.Create(Rule,
             DetermineDiagnosticTarget(matchingNode).GetLocation(),
             GetClassName(matchingNode)));
 }
开发者ID:tiesmaster,项目名称:DebuggerStepThroughRemover,代码行数:7,代码来源:DiagnosticAnalyzer.cs


示例5: Property

 public Property(SemanticModel model, PropertyDeclarationSyntax syntax, AttributeSyntax attribute = null, AttributeSyntax classAttribute = null)
 {
     this.model = model;
     Syntax = syntax;
     propertyAttribute = attribute;
     ClassAttribute = classAttribute;
 }
开发者ID:ciniml,项目名称:NotifyPropertyChangedGenerator,代码行数:7,代码来源:Property.cs


示例6: DetermineDiagnosticTarget

 private static CSharpSyntaxNode DetermineDiagnosticTarget(AttributeSyntax attributeNode)
 {
     var attributesParentNode = (AttributeListSyntax)attributeNode.Parent;
     return ShouldKeepSquareBrackets(attributesParentNode)
         ? (CSharpSyntaxNode) attributeNode
         : attributesParentNode;
 }
开发者ID:tiesmaster,项目名称:DebuggerStepThroughRemover,代码行数:7,代码来源:DiagnosticAnalyzer.cs


示例7: GetAttribute

 internal CSharpAttributeData GetAttribute(AttributeSyntax node, NamedTypeSymbol boundAttributeType, out bool generatedDiagnostics)
 {
     var dummyDiagnosticBag = DiagnosticBag.GetInstance();
     var boundAttribute = base.GetAttribute(node, boundAttributeType, dummyDiagnosticBag);
     generatedDiagnostics = !dummyDiagnosticBag.IsEmptyWithoutResolution;
     dummyDiagnosticBag.Free();
     return boundAttribute;
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:8,代码来源:EarlyWellKnownAttributeBinder.cs


示例8: CreateSpeculative

        /// <summary>
        /// Creates a speculative AttributeSemanticModel that allows asking semantic questions about an attribute node that did not appear in the original source code.
        /// </summary>
        public static AttributeSemanticModel CreateSpeculative(SyntaxTreeSemanticModel parentSemanticModel, AttributeSyntax syntax, NamedTypeSymbol attributeType, AliasSymbol aliasOpt, Binder rootBinder, int position)
        {
            Debug.Assert(parentSemanticModel != null);
            Debug.Assert(rootBinder != null);
            Debug.Assert(rootBinder.IsSemanticModelBinder);

            return new AttributeSemanticModel(parentSemanticModel.Compilation, syntax, attributeType, aliasOpt, rootBinder, parentSemanticModel, position);
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:11,代码来源:AttributeSemanticModel.cs


示例9: AddJustificationToAttributeAsync

        private static Task<Document> AddJustificationToAttributeAsync(Document document, SyntaxNode syntaxRoot, AttributeSyntax attribute)
        {
            var attributeName = SyntaxFactory.IdentifierName(nameof(SuppressMessageAttribute.Justification));
            var newArgument = SyntaxFactory.AttributeArgument(SyntaxFactory.NameEquals(attributeName), null, GetNewAttributeValue());

            var newArgumentList = attribute.ArgumentList.AddArguments(newArgument);
            return Task.FromResult(document.WithSyntaxRoot(syntaxRoot.ReplaceNode(attribute.ArgumentList, newArgumentList)));
        }
开发者ID:JaRau,项目名称:StyleCopAnalyzers,代码行数:8,代码来源:SA1404CodeFixProvider.cs


示例10: TryGetAttributeExpression

        private bool TryGetAttributeExpression(SyntaxNode root, int position, ISyntaxFactsService syntaxFacts, SignatureHelpTriggerReason triggerReason, CancellationToken cancellationToken, out AttributeSyntax attribute)
        {
            if (!CommonSignatureHelpUtilities.TryGetSyntax(root, position, syntaxFacts, triggerReason, IsTriggerToken, IsArgumentListToken, cancellationToken, out attribute))
            {
                return false;
            }

            return attribute.ArgumentList != null;
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:9,代码来源:AttributeSignatureHelpProvider.cs


示例11: GetSourceSymbols

        private static Tuple<ITypeSymbol, ITypeSymbol> GetSourceSymbols(SemanticModel semModel, AttributeSyntax mapperAttribute)
        {
            var attrArguments = mapperAttribute.ArgumentList.Arguments;

            var toExpr = attrArguments[0].Expression as TypeOfExpressionSyntax;
            var toMetadataExpr = attrArguments.Count > 1 ? attrArguments[1].Expression as TypeOfExpressionSyntax : null;

            var to = semModel.GetSymbolInfo(toExpr?.Type).Symbol as ITypeSymbol;
            var toMetadata = toMetadataExpr == null ? null : semModel.GetSymbolInfo(toMetadataExpr.Type).Symbol as ITypeSymbol;

            return Tuple.Create(to, toMetadata);
        }
开发者ID:NCR-Engage,项目名称:MapEnforcerAnalyzer,代码行数:12,代码来源:DiagnosticAnalyzer.cs


示例12: IsSharpSwiftAttribute

        /// <summary>
        /// Detects whether an attribute is a certain SharpSwift-specific Attribute (like [ExportAs])
        /// </summary>
        /// <param name="attribute">The AttributeSyntax to check</param>
        /// <param name="expectingName">The attribute name you're looking for, or null to match all SharpSwift attributes</param>
        /// <returns>A boolean value representing whether it is or isn't the SharpSwift attribute</returns>
        private static bool IsSharpSwiftAttribute(AttributeSyntax attribute, string expectingName = null)
        {
            var symbol = Model.GetSymbolInfo(attribute.Name).Symbol;
            if (symbol == null) return false;

            var containingNamespace = symbol.ContainingSymbol.ContainingNamespace;

            var containingContainingNamespace = containingNamespace.ContainingNamespace;
            if (containingContainingNamespace == null) return false;

            return containingContainingNamespace.Name == "SharpSwift"
                   && containingNamespace.Name == "Attributes"
                   && (expectingName == null || symbol.ContainingSymbol.Name == expectingName);
        }
开发者ID:UIKit0,项目名称:SharpSwift,代码行数:20,代码来源:AttributeSyntaxParser.cs


示例13: AttributeSyntax

        public static string AttributeSyntax(AttributeSyntax attribute)
        {
            var output = "@" + SyntaxNode(attribute.Name).TrimEnd('!');

            if (IsSharpSwiftAttribute(attribute))
            {
                return "";
            }

            if (attribute.ArgumentList != null)
            {
                output += SyntaxNode(attribute.ArgumentList);
            }

            return output;
        }
开发者ID:UIKit0,项目名称:SharpSwift,代码行数:16,代码来源:AttributeSyntaxParser.cs


示例14: ExtractTest

        private static TestCase ExtractTest(AttributeSyntax attribute, TestFixtureDetails testFixture)
        {
            var methodDeclarationSyntax = GetAttributeMethod(attribute);
            bool isAsync = IsAsync(methodDeclarationSyntax);

            if (isAsync && IsVoid(methodDeclarationSyntax))
                return null;

            var testCase = new TestCase(testFixture)
            {
                SyntaxNode = methodDeclarationSyntax,
                IsAsync = isAsync,
                MethodName = methodDeclarationSyntax.Identifier.ValueText,
                Arguments = new string[0]
            };

            return testCase;
        }
开发者ID:pzielinski86,项目名称:RuntimeTestCoverage,代码行数:18,代码来源:NUnitTestExtractor.cs


示例15: Analyze

        private static IEnumerable<Diagnostic> Analyze(AttributeSyntax mapperAttribute, SemanticModel semModel)
        {
            if (mapperAttribute?.Name.ToString() != "Mapper")
            {
                yield break;
            }

            var symbol = semModel.GetSymbolInfo(mapperAttribute).Symbol as IMethodSymbol;
            if (!symbol?.ToString().StartsWith("NCR.Engage.RoslynAnalysis.MapperAttribute") ?? true)
            {
                yield break;
            }
            
            var sourceClass = GetSourceSymbols(semModel, mapperAttribute);

            if (sourceClass == null)
            {
                yield break;
            }

            var sourceProperties = GetSourceProperties(semModel, sourceClass.Item1, sourceClass.Item2);

            var mapperClass = GetMapperClass(semModel, mapperAttribute);

            if (mapperClass == null)
            {
                yield break;
            }

            foreach (var sourceProperty in sourceProperties)
            {
                if (IsPropertyMentioned(sourceProperty, mapperAttribute))
                {
                    continue;
                }

                var sourcePropertyName = $"'{sourceProperty.Type} {sourceClass.Item1.Name}.{sourceProperty.Name}'";
                var mapperClassName = $"'{mapperClass.Name}'";

                yield return Diagnostic.Create(PropertyNotMapped, mapperAttribute.GetLocation(), sourcePropertyName, mapperClassName);
            }
        }
开发者ID:NCR-Engage,项目名称:MapEnforcerAnalyzer,代码行数:42,代码来源:DiagnosticAnalyzer.cs


示例16: AttributeInspector

        public AttributeInspector(AttributeSyntax attributeSyntax, SemanticModel semanticModel)
        {
            _attributeName = attributeSyntax.Name.ToString();

            TypeInfo typeInfo = semanticModel.GetTypeInfo(attributeSyntax);
            ITypeSymbol typeSymbol = typeInfo.Type;
            _attributeQualifiedName = typeSymbol.ToString();

            var unamedArguments = new List<string>();
            var namedArguments = new Dictionary<string, string>();
            if (attributeSyntax.ArgumentList != null)
            {
                foreach (AttributeArgumentSyntax attributeArgumentSyntax in attributeSyntax.ArgumentList.Arguments)
                {
                    String argValue = attributeArgumentSyntax.Expression.ToString();
                    if (attributeArgumentSyntax.NameEquals != null)
                    {
                        string argName = attributeArgumentSyntax.NameEquals.Name.Identifier.Text;
                        namedArguments.Add(argName, argValue);
                    }
                    else
                    {
                        // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                        if (argValue.StartsWith("@"))
                        {
                            argValue = argValue.Remove(0, 1).Replace("\"\"", "\"");
                        }
                        else
                        {
                            argValue = Regex.Unescape(argValue);
                        }
                        argValue = argValue.Trim('"');
                        unamedArguments.Add(argValue);
                    }
                }
            }
            _unamedArguments = unamedArguments.AsReadOnly();
            _namedArguments = new ReadOnlyDictionary<string, string>(namedArguments);
        }
开发者ID:cdsalmons,项目名称:OrleansTemplates,代码行数:39,代码来源:AttributeInspector.cs


示例17: TryGetAttribute

        public static bool TryGetAttribute(this SyntaxList<AttributeListSyntax> attributeLists, KnownType attributeKnownType,
            SemanticModel semanticModel, out AttributeSyntax searchedAttribute)
        {
            searchedAttribute = null;

            if (!attributeLists.Any())
            {
                return false;
            }

            foreach (var attribute in attributeLists.SelectMany(attributeList => attributeList.Attributes))
            {
                var attributeType = semanticModel.GetTypeInfo(attribute).Type;

                if (attributeType.Is(attributeKnownType))
                {
                    searchedAttribute = attribute;
                    return true;
                }
            }

            return false;
        }
开发者ID:duncanpMS,项目名称:sonarlint-vs,代码行数:23,代码来源:SyntaxHelper.cs


示例18: Delete

        private Document Delete(Document document, AttributeSyntax node)
        {
            var attributeList = node.FirstAncestorOrSelf<AttributeListSyntax>();

            // If we don't have anything left, then just delete the whole attribute list.
            if (attributeList.Attributes.Count == 1)
            {
                var text = document.GetTextAsync(CancellationToken.None)
                                   .WaitAndGetResult_CodeModel(CancellationToken.None);

                // Note that we want to keep all leading trivia and delete all trailing trivia.
                var deletionStart = attributeList.SpanStart;
                var deletionEnd = attributeList.FullSpan.End;

                text = text.Replace(TextSpan.FromBounds(deletionStart, deletionEnd), string.Empty);

                return document.WithText(text);
            }
            else
            {
                var newAttributeList = attributeList.RemoveNode(node, SyntaxRemoveOptions.KeepNoTrivia);

                return document.ReplaceNodeAsync(attributeList, newAttributeList, CancellationToken.None)
                               .WaitAndGetResult_CodeModel(CancellationToken.None);
            }
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:26,代码来源:CSharpCodeModelService.cs


示例19: AddEventToEventQueueForAttributes

 private void AddEventToEventQueueForAttributes(AttributeSyntax attribute, SyntaxNode parent, Action<SyntaxNode, SyntaxNode> enqueueAddOrRemoveEvent)
 {
     if (parent is BaseFieldDeclarationSyntax)
     {
         foreach (var variableDeclarator in ((BaseFieldDeclarationSyntax)parent).Declaration.Variables)
         {
             enqueueAddOrRemoveEvent(attribute, variableDeclarator);
         }
     }
     else
     {
         enqueueAddOrRemoveEvent(attribute, parent);
     }
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:14,代码来源:CSharpCodeModelService.CodeModelEventCollector.cs


示例20: ChangeEventQueueForAttributes

 private static void ChangeEventQueueForAttributes(AttributeSyntax attribute, SyntaxNode parent, CodeModelEventType eventType, CodeModelEventQueue eventQueue)
 {
     if (parent is BaseFieldDeclarationSyntax)
     {
         foreach (var variableDeclarator in ((BaseFieldDeclarationSyntax)parent).Declaration.Variables)
         {
             eventQueue.EnqueueChangeEvent(attribute, variableDeclarator, eventType);
         }
     }
     else
     {
         eventQueue.EnqueueChangeEvent(attribute, parent, eventType);
     }
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:14,代码来源:CSharpCodeModelService.CodeModelEventCollector.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Syntax.BaseMethodDeclarationSyntax类代码示例发布时间:2022-05-26
下一篇:
C# Syntax.ArrowExpressionClauseSyntax类代码示例发布时间: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