diff --git a/src/PublicApiGenerator/ApiGenerator.cs b/src/PublicApiGenerator/ApiGenerator.cs
index 97bcefa..178aa32 100644
--- a/src/PublicApiGenerator/ApiGenerator.cs
+++ b/src/PublicApiGenerator/ApiGenerator.cs
@@ -18,10 +18,14 @@ namespace PublicApiGenerator
{
public static class ApiGenerator
{
- public static string GeneratePublicApi(Assembly assembly, ApiGeneratorOptions? options = null)
+ ///
+ /// Generates a public API from the specified assembly.
+ ///
+ /// The assembly to generate an API from.
+ /// The options to control the API output.
+ /// The API output.
+ public static string GeneratePublicApi(this Assembly assembly, ApiGeneratorOptions? options = null)
{
- if (assembly is null) throw new ArgumentNullException(nameof(assembly));
-
options ??= new ApiGeneratorOptions();
var attributeFilter = new AttributeFilter(options.ExcludeAttributes);
@@ -49,7 +53,36 @@ public static string GeneratePublicApi(Assembly assembly, ApiGeneratorOptions? o
}
}
- [Obsolete("Use `GeneratePublicApi(Assembly assembly, ApiGeneratorOptions? options = null)` instead. Will be removed in the next major.")]
+ ///
+ /// Generates a public API from the specified types.
+ ///
+ /// The types to generate an API from.
+ /// The options to control the API output.
+ /// This method assumes all the types belong to the same assembly. The assembly of the first type types[0].Assembly
is used.
+ /// The API output.
+ public static string GeneratePublicApi(this Type[] types, ApiGeneratorOptions? options = null)
+ {
+ if (types.Length == 0)
+ {
+ return string.Empty;
+ }
+ (options ??= new ApiGeneratorOptions()).IncludeTypes = types;
+ return types[0].Assembly.GeneratePublicApi(options);
+ }
+
+ ///
+ /// Generates a public API from the specified type.
+ ///
+ /// The type to generate an API from.
+ /// The options to control the API output.
+ /// The API output.
+ public static string GeneratePublicApi(this Type type, ApiGeneratorOptions? options = null)
+ {
+ (options ??= new ApiGeneratorOptions()).IncludeTypes = new Type[] { type };
+ return type.Assembly.GeneratePublicApi(options);
+ }
+
+ [Obsolete("Use `GeneratePublicApi(this Assembly assembly, ApiGeneratorOptions? options = null)` instead. Will be removed in the next major.")]
public static string GeneratePublicApi(Assembly assembly, Type[]? includeTypes = null, bool shouldIncludeAssemblyAttributes = true, string[]? whitelistedNamespacePrefixes = null, string[]? excludeAttributes = null)
{
var options = new ApiGeneratorOptions
diff --git a/src/PublicApiGeneratorTests/ApiGeneratorTestsBase.cs b/src/PublicApiGeneratorTests/ApiGeneratorTestsBase.cs
index e1b3122..5f5ee90 100644
--- a/src/PublicApiGeneratorTests/ApiGeneratorTestsBase.cs
+++ b/src/PublicApiGeneratorTests/ApiGeneratorTestsBase.cs
@@ -32,7 +32,7 @@ private static void AssertPublicApi(Assembly assembly, string expectedOutput, A
{
options ??= new DefaultApiGeneratorOptions();
- var actualOutput = ApiGenerator.GeneratePublicApi(assembly, options);
+ var actualOutput = assembly.GeneratePublicApi(options);
actualOutput = StripEmptyLines.Replace(actualOutput, string.Empty);
Assert.Equal(expectedOutput, actualOutput, ignoreCase: false, ignoreLineEndingDifferences: true,
ignoreWhiteSpaceDifferences: true);