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


C# Syntax.AttributeSyntax类代码示例

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


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


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