Skip to main content
.NETStandard2.0

This project provides a set of fluent APIs to simplify the handling of structs in .NET. You spent too much time centering stuff with X1 + ((Width1 - Width2) / 2).

Published
Nov 4, 2026
20d ago
Total Downloads
837
837

Install

dotnet add package FluentStructures --version 1.0.2
ProductVersions
.NET Standard
netstandard2.0

README

FluentStructures

This project provides a set of fluent APIs to simplify the handling of structs in .NET.

You spent too much time centering stuff with X1 + ((Width1 - Width2) / 2).

Use cases

Setting properties with With...

The extensions methods With... and WithAdditional... provide expressive ways to get a copy of a struct with absolute values or relative value additions.

//   (p1)───────────────────────────────(p2)
//                                       β”‚
//                                       β”‚
//                                       β”‚   +50px
//                                       β”‚
//                                       β”‚
//                         (p4)─────────(p3)
//                               -33px

// traditional
var p1 = new Point(10, 10);
var p2 = new Point(100, p1.Y);
var p3 = new Point(p2.X, p2.Y + 50);
var p4 = new Point(p3.X - 33, p3.Y);

// fluent
p1 = new Point(10, 10);
p2 = p1.WithX(100);             // absolute
p3 = p2.WithAdditionalY(50);    // relative
p4 = p3.WithAdditionalX(-33);

Emphasizing the intent over simple calculations

This project does not only add fluent extensions to set properties, it also comes with tailored extension methods to emphasize the intent when working with structs. Simple and expressive code instead of calculations that have to be thought through every time they get rediscovered.

The Rectangle (and RectangleF) gets an extension method to find its landmarks (corner stones or the center point) easily ...

//    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
//    β”‚                                  β”‚
//    β”‚                                  β”‚
//    β”‚              (p1)                β”‚
//    β”‚                                  β”‚
//    β”‚                                  β”‚
//    └──────────────(p2)β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜


// traditional
var p1 = new Point(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2));
var p2 = new Point(rect.Left + (rect.Width / 2), rect.Bottom);

// fluent
p1 = rect.GetLandmark(ContentAlignment.MiddleCenter);
p2 = rect.GetLandmark(ContentAlignment.BottomCenter);

... while Embed() takes another rectangle or size to be embedded and returns the corresponding bounds depending on the defined alignment.

//    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
//    β”‚                                  β”‚
//    β”‚                         β”Œβ”€β”€β”€β”€β”   β”‚
//    β”‚                         β”‚    β”‚   β”‚   <-- 10px padding
//    β”‚                         β””β”€β”€β”€β”€β”˜   β”‚
//    β”‚                                  β”‚
//    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

var cellBounds = new Rectangle(100, 100, 300, 150);
var userImage = new Bitmap(30, 30);

// traditional
var userImageBounds = new Rectangle(
    cellBounds.Right - userImage.Width - 10,
    cellBounds.Y + ((cellBounds.Height - userImage.Height) / 2),
    userImage.Width,
    userImage.Height);

// fluent
userImageBounds = cellBounds
    .Embed(userImage.Size, ContentAlignment.MiddleRight)
    .WithAdditionalLeft(-10);

Scope

This project currently adds extension methods to structs of the System.Drawing namespace like Color, Point, Rectangle and so on. More structs might be added over time, pull requests always welcome.


Model icons created by Flowicon on Flaticon

Changes from Previous Version

No structural changes between v1.0.1 and v1.0.2.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

No SPDX license expression is published. Review the license text and your organisation's policy before redistribution.Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.