當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。