Esempio n. 1
0
        public ReferenceSymbols(Compilation compilation)
        {
            Void                  = compilation.GetTypeByMetadataName("System.Void");
            TaskOfT               = compilation.GetTypeByMetadataName("System.Threading.Tasks.Task`1");
            Task                  = compilation.GetTypeByMetadataName("System.Threading.Tasks.Task");
            UnaryResult           = compilation.GetTypeByMetadataName("MagicOnion.UnaryResult`1");
            ClientStreamingResult = compilation.GetTypeByMetadataName("MagicOnion.ClientStreamingResult`2");
            DuplexStreamingResult = compilation.GetTypeByMetadataName("MagicOnion.DuplexStreamingResult`2");
            ServerStreamingResult = compilation.GetTypeByMetadataName("MagicOnion.ServerStreamingResult`1");
            GenerateDefineIf      = compilation.GetTypeByMetadataName("MagicOnion.GenerateDefineIfAttribute");
            IStreamingHubMarker   = compilation.GetTypeByMetadataName("MagicOnion.IStreamingHubMarker");
            IServiceMarker        = compilation.GetTypeByMetadataName("MagicOnion.IServiceMarker");
            IStreamingHub         = compilation.GetTypeByMetadataName("MagicOnion.IStreamingHub`2");
            MethodIdAttribute     = compilation.GetTypeByMetadataName("MagicOnion.Server.Hubs.MethodIdAttribute");

            Global = this;
        }
Esempio n. 2
0
        public ReferenceSymbols(Compilation compilation, Action <string> logger)
        {
            Void = compilation.GetTypeByMetadataName("System.Void");
            if (Void == null)
            {
                logger("failed to get metadata of System.Void.");
            }

            TaskOfT = compilation.GetTypeByMetadataName("System.Threading.Tasks.Task`1");
            if (TaskOfT == null)
            {
                logger("failed to get metadata of System.Threading.Tasks.Task`1.");
            }

            Task = compilation.GetTypeByMetadataName("System.Threading.Tasks.Task");
            if (Task == null)
            {
                logger("failed to get metadata of System.Threading.Tasks.Task.");
            }

            INamedTypeSymbol GetTypeSymbolOrThrow(string name)
            {
                var symbol = compilation.GetTypeByMetadataName(name);

                if (symbol == null)
                {
                    throw new InvalidOperationException("failed to get metadata of " + name);
                }
                return(symbol);
            }

            UnaryResult           = GetTypeSymbolOrThrow("MagicOnion.UnaryResult`1");
            ClientStreamingResult = GetTypeSymbolOrThrow("MagicOnion.ClientStreamingResult`2");
            DuplexStreamingResult = GetTypeSymbolOrThrow("MagicOnion.DuplexStreamingResult`2");
            ServerStreamingResult = GetTypeSymbolOrThrow("MagicOnion.ServerStreamingResult`1");
            IStreamingHubMarker   = GetTypeSymbolOrThrow("MagicOnion.IStreamingHubMarker");
            IServiceMarker        = GetTypeSymbolOrThrow("MagicOnion.IServiceMarker");
            IStreamingHub         = GetTypeSymbolOrThrow("MagicOnion.IStreamingHub`2");
            IService          = GetTypeSymbolOrThrow("MagicOnion.IService`1");
            MethodIdAttribute = GetTypeSymbolOrThrow("MagicOnion.Server.Hubs.MethodIdAttribute");

            Global = this;
        }
Esempio n. 3
0
        protected MethodCollector(string csProjPath, Compilation compilation)
        {
            this.csProjPath     = csProjPath;
            this.typeReferences = new ReferenceSymbols(compilation);

            var marker = compilation.GetTypeByMetadataName("MagicOnion.IServiceMarker");

            baseInterface = compilation.GetTypeByMetadataName("MagicOnion.IService`1");

            serviceTypes = compilation.GetNamedTypeSymbols()
                           .Where(t => t.AllInterfaces.Any(x => x == marker))
                           .ToArray();

            interfaces = serviceTypes
                         .Concat(serviceTypes.SelectMany(x => x.AllInterfaces))
                         .Distinct()
                         .Where(x => x != marker)
                         .Where(t => t != baseInterface)
                         .Where(x => !x.IsGenericType || x.ConstructedFrom != baseInterface)
                         .ToArray();
        }
Esempio n. 4
0
        public MethodCollector(string csProjPath, IEnumerable <string> conditinalSymbols)
        {
            this.csProjPath = csProjPath;
            var compilation = RoslynExtensions.GetCompilationFromProject(csProjPath, conditinalSymbols.ToArray()).GetAwaiter().GetResult();

            this.typeReferences = new ReferenceSymbols(compilation);

            var marker = compilation.GetTypeByMetadataName("MagicOnion.IServiceMarker");

            baseInterface = compilation.GetTypeByMetadataName("MagicOnion.IService`1");

            serviceTypes = compilation.GetNamedTypeSymbols()
                           .Where(t => t.AllInterfaces.Any(x => x == marker))
                           .ToArray();

            interfaces = serviceTypes
                         .Concat(serviceTypes.SelectMany(x => x.AllInterfaces))
                         .Distinct()
                         .Where(x => x != marker)
                         .Where(t => t != baseInterface)
                         .Where(x => !x.IsGenericType || x.ConstructedFrom != baseInterface)
                         .ToArray();
        }