Exemple #1
0
 public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node)
 {
     if (node.HasAttribute <SlideAttribute>())
     {
         var arguments =
             node.GetAttributes <SlideAttribute>()
             .Select(a => new { title = a.GetArgument(0), id = a.GetArgument(1) })
             .Single();
         Title = arguments.title;
         Id    = Guid.Parse(arguments.id);
     }
     return(VisitMemberDeclaration(node, base.VisitClassDeclaration(node)));
 }
Exemple #2
0
        private static string[] GetExports(this ClassDeclarationSyntax classDeclaration)
        {
            var expressions = classDeclaration.GetAttributes("Export")
                              .Concat(classDeclaration.GetAttributes("InheritedExport"))
                              .SelectMany(a => a.ArgumentList.Arguments)
                              .Select(a => a.Expression)
                              .OfType <TypeOfExpressionSyntax>();

            var found     = new Queue <string>(allPlugins.Length);
            var typeNames = expressions.Select(e => e.Type.ToString());

            foreach (var t in typeNames)
            {
                foreach (var i in allPlugins)
                {
                    if (t == i || t == $"Grabacr07.KanColleViewer.Composition.{i}")
                    {
                        found.Enqueue(i);
                    }
                }
            }
            return(found.ToArray());
        }
Exemple #3
0
 public static string GetGuidMetadataValue(this ClassDeclarationSyntax classDeclaration)
 {
     return(classDeclaration.GetAttributes("ExportMetadata")
            .FirstOrDefault(a => a.ArgumentList.Arguments[0].ToString() == $"\"{nameof(IPluginGuid.Guid)}\"")
            ?.ArgumentList.Arguments[1].ToString().Replace("\"", ""));
 }
Exemple #4
0
 private static string[] GetMetadatas(this ClassDeclarationSyntax classDeclaration)
 {
     return(classDeclaration.GetAttributes("ExportMetadata")
            .Select(a => a.ArgumentList.Arguments.First().ToString().Replace("\"", ""))
            .ToArray());
 }
Exemple #5
0
 public static IEnumerable <TAttribute> GetAttributes <TAttribute>(this ClassDeclarationSyntax classDeclarationSyntax)
     where TAttribute : Attribute
 {
     return(classDeclarationSyntax.GetAttributes(typeof(TAttribute)).OfType <TAttribute>());
 }
Exemple #6
0
 public static AttributeSyntax GetAttribute(this ClassDeclarationSyntax classDeclaration, string attributeName)
 => classDeclaration.GetAttributes(attributeName).Single();