// ---

        public TypeCollector(IEnumerable <string> inputFiles, IEnumerable <string> inputDirs, IEnumerable <string> conditinalSymbols, bool disallowInternal, Utf8JsonGenerateArguments arguments)
        {
            var compilation = RoslynExtensions.GetCompilationFromProject(inputFiles, inputDirs,
                                                                         conditinalSymbols.Concat(new[] { CodegeneratorOnlyPreprocessorSymbol }).ToArray()
                                                                         );

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

            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.TypeKind == TypeKind.Class) || (x.TypeKind == TypeKind.Struct))
                          .ToArray();
        }
Beispiel #2
0
        internal static string InternalGenerate(GeneratorArguments arguments, Utf8JsonGenerateArguments arguments2)
        {
            var    collector    = new TypeCollector(arguments.InputFiles, arguments.InputDirectories, arguments.ConditionalSymbols, !arguments.AllowInternal, arguments2);
            string namespaceDot = arguments.GetNamespaceDot();

            (ObjectSerializationInfo[] objectInfo, GenericSerializationInfo[] genericInfo, EnumSerializationInfo[] enumInfo) = collector.Collect();

            FormatterTemplate[] objectFormatterTemplates = objectInfo
                                                           .GroupBy(x => x.Namespace)
                                                           .Select(x => new FormatterTemplate
            {
                Namespace = $"{namespaceDot}Formatters{((x.Key == null) ? "" : $".{x.Key}")}",
                objectSerializationInfos = x.ToArray(),
            })
Beispiel #3
0
 /// <summary>
 /// Generates formatters without resolver from the specified files and other arguments.
 /// </summary>
 /// <param name="inputFiles">The collection of input .cs files.</param>
 /// <param name="inputDirectories">The collection of directories with input .cs files.</param>
 /// <param name="conditionalSymbols">The collection of conditional compile symbols.</param>
 /// <param name="allowInternal">The value that determines whether to allow generate of the internal.</param>
 /// <param name="namespaceRoot">The root namespace for generated resolver and formatters.</param>
 /// <param name="arguments">The generate arguments to control additional generation behaviour.</param>
 public static string GenerateFormatters(IEnumerable <string> inputFiles, IEnumerable <string> inputDirectories, IEnumerable <string> conditionalSymbols = null, bool allowInternal = false, string namespaceRoot = "Utf8Json", Utf8JsonGenerateArguments arguments = default)
 {
     return(InternalGenerateFormatters(InternalGetArguments(inputFiles, inputDirectories, conditionalSymbols, allowInternal, "GeneratedResolver", namespaceRoot), arguments));
 }
Beispiel #4
0
 /// <summary>
 /// Generates formatters without resolver from the specified files and other arguments.
 /// </summary>
 /// <param name="inputFiles">The collection of input .cs files.</param>
 /// <param name="namespaceRoot">The root namespace for generated resolver and formatters.</param>
 /// <param name="arguments">The generate arguments to control additional generation behaviour.</param>
 public static string GenerateFormatters(IEnumerable <string> inputFiles, string namespaceRoot, Utf8JsonGenerateArguments arguments = default)
 {
     return(GenerateFormatters(inputFiles, null, null, false, namespaceRoot, arguments));
 }
Beispiel #5
0
 /// <summary>
 /// Generates resolver and formatters from the specified files and other arguments.
 /// </summary>
 /// <param name="inputFiles">The collection of input .cs files.</param>
 /// <param name="resolverName">The generated resolver name.</param>
 /// <param name="namespaceRoot">The root namespace for generated resolver and formatters.</param>
 /// <param name="arguments">The generate arguments to control additional generation behaviour.</param>
 public static string Generate(IEnumerable <string> inputFiles, string resolverName, string namespaceRoot, Utf8JsonGenerateArguments arguments = default)
 {
     return(Generate(inputFiles, null, null, false, resolverName, namespaceRoot, arguments));
 }