コード例 #1
0
        /// <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);
        }
コード例 #2
0
 public static AttributeSyntax SelectAttributeOfType(SyntaxList<AttributeListSyntax> attributeLists, Type type, SemanticModel semanticModel)
 {
     return attributeLists.SelectMany(
         attributeListSyntax => attributeListSyntax.Attributes)
         .FirstOrDefault(
             attributeSyntax =>
                 new AttributeInspector(attributeSyntax, semanticModel).IsAttributeTypeOf(type));
 }
コード例 #3
0
 private bool HasAttribute(SyntaxList<AttributeListSyntax> attributeLists, string attributeName)
 {
     return attributeLists
         .SelectMany(al => al.Attributes)
         .Any(a => GetSimpleNameFromNode(a).Identifier.ValueText == attributeName);
 }