com.IvanMurzak.ReflectorNet
1.0.4
dotnet add package com.IvanMurzak.ReflectorNet --version 1.0.4
NuGet\Install-Package com.IvanMurzak.ReflectorNet -Version 1.0.4
<PackageReference Include="com.IvanMurzak.ReflectorNet" Version="1.0.4" />
<PackageVersion Include="com.IvanMurzak.ReflectorNet" Version="1.0.4" />
<PackageReference Include="com.IvanMurzak.ReflectorNet" />
paket add com.IvanMurzak.ReflectorNet --version 1.0.4
#r "nuget: com.IvanMurzak.ReflectorNet, 1.0.4"
#:package com.IvanMurzak.ReflectorNet@1.0.4
#addin nuget:?package=com.IvanMurzak.ReflectorNet&version=1.0.4
#tool nuget:?package=com.IvanMurzak.ReflectorNet&version=1.0.4
ReflectorNet
ReflectorNet is an advanced .NET reflection toolkit specifically designed for AI-driven scenarios. It provides sophisticated reflection-based serialization, deserialization, population, and method invocation capabilities that enable seamless integration between AI systems and .NET applications.
Main Features
๐ Intelligent Method Discovery & Invocation
Discover and invoke methods at runtime using powerful fuzzy matching algorithms. Supports partial method names, parameter matching, and configurable similarity scoring (0-6 levels) for robust method resolution even with incomplete information.
var reflector = new Reflector();
var methods = reflector.FindMethod(new MethodRef
{
TypeName = "TestClass",
MethodName = "Process", // Partial match supported
Namespace = "MyApp.Services"
}, methodNameMatchLevel: 3); // Flexible matching
๐ Advanced Reflection-Based Serialization
Convert complex .NET objects to type-preserving, AI-friendly serialized formats. Supports nested objects, collections, custom types, and maintains full type information for accurate reconstruction.
var reflector = new Reflector();
var serialized = reflector.Serialize(complexObject, recursive: true);
var restored = reflector.Deserialize<MyClass>(serialized);
๐ง Smart Instance Creation & Population
Intelligently create instances with automatic constructor resolution, dependency handling, and in-place object population from serialized data.
var instance = reflector.CreateInstance<MyClass>();
reflector.TryPopulate(ref instance, serializedData);
๐ Advanced Object Population System
ReflectorNet provides sophisticated in-place object population capabilities that enable seamless data transfer from serialized formats to existing object instances. The population system offers precise control over which members are populated and comprehensive error handling.
Key Population Features
๐ฏ In-Place Population
// Populate existing objects without replacement
var existingObject = new MyClass { Id = 1 };
var serializedData = reflector.Serialize(sourceObject);
var success = reflector.TryPopulate(ref existingObject, serializedData);
๐ Selective Member Population
// Control which fields and properties are populated
reflector.TryPopulate(
ref targetObject,
serializedData,
flags: BindingFlags.Public | BindingFlags.Instance // Only public members
);
๐ Hierarchical Population
// Population with nested object support and depth tracking
var stringBuilder = new StringBuilder();
var success = reflector.TryPopulate(
ref complexObject,
serializedData,
depth: 0,
stringBuilder: stringBuilder // Collect detailed operation logs
);
๐ก๏ธ Type-Safe Population with Validation
// Explicit type validation during population
reflector.TryPopulate(
ref targetObject,
serializedData,
fallbackObjType: typeof(MyExpectedType) // Ensure type compatibility
);
Population Workflow
- Type Resolution: Automatically resolves target type from serialized data or explicit parameters
- Compatibility Validation: Ensures object compatibility before attempting population
- Converter Selection: Uses the Chain of Responsibility pattern to select optimal converters
- Member Population: Populates fields and properties based on BindingFlags
- Error Collection: Accumulates detailed error messages with hierarchical indentation
- Success Reporting: Returns comprehensive success/failure status
Advanced Population Scenarios
๐ง Partial Object Updates
// Update only specific fields of existing objects
var partialData = new SerializedMember
{
fields = new List<SerializedMember>
{
new SerializedMember { name = "Name", valueString = "Updated Name" },
new SerializedMember { name = "Status", valueString = "Active" }
}
};
reflector.TryPopulate(ref existingObject, partialData);
๐ Batch Population with Error Tracking
// Populate multiple objects with consolidated error reporting
var errorLog = new StringBuilder();
var overallSuccess = true;
foreach (var (target, data) in objectDataPairs)
{
var success = reflector.TryPopulate(
ref target,
data,
stringBuilder: errorLog
);
overallSuccess &= success;
}
if (!overallSuccess)
Console.WriteLine($"Population errors:\n{errorLog}");
๐ State Synchronization
// Synchronize object state from external sources
public void SynchronizeFromJson(ref MyClass target, string jsonData)
{
var serialized = JsonSerializer.Deserialize<SerializedMember>(jsonData);
var success = reflector.TryPopulate(ref target, serialized);
if (!success)
throw new InvalidOperationException("Failed to synchronize object state");
}
๐งช Configuration Management
// Apply configuration updates to existing settings objects
var configObject = LoadCurrentConfiguration();
var updateData = reflector.Serialize(newConfigurationData);
// Apply updates while preserving existing values for unspecified fields
reflector.TryPopulate(ref configObject, updateData);
SaveConfiguration(configObject);
๐ Automatic JSON Schema Generation
Generate comprehensive JSON Schema documentation for methods and types, enabling seamless integration with OpenAPI, code generation tools, and AI systems.
var methodSchema = reflector.GetArgumentsSchema(methodInfo);
var typeSchema = reflector.GetSchema<MyClass>();
๐ Extensible Converter System
Register custom converters using a flexible chain-of-responsibility pattern. Easily extend serialization behavior for any .NET type with specialized logic.
reflector.Convertors.Add(new MyCustomConverter<SpecialType>());
๐ Comprehensive Type Introspection
Analyze and discover serializable fields, properties, and type metadata with advanced filtering and analysis capabilities.
var fields = reflector.GetSerializableFields(typeof(MyClass));
var properties = reflector.GetSerializableProperties(typeof(MyClass));
๐ก๏ธ Robust Error Handling & Logging
Integrated Microsoft.Extensions.Logging support with hierarchical error reporting, detailed diagnostics, and comprehensive validation.
๐ค AI & Integration Ready
Optimized for AI scenarios with JSON Schema support, dynamic method binding, and cross-language serialization compatibility.
Architecture Overview
ReflectorNet employs a sophisticated Chain of Responsibility pattern with multiple specialized converters:
- PrimitiveReflectionConvertor: Handles built-in .NET types (int, string, DateTime, etc.)
- GenericReflectionConvertor: Manages custom classes and structs
- ArrayReflectionConvertor: Specialized handling for arrays and collections
- Custom Converters: Extensible system for specialized type handling
Advanced Use Cases
๐ฅ Dynamic Scripting & Automation
// AI can discover and invoke methods dynamically
var result = reflector.MethodCall(new MethodRef
{
TypeName = "Calculator",
MethodName = "Add"
}, inputParameters: parameters);
๐ API Documentation Generation
// Generate comprehensive API documentation
var schema = reflector.GetArgumentsSchema(methodInfo);
// Use schema for OpenAPI/Swagger generation
๐งช Advanced Testing Frameworks
// Dynamic test case generation and execution
var testMethods = reflector.FindMethod(new MethodRef
{
MethodName = "Test",
TypeName = "TestClass"
}, methodNameMatchLevel: 2);
๐ Configuration & State Management
// Serialize complex application state
var appState = reflector.Serialize(applicationState);
// Later restore with exact type preservation
var restored = reflector.Deserialize(appState);
Getting Started
Installation
dotnet add package com.IvanMurzak.ReflectorNet
Basic Usage
using com.IvanMurzak.ReflectorNet;
var reflector = new Reflector();
// Serialize any object
var serialized = reflector.Serialize(myObject);
// Deserialize with type safety
var restored = reflector.Deserialize<MyClass>(serialized);
// Discover methods dynamically
var methods = reflector.FindMethod(new MethodRef
{
TypeName = "MyClass",
MethodName = "MyMethod"
});
// Generate JSON Schema
var schema = reflector.GetSchema<MyClass>();
Core API Reference
Primary Methods
Serialization & Deserialization
Serialize(...)
- Convert objects to type-preserving serialized representations with support for complex nested structuresDeserialize<T>(...)
- Reconstruct strongly-typed objects from serialized data with intelligent type resolutionDeserialize(...)
- Deserialize to specific types with flexible fallback type support
Object Management
CreateInstance<T>()
- Intelligent instance creation with automatic constructor resolution and dependency handlingCreateInstance(Type)
- Create instances of specific types with support for complex constructorsTryPopulate(...)
- Advanced in-place object population from serialized data with comprehensive validation and error handling- Supports selective member population with BindingFlags control
- Hierarchical population with depth tracking and detailed error reporting
- Type-safe validation and compatibility checking
- Non-destructive updates that preserve existing object structure
- Batch population capabilities with consolidated error logging
GetDefaultValue<T>()
- Retrieve intelligent default values for types with custom converter logicGetDefaultValue(Type)
- Get default values for specific types with nullable type unwrapping
Method Discovery & Invocation
FindMethod(...)
- Discover methods with fuzzy matching algorithms and configurable similarity scoring (0-6 levels)MethodCall(...)
- Dynamically invoke discovered methods with parameter binding and execution control
Type Introspection
GetSerializableFields(...)
- Analyze type structure and discover serializable fields using converter chainGetSerializableProperties(...)
- Discover serializable properties with BindingFlags control and logging support
JSON Schema Generation
GetSchema<T>()
- Generate comprehensive JSON Schema for generic types with reference optimizationGetSchema(Type)
- Create JSON Schema for specific types with primitive handling and documentation extractionGetArgumentsSchema(...)
- Generate method parameter schemas for dynamic invocation and API documentation
JSON Serialization
JsonSerializer
- Access to ReflectorNet-optimized JSON serializer with custom convertersJsonSerializerOptions
- Access to configured JSON serialization optionsJsonSchema
- Access to JSON Schema generation utilities
Advanced Configuration
Custom Converter Registration
// Create a custom converter for specialized types
public class MyReflectionConvertor : GenericReflectionConvertor<MyClass>
{
// Override serialization behavior
protected override SerializedMember InternalSerialize(
Reflector reflector, object? obj, Type type,
string? name = null, bool recursive = true,
BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
int depth = 0, StringBuilder? stringBuilder = null, ILogger? logger = null)
{
// Custom serialization logic
return base.InternalSerialize(reflector, obj, type, name, recursive, flags, depth, stringBuilder, logger);
}
// Override priority scoring for better type matching
public override int SerializationPriority(Type type, ILogger? logger = null)
{
// Custom priority logic
return base.SerializationPriority(type, logger);
}
}
// Register the custom converter
reflector.Convertors.Add(new MyReflectionConvertor());
JSON Serialization Configuration
// Access to JSON serializer for additional configuration
var jsonSerializer = reflector.JsonSerializer;
jsonSerializer.AddConverter(new MyCustomJsonConverter());
// Access to JSON schema generation
var jsonSchema = reflector.JsonSchema;
var schema = jsonSchema.GetSchema<MyClass>(reflector, justRef: false);
Converter System Architecture
The ReflectorNet converter system uses a sophisticated priority-based selection:
- Priority Scoring: Each converter returns a score (0-10000+) indicating compatibility
- Automatic Selection: Highest priority converter is automatically selected
- Type Inheritance: Considers inheritance distance for optimal converter matching
- Extensibility: Easy to add custom converters for specialized type handling
Integration Examples
Unity Game Engine
This project powers Unity-MCP for AI-driven Unity development.
Web APIs
// Generate OpenAPI documentation
var methodSchemas = GetAllMethods()
.Select(m => reflector.GetArgumentsSchema(m))
.ToList();
AI & Machine Learning
// AI can discover and invoke methods based on natural language
var candidates = reflector.FindMethod(new MethodRef
{
MethodName = aiGeneratedMethodName,
TypeName = aiGeneratedTypeName
}, methodNameMatchLevel: 3);
Performance & Optimization
- Lazy Loading: Types and methods are discovered on-demand
- Caching: Reflection metadata is cached for optimal performance
- Memory Efficient: Minimal memory footprint with intelligent object pooling
- Parallel Safe: Thread-safe operations for concurrent environments
Contributing
We welcome contributions! Here's how to get involved:
- Fork the repository on GitHub
- Create a feature branch:
git checkout -b feature/amazing-feature
- Implement your changes with comprehensive tests
- Document your changes and update relevant documentation
- Test thoroughly across supported .NET versions
- Submit a Pull Request with detailed description
Development Guidelines
- Follow existing code style and patterns
- Add comprehensive unit tests for new features
- Update documentation for API changes
- Ensure compatibility across all supported .NET versions
- Include performance benchmarks for significant changes
Bug Reports & Feature Requests
Please use GitHub Issues with detailed descriptions, reproduction steps, and environment information.
License & Support
ReflectorNet is released under the Apache-2.0 License.
For questions, support, or discussions:
- GitHub Issues for bug reports and feature requests
- GitHub Discussions for general questions and community support
- Check the
docs/
folder for detailed documentation and examples
Built with โค๏ธ for the .NET and AI communities
Attribution & Citation
If you use ReflectorNet, please attribute the project:
"ReflectorNet (c) 2024-2025 Ivan Murzak, licensed under Apache-2.0"
Formal citation (see CITATION.cff
):
Murzak, I. (2025). ReflectorNet: Advanced .NET Reflection Toolkit for AI. Version 0.2.1. https://github.com/IvanMurzak/ReflectorNet
Third-party notices (if any) are listed in NOTICE
.
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 is compatible. 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. 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.0
- Microsoft.Extensions.Logging (>= 9.0.7)
- System.Text.Json (>= 9.0.7)
-
.NETStandard 2.1
- Microsoft.Extensions.Logging (>= 9.0.7)
- System.Text.Json (>= 9.0.7)
-
net9.0
- Microsoft.Extensions.Logging (>= 9.0.7)
- System.Text.Json (>= 9.0.7)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on com.IvanMurzak.ReflectorNet:
Package | Downloads |
---|---|
com.IvanMurzak.Unity.MCP.Common
Shared code between Unity-MCP-Plugin and Unity-MCP-Server projects. |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on com.IvanMurzak.ReflectorNet:
Repository | Stars |
---|---|
IvanMurzak/Unity-MCP
MCP Server + Plugin for Unity Editor and Unity game. The Plugin allows to connect to MCP clients like Claude Desktop or others.
|
Version | Downloads | Last Updated |
---|---|---|
1.0.4 | 287 | 8/16/2025 |
1.0.3 | 193 | 8/14/2025 |
1.0.2 | 194 | 8/14/2025 |
1.0.1 | 318 | 8/8/2025 |
1.0.0 | 294 | 8/8/2025 |
0.3.0 | 253 | 8/4/2025 |
0.2.4 | 511 | 7/25/2025 |
0.2.3 | 508 | 7/25/2025 |
0.2.1 | 550 | 7/24/2025 |
0.2.0 | 595 | 7/23/2025 |
0.1.13 | 467 | 6/24/2025 |
0.1.12 | 236 | 6/22/2025 |
0.1.11 | 108 | 6/22/2025 |
0.1.10 | 520 | 6/13/2025 |
0.1.9 | 161 | 5/29/2025 |
0.1.8 | 153 | 5/29/2025 |
0.1.7 | 152 | 5/28/2025 |
0.1.6 | 153 | 5/28/2025 |
0.1.5 | 151 | 5/28/2025 |
0.1.4 | 149 | 5/28/2025 |
0.1.3 | 155 | 5/28/2025 |
0.1.2 | 152 | 5/28/2025 |
0.1.1 | 150 | 5/28/2025 |
0.1.0 | 157 | 5/28/2025 |