Ministry.Reflection 5.0.0

dotnet add package Ministry.Reflection --version 5.0.0                
NuGet\Install-Package Ministry.Reflection -Version 5.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ministry.Reflection" Version="5.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ministry.Reflection --version 5.0.0                
#r "nuget: Ministry.Reflection, 5.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Ministry.Reflection as a Cake Addin
#addin nuget:?package=Ministry.Reflection&version=5.0.0

// Install Ministry.Reflection as a Cake Tool
#tool nuget:?package=Ministry.Reflection&version=5.0.0                

Ministry.ReflectionHelper

This project is set up to make the process of Reflection in .net much easier to code than it is using the standard methods provided by the framework by applying core features through a simple API. I always found the .net Reflection methods quite unwieldy and unintuitive.

Fields

The following methods exist for fields...

Ministry.ReflectionHelper.Field.Exists()

Traditional and generic variants of this method can be called either passing in a type or a value of a given type along with a field name to look for on that type.

Ministry.ReflectionHelper.Field.Get()

Traditional and generic variants of this method can be called by passing in an object to query along with a field name. For example...

Field.Get(myObj, "name");

Overloads are also provided for static types that take a type parameter instead of an object instance.

Ministry.ReflectionHelper.Field.Set()

Traditional and generic variants of this method can be called by passing in an object to query along with a field name to set. For example...

Field.Set(myObj, "name", "new value");

Overloads are also provided for static types that take a type parameter instead of an object instance.

Ministry.ReflectionHelper.Field.GetInfo()

Sometimes you do need the Info objects but in traditional .net code this can become quite awkward if the object you are looking for is further down the inheritance tree than the layer that you are interrogating. Ministry.ReflectionHelper wraps up all of the code required to recurse down the inheritance tree to find the type that you are looking for. This method also provides the same service to the rest of the Field class, enabling the helper to provide Reflection against the whole inheritance tree.

Properties

Reflection on Fields & Properties are similar. The following methods exist for properties...

Ministry.ReflectionHelper.Property.Exists()

Traditional and generic variants of this method can be called either passing in a type or a value of a given type along with a property name to look for on that type.

Ministry.ReflectionHelper.Property.IsReadOnly()

Traditional and generic variants of this method can be called either passing in a type or a value of a given type along with a property name to look for on that type.

Ministry.ReflectionHelper.Property.Get()

Traditional and generic variants of this method can be called by passing in an object to query along with a property name. For example...

Property.Get(myObj, "Name");

Overloads are also provided for static types that take a type parameter instead of an object instance.

Ministry.ReflectionHelper.Property.Set()

Traditional and generic variants of this method can be called by passing in an object to query along with a property name to set. For example...

Property.Set(myObj, "Name", "new value");

Overloads are also provided for static types that take a type parameter instead of an object instance.

Ministry.ReflectionHelper.Property.GetInfo()

Sometimes you do need the Info objects but in traditional .net code this can become quite awkward if the object you are looking for is further down the inheritance tree than the layer that you are interrogating. Ministry.ReflectionHelper wraps up all of the code required to recurse down the inheritance tree to find the type that you are looking for. This method also provides the same service to the rest of the Properties class, enabling the helper to provide Reflection against the whole inheritance tree.

Ministry.ReflectionHelper.Property.Indexer.GetItem()

Traditional and generic variants of this method can be called by passing in an object to query along with a property name and an index. For example...

Property.Indexer.GetIItem(myObj, "Index", 4);

Ministry.ReflectionHelper.Property.Indexer.SetItem()

Traditional and generic variants of this method can be called by passing in an object to query along with a property name and an index to set. For example...

Property.Indexer.SetItem(myObj, "Index", 4, "new value");

Methods

The following methods exist for methods. Method access through Reflection is very problematic. The Methods class within Ministry.ReflectionHelper, as with Fields and Properties, benefits from inheritance tree recursion.

Ministry.ReflectionHelper.Method.Execute()

Many overloaded variants of this exist to call a method with or without parameters. The method execution code will search for the method to execute using the method below.

Ministry.ReflectionHelper.Method.GetInfo()

Sometimes you do need the Info objects but in traditional .net code this can become quite awkward if the object you are looking for is further down the inheritance tree than the layer that you are interrogating. Ministry.ReflectionHelper wraps up all of the code required to recurse down the inheritance tree to find the type that you are looking for.

Ministry.ReflectionHelper.Method.GetParameters()

Provides you with the info about the parameters for a given method.

Summary

That's the key functionality of the Ministry.ReflectionHelper classes. If you want to do any kind of deep reflection and you don't have the joy of the Dynamic Language Runtime to help you out then I hope you'll find some of the methods in these classes really useful. If you want to find out any more, simply check out the source code.

Upgrading v3.x to v4.x / v5.x

If you are upgrading from v2 or v3 to v4 or v5 you may find breaking changes. In v4 we have added some helpful extension methods and moved support away from the stanadrd .net framework to NETSTandard 1.6 to support dotnet core. v5 No longer supports .net Standard and .net Framework.

The Ministry of Technology Open Source Products

Welcome to The Ministry of Technology open source products. All open source Ministry of Technology products are distributed under the MIT License for maximum re-usability. Our other open source repositories can be found here...

Where can I get it?

You can download the package for this project from any of the following package managers...

Contribution guidelines

If you would like to contribute to the project, please contact me.

Who do I talk to?

  • Keith Jackson - temporal-net@live.co.uk
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Ministry.Reflection:

Package Downloads
Ministry.Compositions

Library of Functional Composition Extension Methods

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.0.0 3,952 12/28/2023
4.0.1 18,607 5/9/2018
4.0.0 1,847 3/21/2018