本文整理汇总了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;
}
示例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;
}
示例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;
}
示例4: ReportDiagnostic
private static void ReportDiagnostic(SyntaxNodeAnalysisContext context, AttributeSyntax matchingNode)
{
context.ReportDiagnostic(
Diagnostic.Create(Rule,
DetermineDiagnosticTarget(matchingNode).GetLocation(),
GetClassName(matchingNode)));
}
示例5: Property
public Property(SemanticModel model, PropertyDeclarationSyntax syntax, AttributeSyntax attribute = null, AttributeSyntax classAttribute = null)
{
this.model = model;
Syntax = syntax;
propertyAttribute = attribute;
ClassAttribute = classAttribute;
}
示例6: DetermineDiagnosticTarget
private static CSharpSyntaxNode DetermineDiagnosticTarget(AttributeSyntax attributeNode)
{
var attributesParentNode = (AttributeListSyntax)attributeNode.Parent;
return ShouldKeepSquareBrackets(attributesParentNode)
? (CSharpSyntaxNode) attributeNode
: attributesParentNode;
}
示例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;
}
示例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);
}
示例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)));
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}