// ---

        public TypeCollector(string csProjPath, IEnumerable <string> conditinalSymbols, bool disallowInternal, bool isForceUseMap)
        {
            this.csProjPath = csProjPath;
            var compilation = RoslynExtensions.GetCompilationFromProject(csProjPath, conditinalSymbols.Concat(new[] { CodegeneratorOnlyPreprocessorSymbol }).ToArray()).GetAwaiter().GetResult();

            this.typeReferences   = new ReferenceSymbols(compilation);
            this.disallowInternal = disallowInternal;
            this.isForceUseMap    = isForceUseMap;

            targetTypes = compilation.GetNamedTypeSymbols()
                          .Where(x =>
            {
                if (x.DeclaredAccessibility == Accessibility.Public)
                {
                    return(true);
                }
                if (!disallowInternal)
                {
                    return(x.DeclaredAccessibility == Accessibility.Friend);
                }

                return(false);
            })
                          .Where(x =>
                                 ((x.TypeKind == TypeKind.Interface) && x.GetAttributes().Any(x2 => x2.AttributeClass == typeReferences.UnionAttribute)) ||
                                 ((x.TypeKind == TypeKind.Class) && x.GetAttributes().Any(x2 => x2.AttributeClass == typeReferences.MessagePackObjectAttribnute)) ||
                                 ((x.TypeKind == TypeKind.Struct) && x.GetAttributes().Any(x2 => x2.AttributeClass == typeReferences.MessagePackObjectAttribnute))
                                 )
                          .ToArray();
        }
Exemplo n.º 2
0
        public static async Task <TypeCollector> CreateCollector(string csProjPath, IEnumerable <string> conditinalSymbols, bool disallowInternal,
                                                                 bool isForceUseMap, string framework, bool quiet)
        {
            MSBuildLocator.RegisterDefaults();

            var compilation = await RoslynExtensions.GetCompilationFromProject(csProjPath, framework, quiet,
                                                                               conditinalSymbols.Union(new[] { CodegeneratorOnlyPreprocessorSymbol }).ToArray());

            return(new TypeCollector(csProjPath, disallowInternal, isForceUseMap, compilation));
        }
Exemplo n.º 3
0
        public TypeCollector(string csProjPath, IEnumerable <string> conditinalSymbols, bool disallowInternal, bool isForceUseMap)
        {
            this.csProjPath = csProjPath;
            Compilation compilation = RoslynExtensions.GetCompilationFromProject(csProjPath, conditinalSymbols.Concat(new[] { CodegeneratorOnlyPreprocessorSymbol }).ToArray()).GetAwaiter().GetResult();

            Diagnostic[] compilationErrors = compilation.GetDiagnostics().Where(x => x.Severity == DiagnosticSeverity.Error).ToArray();
            if (compilationErrors.Length != 0)
            {
                throw new InvalidOperationException($"detect compilation error:{string.Join("\n", compilationErrors.Select(x => x.ToString()))}");
            }

            this.typeReferences   = new ReferenceSymbols(compilation);
            this.disallowInternal = disallowInternal;
            this.isForceUseMap    = isForceUseMap;

            this.targetTypes = compilation.GetNamedTypeSymbols()
                               .Where(x =>
            {
                if (x.DeclaredAccessibility == Accessibility.Public)
                {
                    return(true);
                }

                if (!disallowInternal)
                {
                    return(x.DeclaredAccessibility == Accessibility.Friend);
                }

                return(false);
            })
                               .Where(x =>
                                      ((x.TypeKind == TypeKind.Interface) && x.GetAttributes().Any(x2 => x2.AttributeClass == this.typeReferences.UnionAttribute)) ||
                                      (x.TypeKind == TypeKind.Class && x.IsAbstract && x.GetAttributes().Any(x2 => x2.AttributeClass == this.typeReferences.UnionAttribute)) ||
                                      ((x.TypeKind == TypeKind.Class) && x.GetAttributes().Any(x2 => x2.AttributeClass == this.typeReferences.MessagePackObjectAttribute)) ||
                                      ((x.TypeKind == TypeKind.Struct) && x.GetAttributes().Any(x2 => x2.AttributeClass == this.typeReferences.MessagePackObjectAttribute)))
                               .ToArray();
        }
Exemplo n.º 4
0
        public static async Task <TypeCollector> CreateAsync(string csProjPath, IEnumerable <string> conditionalSymbols, bool disallowInternal, bool isForceUseMap)
        {
            Compilation compilation = await RoslynExtensions.GetCompilationFromProjectAsync(csProjPath, conditionalSymbols.Concat(new[] { CodegeneratorOnlyPreprocessorSymbol }).ToArray());

            return(new TypeCollector(csProjPath, compilation, conditionalSymbols, disallowInternal, isForceUseMap));
        }