diff --git a/src/Pharmacist.Console/Program.cs b/src/Pharmacist.Console/Program.cs index 47f77f5..2d60e34 100644 --- a/src/Pharmacist.Console/Program.cs +++ b/src/Pharmacist.Console/Program.cs @@ -49,17 +49,26 @@ public static async Task Main(string[] args) { try { - string referenceAssembliesLocation; - if (!string.IsNullOrWhiteSpace(options.ReferenceAssemblies)) + var referenceAssembliesLocation = !string.IsNullOrWhiteSpace(options.ReferenceAssemblies) + ? options.ReferenceAssemblies! + : ReferenceLocator.GetReferenceLocation(); + + if (string.IsNullOrWhiteSpace(options.OutputPath)) { - referenceAssembliesLocation = options.ReferenceAssemblies; + throw new Exception("Invalid output path for the event generation."); } - else + + if (string.IsNullOrWhiteSpace(options.OutputPrefix)) + { + throw new Exception("Invalid output prefix for the event generation."); + } + + if (options.Platforms == null) { - referenceAssembliesLocation = ReferenceLocator.GetReferenceLocation(); + throw new Exception("Invalid platforms for the event generation."); } - await ObservablesForEventGenerator.ExtractEventsFromPlatforms(options.OutputPath, options.OutputPrefix, ".cs", referenceAssembliesLocation, options.Platforms).ConfigureAwait(false); + await ObservablesForEventGenerator.ExtractEventsFromPlatforms(options.OutputPath!, options.OutputPrefix!, ".cs", referenceAssembliesLocation, options.Platforms).ConfigureAwait(false); return ExitCode.Success; } @@ -75,9 +84,24 @@ public static async Task Main(string[] args) { using (var writer = new StreamWriter(Path.Combine(options.OutputPath, options.OutputPrefix + ".cs"))) { - await ObservablesForEventGenerator.WriteHeader(writer, options.Assemblies).ConfigureAwait(false); + if (options.Assemblies == null) + { + throw new Exception("Invalid specified assemblies for observable generation."); + } - await ObservablesForEventGenerator.ExtractEventsFromAssemblies(writer, options.Assemblies, options.SearchDirectories, options.TargetFramework).ConfigureAwait(false); + if (options.SearchDirectories == null) + { + throw new Exception("Invalid search directories specified for observable generation."); + } + + if (string.IsNullOrWhiteSpace(options.TargetFramework)) + { + throw new Exception("Invalid target framework for the event generation."); + } + + await ObservablesForEventGenerator.WriteHeader(writer, options.Assemblies!).ConfigureAwait(false); + + await ObservablesForEventGenerator.ExtractEventsFromAssemblies(writer, options.Assemblies!, options.SearchDirectories!, options.TargetFramework!).ConfigureAwait(false); } return ExitCode.Success; @@ -94,8 +118,13 @@ public static async Task Main(string[] args) { using (var writer = new StreamWriter(Path.Combine(options.OutputPath, options.OutputPrefix + ".cs"))) { + if (string.IsNullOrWhiteSpace(options.TargetFramework)) + { + throw new Exception("Invalid target framework for the event generation."); + } + var packageIdentity = new[] { new LibraryRange(options.NugetPackageName, VersionRange.Parse(options.NugetVersion), LibraryDependencyTarget.Package) }; - var nugetFramework = options.TargetFramework.ToFrameworks(); + var nugetFramework = options.TargetFramework!.ToFrameworks(); await ObservablesForEventGenerator.WriteHeader(writer, packageIdentity).ConfigureAwait(false); await ObservablesForEventGenerator.ExtractEventsFromNuGetPackages(writer, packageIdentity, nugetFramework, options.PackageFolder).ConfigureAwait(false); } diff --git a/src/Pharmacist.Core/Generation/ReflectionExtensions.cs b/src/Pharmacist.Core/Generation/ReflectionExtensions.cs index 84e5045..9699edc 100644 --- a/src/Pharmacist.Core/Generation/ReflectionExtensions.cs +++ b/src/Pharmacist.Core/Generation/ReflectionExtensions.cs @@ -5,7 +5,6 @@ using System.Collections.Concurrent; using System.Collections.Generic; -using System.Collections.Immutable; using System.Linq; using System.Text; @@ -21,7 +20,7 @@ namespace Pharmacist.Core.Generation /// internal static class ReflectionExtensions { - private static readonly ConcurrentDictionary>> _typeNameMapping = new ConcurrentDictionary>>(); + private static readonly ConcurrentDictionary>> _typeNameMapping = new ConcurrentDictionary>>(); private static readonly ConcurrentDictionary> _publicNonGenericTypeMapping = new ConcurrentDictionary>(); private static readonly ConcurrentDictionary> _publicEventsTypeMapping = new ConcurrentDictionary>(); @@ -57,9 +56,14 @@ public static IEnumerable GetPublicTypesWithStaticEvents(this I /// The name of the items. public static IReadOnlyCollection GetReferenceTypeDefinitionsWithFullName(this ICompilation compilation, string name) { - var map = _typeNameMapping.GetOrAdd(compilation, comp => comp.ReferencedModules.Concat(compilation.Modules).SelectMany(x => x.TypeDefinitions).GroupBy(x => x.ReflectionName).ToImmutableDictionary(x => x.Key, x => x.ToImmutableList())); + var map = _typeNameMapping.GetOrAdd(compilation, comp => comp.ReferencedModules.Concat(compilation.Modules).SelectMany(x => x.TypeDefinitions).GroupBy(x => x.ReflectionName).ToDictionary(x => x.Key, x => x.ToList())); - return map.GetValueOrDefault(name) ?? ImmutableList.Empty; + if (map.TryGetValue(name, out var value)) + { + return value; + } + + return Array.Empty(); } /// diff --git a/src/Pharmacist.Core/Pharmacist.Core.csproj b/src/Pharmacist.Core/Pharmacist.Core.csproj index 8ec540b..67c0fe3 100644 --- a/src/Pharmacist.Core/Pharmacist.Core.csproj +++ b/src/Pharmacist.Core/Pharmacist.Core.csproj @@ -18,7 +18,6 @@ -