protected static ProxyUnitSyntaxFactory CreateMainUnit(INamedTypeSymbol generator, Compilation compilation)
        {
            string qualifiedName = generator.GetQualifiedMetadataName() !;

            return(generator switch
            {
                _ when qualifiedName == typeof(DuckGenerator <,>).FullName => new DuckSyntaxFactory
                (
                    SymbolTypeInfo.CreateFrom(generator.TypeArguments[0], compilation),
                    SymbolTypeInfo.CreateFrom(generator.TypeArguments[1], compilation),
                    compilation.Assembly.Name,
                    OutputType.Unit,
                    SymbolAssemblyInfo.CreateFrom(generator.ContainingAssembly, compilation),
                    CreateReferenceCollector()
                ),
                _ when qualifiedName == typeof(ProxyGenerator <,>).FullName => new ProxySyntaxFactory
                (
                    SymbolTypeInfo.CreateFrom(generator.TypeArguments[0], compilation),
                    SymbolTypeInfo.CreateFrom(generator.TypeArguments[1], compilation),
                    compilation.Assembly.Name,
                    OutputType.Unit,
                    CreateReferenceCollector()
                ),
                _ => throw new InvalidOperationException
                (
                    string.Format
                    (
                        SGResources.Culture,
                        SGResources.NOT_A_GENERATOR,
                        generator
                    )
                )
            });
Пример #2
0
        public ITypeInfo?GetType(string fullName)
        {
            INamedTypeSymbol?type = UnderlyingSymbol.GetTypeByMetadataName(fullName);

            return(type is not null
                ? SymbolTypeInfo.CreateFrom(type, Compilation)
                : null);
        }
Пример #3
0
        private SymbolReturnParameterInfo(IMethodSymbol method, Compilation compilation)
        {
            Kind = method switch
            {
                _ when method.ReturnsByRefReadonly => ParameterKind.RefReadonly,
                              _ when method.ReturnsByRef => ParameterKind.Ref,
                              _ => ParameterKind.Out
            };

            Type = SymbolTypeInfo.CreateFrom(method.ReturnType, compilation);
        }
Пример #4
0
        public IEnumerable <SourceCode> GetSourceCodes(INamedTypeSymbol generator, GeneratorExecutionContext context)
        {
            ITypeSymbol
                iface  = generator.TypeArguments[0],
                target = generator.TypeArguments[1];

            Compilation compilation = context.Compilation;

            SourceCode result;

            try
            {
                IUnitSyntaxFactory unitSyntaxFactory = new DuckSyntaxFactory
                                                       (
                    SymbolTypeInfo.CreateFrom(iface, compilation),
                    SymbolTypeInfo.CreateFrom(target, compilation),
                    compilation.AssemblyName !,
                    OutputType.Unit,
                    SymbolTypeInfo.CreateFrom(generator, compilation)
                                                       );

                result = unitSyntaxFactory.GetSourceCode(context.CancellationToken);
            }
            catch (Exception e)
            {
                e.Data[nameof(iface)]  = iface.GetDebugString();
                e.Data[nameof(target)] = target.GetDebugString();

                throw;
            }

            //
            // "yield" nem szerepelhet "try" blokkban
            //

            yield return(result);
        }