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; }
private static bool HasThreadStaticAttribute(SyntaxList<AttributeListSyntax> attributeLists, SemanticModel semanticModel) { if (!attributeLists.Any()) { return false; } return attributeLists.Any(attributeList => attributeList.Attributes.Any(attribute => semanticModel.GetTypeInfo(attribute).Type.Is(KnownType.System_ThreadStaticAttribute))); }
private static bool HasThreadStaticAttribute(SyntaxList<AttributeListSyntax> attributeLists, SemanticModel semanticModel) { if (!attributeLists.Any()) { return false; } return attributeLists .Any(attributeList => attributeList.Attributes .Select(attribute => semanticModel.GetTypeInfo(attribute).Type) .Any(attributeType => attributeType != null && attributeType.ToDisplayString() == ThreadStaticAttributeName)); }
/// <summary> /// Parses an attribute /// </summary> /// <param name="attributeLists">The list of attributes to parse</param> /// <param name="separator">The separator to use between attributes</param> /// <returns>A tuple where the first value is the Swift attributes and the second contains the value of an ExportAttribute</returns> private static Tuple<string, string> ParseAttributes(SyntaxList<AttributeListSyntax> attributeLists, string separator = " ") { if (!attributeLists.Any()) return new Tuple<string, string>("", null); var output = ""; string exportAs = null; foreach (var attribute in attributeLists.SelectMany(attrList => attrList.Attributes)) { if (IsSharpSwiftAttribute(attribute, "ExportAttribute")) { exportAs = SyntaxNode(attribute.ArgumentList.Arguments[0].Expression).Trim().Trim('"'); continue; } output += SyntaxNode(attribute) + separator; } return new Tuple<string, string>(output, exportAs); }
private static bool HasAttributes(SyntaxList<AccessorDeclarationSyntax> accessors) { return accessors.Any(a => a.AttributeLists.Any()); }
private static StatementSyntax caseStatement(SyntaxList<StatementSyntax> statements) { Debug.Assert(statements.Any()); if (statements.Count == 1) return statements.First(); return CSharp.Block(statements); }
private static SyntaxList<TypeParameterConstraintClauseSyntax> GetNewConstraintClause( SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses, string typeParameterName) { if (!constraintClauses.Any()) { return constraintClauses; } var constraintList = SyntaxFactory.List<TypeParameterConstraintClauseSyntax>(); foreach (var constraint in constraintClauses) { var currentConstraint = constraint; if (constraint.Name.Identifier.ValueText == typeParameterName) { currentConstraint = currentConstraint .WithConstraints( currentConstraint.Constraints.Insert(0, SyntaxFactory.ClassOrStructConstraint(SyntaxKind.ClassConstraint))) .WithAdditionalAnnotations(Formatter.Annotation); } constraintList = constraintList.Add(currentConstraint); } return constraintList; }