ToolBX.Reflection4Humans.TypeFetcher 2.0.0-beta1

This is a prerelease version of ToolBX.Reflection4Humans.TypeFetcher.
There is a newer version of this package available.
See the version list below for details.
dotnet add package ToolBX.Reflection4Humans.TypeFetcher --version 2.0.0-beta1
                    
NuGet\Install-Package ToolBX.Reflection4Humans.TypeFetcher -Version 2.0.0-beta1
                    
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="ToolBX.Reflection4Humans.TypeFetcher" Version="2.0.0-beta1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ToolBX.Reflection4Humans.TypeFetcher" Version="2.0.0-beta1" />
                    
Directory.Packages.props
<PackageReference Include="ToolBX.Reflection4Humans.TypeFetcher" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ToolBX.Reflection4Humans.TypeFetcher --version 2.0.0-beta1
                    
#r "nuget: ToolBX.Reflection4Humans.TypeFetcher, 2.0.0-beta1"
                    
#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.
#addin nuget:?package=ToolBX.Reflection4Humans.TypeFetcher&version=2.0.0-beta1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=ToolBX.Reflection4Humans.TypeFetcher&version=2.0.0-beta1&prerelease
                    
Install as a Cake Tool

Reflection4Humans

Reflection4Humans

Reflection extension methods meant to be used by humans.

Type extensions

Type.GetHumanReadableName

Have you ever wanted to output a type name in an exception message before only for it to read like this?

"Reflection4Humans.Extensions.Tests.Dummy`1[System.String] did something weird!"

Wouldn't it have been easier on the eyes if it had said this instead?

"Dummy<String> did something weird!"

This is what this method helps you achieve.

//Instead of this
typeof(Dummy<string>).Name

//Use this
typeof(Dummy<string>).GetHumanReadableName();

Type.IsAttribute

//Isn't it weird that you have the following in C#
var isInterface = type.IsInterface;
var isAbstract = type.IsAbstract;
var isClass = type.IsClass;
var isGenericType = type.IsGenericType;

//But not this?
var isAttribute = type.IsAttribute();

Well now you have it.

TypeFetcher

Wouldn't it be awesome if there was a way to get all your type metadata in all your assemblies in a straightforward way like this?

var allMyAbstractClasses = TypeFetcher.Query().IsClass().IsAbstract().ToList();

Well now you can!

Currently, TypeFetcher only supports the following criterion :

  • IsClass / IsNotClass
  • IsAbstract / IsNotAbstract (applies to both classes and interfaces unless also searching for classes)
  • IsStruct / IsNotStruct
  • IsInterface / IsNotInterface
  • IsAttribute / IsNotAttribute
  • IsGeneric / IsNotGeneric
  • IsGenericTypeDefinition / IsNotGenericTypeDefinition
  • IsEnum /IsNotEnum
  • Implements
  • HasAttributes

It is still being actively tested and may (very probably) change a lot in its syntax and usability.

Why should I use this when I can do it myself?

You certainly can use the following (and might have) :

AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())[...]

But if you're like me then you probably don't like remembering that whole trainwreck and might even have to look up how you did it before in order to use it.

Not only that but I have also encountered problems with the above line in some cases because assemblies are not always automatically loaded and some types got left out. TypeFetcher does that for you. I won't hide that there's a bigger performance cost to it but getting types is always something that should be used sparingly.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on ToolBX.Reflection4Humans.TypeFetcher:

Package Downloads
ToolBX.AutoInject

A .NET library to make it easier to use DI by adding [AutoInject] attributes directly on classes.

ToolBX.Dummies

A lightweight object generation framework for unit testing purposes

ToolBX.AutoConfig

A .NET library to make it easier to use appsettings sections using [AutoConfig] attributes directly on classes.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 6,308 9/26/2024
3.0.0-beta5 319 9/22/2024
3.0.0-beta4 308 9/22/2024
3.0.0-beta3 116 9/22/2024
3.0.0-beta2 153 9/7/2024
3.0.0-beta1 227 5/31/2024
2.2.0 10,566 1/11/2024
2.2.0-beta9 600 1/7/2024
2.2.0-beta8 137 12/29/2023
2.2.0-beta7 129 12/14/2023
2.2.0-beta6 297 12/14/2023
2.2.0-beta4 433 11/16/2023
2.2.0-beta3 103 11/15/2023
2.2.0-beta2 140 8/16/2023
2.2.0-beta1 425 7/24/2023
2.1.0-beta1 10,422 6/28/2023
2.0.3 3,245 6/19/2023
2.0.1 1,970 4/23/2023
2.0.0 1,055 11/9/2022
2.0.0-beta1 178 9/20/2022
0.9.0-beta 6,420 5/12/2022