Astronomy calculations for HVO projects — solar/lunar position, sunrise/sunset, twilight, moon phase, planetary ephemeris, and coordinate transforms.
$ dotnet add package HVO.AstronomyShared .NET utilities and functional patterns used across all HVO projects.
| Package | Target | Description |
|---|---|---|
| HVO.Core | netstandard2.0 | Result<T>, Option<T>, OneOf<T1..T4>, discriminated unions, guard clauses, extensions |
| HVO.Core.SourceGenerators | netstandard2.0 | Roslyn source generators (e.g., [NamedOneOf] attribute) |
dotnet add package HVO.Core
dotnet add package HVO.Core.SourceGenerators
using HVO.Core.Results;
public Result<Customer> GetCustomer(int id)
{
try
{
var customer = _repository.Find(id);
return customer != null
? Result<Customer>.Success(customer)
: Result<Customer>.Failure(new NotFoundException($"Customer {id} not found"));
}
catch (Exception ex)
{
return ex; // Implicit conversion to failure
}
}
// Usage
var result = GetCustomer(42);
var output = result.Match(
success: c => $"Found: {c.Name}",
failure: ex => $"Error: {ex.Message}");
using HVO.Core.Results;
public enum OrderError { NotFound, InvalidAmount, Unauthorized }
public Result<Order, OrderError> ValidateOrder(OrderRequest request)
{
if (request.Amount <= 0)
return OrderError.InvalidAmount; // Implicit conversion
return Result<Order, OrderError>.Success(new Order(request));
}
using HVO.Core.Options;
public Option<string> GetSetting(string key)
{
return _config.TryGetValue(key, out var value)
? new Option<string>(value)
: Option<string>.None();
}
// Usage
var setting = GetSetting("timeout");
var value = setting.GetValueOrDefault("30"); // Returns "30" if None
using HVO.Core.OneOf;
OneOf<int, string> result = 42;
var output = result.Match(
i => $"Got integer: {i}",
s => $"Got string: {s}");
// output: "Got integer: 42"
using HVO.Core.Utilities;
// Guard: validates input parameters (throws ArgumentException)
public void Process(string name, int count)
{
Guard.AgainstNullOrWhiteSpace(name);
Guard.AgainstNegativeOrZero(count, 0);
}
// Ensure: asserts internal state (throws InvalidOperationException)
public void Execute()
{
Ensure.That(_isInitialized, "Service must be initialized");
Ensure.NotNull(_connection, "Connection not established");
}
using HVO.Core.Extensions;
// String extensions
"hello world".ToTitleCase(); // "Hello World"
"Hello World Test".RemoveWhitespace(); // "HelloWorldTest"
"Second".ToEnum<MyEnum>(); // MyEnum.Second
// Collection extensions
new[] { 1, 2, 3 }.ForEach(x => Console.Write(x));
items.DistinctBy(x => x.Id);
items.Shuffle();
// Enum extensions
MyEnum.Value.GetDescription(); // Returns [Description] attribute value
HVO.Core targets .NET Standard 2.0 for maximum compatibility:
dotnet build
dotnet test
| Document | Description |
|---|---|
| CONTRIBUTING.md | PR workflow, coding standards, branch naming |
| CHANGELOG.md | Release history and notable changes |
See CONTRIBUTING.md for PR workflow, coding standards, and how to run tests locally.
MIT