| name | olive |
| description | Guidance for Olive productivity framework for .NET. USE FOR: common string extensions (null-safe operations, validation), collection utilities, date/time helpers, file name sanitization, fluent API helpers, reducing boilerplate in business applications. DO NOT USE FOR: full web frameworks (use ASP.NET Core), ORM functionality (use EF Core), UI frameworks, large-scale enterprise architecture.
|
| license | MIT |
| metadata | {"displayName":"Olive","author":"Tyler-R-Kendrick","version":"1.0.0"} |
| compatibility | ["claude","copilot","cursor"] |
| references | [{"title":"Olive Documentation","url":"https://geeksltd.github.io/Olive/"},{"title":"Olive GitHub Repository","url":"https://github.com/Geeksltd/Olive"},{"title":"Olive NuGet Package","url":"https://www.nuget.org/packages/Olive"}] |
Olive
Overview
Olive is a productivity framework for .NET developed by Geeks Ltd. It provides a comprehensive set of extension methods and utility classes that reduce boilerplate in business application development. The framework covers string manipulation, collection operations, date/time helpers, validation utilities, file handling, and more.
Olive's philosophy is to make common operations fluent and null-safe through extension methods. Instead of writing defensive null checks and multi-line utility methods, Olive provides concise, chainable operations that handle edge cases like null or empty inputs gracefully.
Install via NuGet:
dotnet add package Olive
String Extensions
Olive provides null-safe string operations that eliminate defensive coding patterns.
using Olive;
string? nullStr = null;
string result = nullStr.OrEmpty();
string trimmed = nullStr.TrimOrNull();
string defaulted = nullStr.Or("default");
bool isEmail = "user@example.com".IsValidEmail();
bool isUrl = "https://example.com".IsValidUrl();
bool hasValue = "hello".HasValue();
bool isEmpty = "".IsEmpty();
string safe = "my file (1).txt".ToSafeFileName();
string pascal = "hello world".ToPascalCase();
string camel = "hello world".ToCamelCase();
string truncated = "A very long string that needs truncating".Summarize(20);
string wrapped = "content".WithWrappers("<b>", "</b>");
bool contains = "Hello World".Contains(, caseSensitive: );
removed = .Remove();
replaced = .RemoveFrom();
Collection Extensions
Fluent collection operations with null safety and LINQ enhancements.
using System;
using System.Collections.Generic;
using System.Linq;
using Olive;
var items = new List<string> { "apple", "banana", "cherry", "date" };
List<string>? nullList = null;
var safe = nullList.OrEmpty();
string joined = items.ToString(", ");
bool hasAny = items.HasAny();
bool none = items.None();
var batches = items.ChunkBy(2);
var people = new[]
{
new { Name = "Alice", Dept = "IT" },
new { Name = "Bob", Dept = "IT" },
new { Name = "Carol", Dept = "HR" }
};
var distinctByDept = people.DistinctBy(p => p.Dept);
var extended = items.Concat("elderberry").ToList();
var without = items.Except("banana").ToList();
firstOrNull = items.FirstOrDefault();
Date and Time Helpers
Simplified date arithmetic and formatting extensions.
using System;
using Olive;
var now = DateTime.Now;
var tomorrow = now.AddDays(1);
var nextWeek = now.AddDays(7);
var specificDate = 15.June(2025);
var christmas = 25.December(2025);
var rounded = now.RoundToNearest(TimeSpan.FromMinutes(15));
bool isWeekend = now.IsWeekend();
bool isWeekday = now.IsWeekday();
bool isToday = specificDate.IsToday();
bool isBetween = now.IsBetween(
new DateTime(2025, 1, 1),
new DateTime(2025, 12, 31));
string relative = tomorrow.ToTimeDifferenceString();
string friendly = now.ToFriendlyDateString();
Type Conversion Extensions
Safe type conversion utilities that handle parsing with fallbacks.
using Olive;
int number = "42".To<int>();
int fallback = "not-a-number".To<int>();
double price = "19.99".To<double>();
int? nullable = "42".ToIntOrNull();
int? nullResult = "abc".ToIntOrNull();
double? dbl = "3.14".ToDoubleOrNull();
bool yes = "yes".ToBoolean();
bool one = "1".ToBoolean();
bool trueStr = "true".ToBoolean();
var status = "Active".To<Status>();
public enum Status { Active, Inactive, Pending }
IO and File Utilities
File system operations with safety and convenience methods.
using System.IO;
using Olive;
string safeName = "Report (Q1/2025).pdf".ToSafeFileName();
bool isPdf = "document.pdf".HasExtension(".pdf");
string noExt = "document.pdf".TrimEnd(".pdf");
var tempDir = Path.GetTempPath();
var appDir = Path.Combine(tempDir, "MyApp");
Directory.CreateDirectory(appDir);
string fullPath = new[] { tempDir, "MyApp", "data", "file.json" }
.Where(p => p.HasValue())
.Aggregate(Path.Combine);
Building Services with Olive Extensions
Integrate Olive utilities into service classes for cleaner business logic.
using System;
using System.Collections.Generic;
using System.Linq;
using Olive;
public class CustomerService
{
public IReadOnlyList<Customer> Search(string? query, string? department)
{
var customers = GetAllCustomers();
return customers
.Where(c => query.IsEmpty() || c.Name.Contains(query, caseSensitive: false))
.Where(c => department.IsEmpty() || c.Department.OrEmpty() == department)
.OrderBy(c => c.Name)
.ToList();
}
public string FormatCustomerSummary(Customer customer)
{
var parts = new[]
{
customer.Name,
customer.Email.HasValue() ? $"({customer.Email})" : null,
customer.Department.Or("Unassigned")
};
return parts.Where(p => p.HasValue()).ToString(" ");
}
public ValidationResult Validate(CustomerInput input)
{
var errors = new List<string>();
if (input.Name.IsEmpty())
errors.Add("Name is required");
if (input.Email.HasValue() && !input.Email.IsValidEmail())
errors.Add("Invalid email format");
return new ValidationResult(errors.None(), errors);
}
=> Enumerable.Empty<Customer>();
}
;
;
;
Olive vs Standard .NET
| Operation | Standard .NET | Olive |
|---|
| Null-safe string | str ?? string.Empty | str.OrEmpty() |
| Email validation | Regex or MailAddress parse | str.IsValidEmail() |
| Safe file name | Manual char replacement | str.ToSafeFileName() |
| Collection join | string.Join(", ", list) | list.ToString(", ") |
| Null-safe enumeration | list ?? Enumerable.Empty<T>() | list.OrEmpty() |
| Type conversion | int.TryParse(str, out var n) | str.To<int>() |
| Date check | date.DayOfWeek == ... | date.IsWeekend() |
Best Practices
- Use
OrEmpty() and Or("default") at API boundaries to convert nullable strings into safe values immediately, eliminating null-check boilerplate in downstream code.
- Prefer
.HasValue() over !string.IsNullOrWhiteSpace() for readability and consistency with Olive's fluent style throughout your codebase.
- Use
.IsValidEmail() for quick input validation but supplement with actual email delivery verification for critical flows, since format validation alone is insufficient.
- Apply
.ToSafeFileName() on all user-provided file names before writing to disk to prevent path traversal and invalid character errors.
- Use
.To<T>() for configuration parsing where missing or invalid values should silently default, and .ToIntOrNull() when you need to detect and report invalid input.
- Avoid mixing Olive extensions with standard LINQ carelessly -- pick a consistent style within each service class so the code reads uniformly.
- Use
.OrEmpty() on collection parameters at the start of methods to avoid null-reference exceptions when callers pass null collections.
- Prefer Olive's
.ToString(separator) on collections over string.Join() for consistency with the fluent extension method style.
- Keep Olive usage in application/service layers rather than in domain entities, since domain types should be self-validating and not depend on utility extensions.
- Pin the Olive NuGet version in your project to avoid breaking changes across minor versions, since the library evolves its API surface actively.