Utility functions for common tasks like prime checking and file splitting, plus a custom Swagger attribute to enhance API documentation by adding descriptive info to Swagger UI summaries and descriptions.
License
—
Deps
1
Install Size
—
Vulns
✓ 0
Published
Jun 2, 2025
$ dotnet add package MyClassLibrary027.UtilitiesUtility functions for common tasks like prime checking and file splitting, plus a custom Swagger attribute to enhance API documentation by adding descriptive info to Swagger UI summaries and descriptions.
You can install the package from NuGet.org:
dotnet add package MyClassLibrary027.Utilities
Or, if you're using Visual Studio, you can search for the package in the NuGet Package Manager and install it from there.
Checks if a number is prime.
Utilities.CheckPrime(5); // Output: Prime Number
Utilities.CheckPrime(10); // Output: Not Prime Number
SplitFile(string filePath, int n = 10000)Splits a large file into smaller chunks, each with a maximum size of n characters. The default value of n is 10,000 characters.
filePath (string): The path to the file to be split.n (int, optional): The maximum size of each chunk (default is 10,000 characters).Utilities.SplitFile("path/to/largefile.txt", 5000);
This will split the file into chunks of 5,000 characters each and save them as separate files in the same directory.
Use SwaggerInfoAttribute on API methods to add custom info in Swagger UI. Register the filter:
services.AddSwaggerGen(c =>
{
// Other Swagger configuration...
c.OperationFilter<SwaggerInfoOperationFilter>();
});
Example:
[ApiController]
[Route("api/[controller]")]
public class SampleController : ControllerBase
{
[HttpGet("data")]
[SwaggerInfo("Requires Admin", Description = "Requires admin privileges.")]
public IActionResult GetSensitiveData() => Ok(new { Message = "Secret data" });
[HttpGet("public")]
[SwaggerInfo("Public Access")]
public IActionResult GetPublicData() => Ok(new { Message = "Public data" });
[HttpGet("status")]
[SwaggerInfo()]
public IActionResult GetStatus() => Ok(new { Message = "All systems operational" });
}
For the GetSensitiveData endpoint, Swagger UI summary will start with [Requires Admin] and the description panel will include your info text:
🔹 Info: This endpoint requires admin privileges and returns sensitive data.
For the GetPublicData endpoint, summary will start with [Public Access] and description stays unchanged (since Description was not provided).
For the GetStatus endpoint, the summary will display [Additional endpoint info] (the default), and the description will remain unchanged because no Description was provided.