Albatross.Reflection
8.0.0
Prefix Reserved
dotnet add package Albatross.Reflection --version 8.0.0
NuGet\Install-Package Albatross.Reflection -Version 8.0.0
<PackageReference Include="Albatross.Reflection" Version="8.0.0" />
<PackageVersion Include="Albatross.Reflection" Version="8.0.0" />
<PackageReference Include="Albatross.Reflection" />
paket add Albatross.Reflection --version 8.0.0
#r "nuget: Albatross.Reflection, 8.0.0"
#:package Albatross.Reflection@8.0.0
#addin nuget:?package=Albatross.Reflection&version=8.0.0
#tool nuget:?package=Albatross.Reflection&version=8.0.0
Albatross.Reflection
A powerful .NET Standard 2.1 utility library that simplifies reflection operations with a focus on type-safe, expression-based property access and manipulation. This library provides a comprehensive set of extension methods for working with types, assemblies, and object introspection in .NET applications.
Features
- Expression-based Property Access: Compile-time safe property operations using strongly-typed lambda expressions
- Type Inspection Utilities: Comprehensive type checking for nullable types, collections, tasks, and generics
- Assembly Type Discovery: Find and filter types within assemblies with powerful search capabilities
- Object Property Enumeration: Flatten complex objects and collections into key-value dictionaries
- Embedded Resource Management: Easy access to embedded resources with namespace resolution
- Nullable Type Handling: Specialized support for nullable value types and reference types
- Generic Type Operations: Utilities for working with generic types and their constraints
- Predicate Generation: Create LINQ predicates from property names and values
Prerequisites
- .NET Standard 2.1 or higher
Installation
Package Manager Console
Install-Package Albatross.Reflection
.NET CLI
dotnet add package Albatross.Reflection
PackageReference
<PackageReference Include="Albatross.Reflection" Version="7.5.10" />
Example Usage
Expression-based Property Access
using Albatross.Reflection;
public class Person
{
public string Name { get; set; }
public int? Age { get; set; }
public DateTime CreatedDate { get; set; }
}
// Get PropertyInfo using expression
var nameProperty = ExpressionExtensions.GetPropertyInfo<Person>(p => p.Name);
Console.WriteLine(nameProperty.Name); // Output: Name
// Set value only if not null
var person = new Person();
person.SetValueIfNotNull(p => p.Age, 25);
person.SetTextIfNotEmpty(p => p.Name, "John Doe");
// Create predicate expressions
var predicate = ExpressionExtensions.GetPredicate<Person>("Name", "John");
// Results in: person => person.Name == "John"
Type Inspection and Utilities
using Albatross.Reflection;
// Check nullable types
if (typeof(int?).GetNullableValueType(out Type valueType))
{
Console.WriteLine(valueType); // Output: System.Int32
}
// Check collection types
if (typeof(List<string>).GetCollectionItemType(out Type itemType))
{
Console.WriteLine(itemType); // Output: System.String
}
// Type compatibility checks
bool isDerived = typeof(string).IsDerived<object>(); // true
bool isNullable = typeof(int?).IsNullableValueType(); // true
Assembly Type Discovery
using Albatross.Reflection;
// Find all concrete classes implementing an interface
var services = Assembly.GetExecutingAssembly()
.GetConcreteClasses<IMyService>();
// Get embedded resource content
string content = typeof(MyClass).GetEmbeddedFile("config.json", "Settings");
Object Property Enumeration
using Albatross.Reflection;
var person = new Person
{
Name = "John",
Age = 30,
Addresses = new[] { "123 Main St", "456 Oak Ave" }
};
var properties = new Dictionary<string, object>();
Enumerations.Property(person, null, null, properties);
// Results in flattened structure:
// "Name" => "John"
// "Age" => 30
// "Addresses[0]" => "123 Main St"
// "Addresses[1]" => "456 Oak Ave"
Project Structure
├── Albatross.Reflection/ # Main library source code
│ ├── AssemblyExtensions.cs # Assembly type discovery utilities
│ ├── ExpressionExtensions.cs # Expression-based property operations
│ ├── TypeExtensions.cs # Type inspection and manipulation
│ ├── Enumerations.cs # Object property enumeration
│ ├── DefaultNamespaceAttribute.cs # Custom attribute for resources
│ └── README.md # Package documentation
├── Albatross.Reflection.Test/ # Unit tests
│ ├── ExpressionTest.cs # Expression extension tests
│ ├── Tests.cs # Core functionality tests
│ ├── TestEnumerations.cs # Property enumeration tests
│ └── ... # Additional test files
├── docs/ # Generated API documentation
├── README.md # This file
└── reflection.sln # Solution file
Building from Source
Clone the repository
git clone https://github.com/RushuiGuan/reflection.git cd reflection
Restore dependencies
dotnet restore
Build the solution
dotnet build
Run the application (if applicable)
dotnet run --project Albatross.Reflection
Running Tests
Execute all unit tests:
dotnet test
Run tests with detailed output:
dotnet test --verbosity normal
Run tests for specific project:
dotnet test Albatross.Reflection.Test/Albatross.Reflection.Test.csproj
Contributing
We welcome contributions! Please follow these steps:
- Fork the repository on GitHub
- Create a feature branch from
main
git checkout -b feature/your-feature-name
- Make your changes and add tests if applicable
- Ensure all tests pass
dotnet test
- Commit your changes with a clear commit message
git commit -m "Add feature: your feature description"
- Push to your fork and create a pull request
Code Style Guidelines
- Follow existing code formatting and naming conventions
- Add XML documentation comments for public APIs
- Include unit tests for new functionality
- Ensure backward compatibility when possible
License
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2019 Rushui Guan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Support
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
NuGet packages (8)
Showing the top 5 NuGet packages that depend on Albatross.Reflection:
Package | Downloads |
---|---|
Albatross.CodeGen
A customizable code generator engine with built in support for C# and TypeScript code generation |
|
Albatross.Serialization
Provides additional functionalities for serialization using System.Text.Json. |
|
Albatross.Messaging
A durable messaging library built on top of ZeroMQ |
|
Albatross.Text.Table
Convert collection of objects into a tabular string format with fluent interface.. Can print tabular data as a table or other formats using TextWriter. |
|
Albatross.Commands
InProcess command queue implementation |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
8.0.0 | 30 | 9/10/2025 |
8.0.0-23.main | 39 | 9/3/2025 |
8.0.0-22.main | 13 | 9/3/2025 |
7.5.9 | 277 | 2/27/2025 |
7.5.7 | 155 | 11/11/2024 |
7.5.6 | 72 | 11/8/2024 |
7.5.5 | 62 | 11/7/2024 |
7.5.4 | 62 | 11/7/2024 |
7.4.2 | 95 | 10/8/2024 |