private static List <INamedTypeSymbol> GetClassSymbols(GeneratorExecutionContext context, SyntaxReceiver receiver)
        {
            var options     = (context.Compilation as CSharpCompilation).SyntaxTrees[0].Options as CSharpParseOptions;
            var compilation = context.Compilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(SourceText.From(cloneableAttributeText, Encoding.UTF8), options));

            var cloneableAttributeSymbol = compilation.GetTypeByMetadataName("Cloneable.CloneableAttribute") !;

            var classSymbols = new List <INamedTypeSymbol>();

            foreach (var clazz in receiver.CandidateClasses)
            {
                INamedTypeSymbol classSymbol = GetClassSymbol(compilation, clazz);
                if (HasAttribute(classSymbol, cloneableAttributeSymbol))
                {
                    classSymbols.Add(classSymbol);
                }
            }

            return(classSymbols);
        }
Example #2
0
 private static IEnumerable <INamedTypeSymbol> GetClassSymbols(Compilation compilation, SyntaxReceiver receiver)
 {
     return(receiver.CandidateClasses.Select(clazz => GetClassSymbol(compilation, clazz)));
 }