Add useful extension methods for System.Type #358

Open
dotnetjunkie opened this Issue Dec 21, 2016 · 0 comments

Projects

None yet

1 participant

@dotnetjunkie
Collaborator

When working with Simple Injector (or any other DI container for that matter), it is quite usual for a user to query the type system for generic types. Some very common scenarios are checking whether a type implements a closed version of a some open-generic type, or getting the list of closed types that a type implements based on an open-generic type.

In the past we decided not to add such set of extension methods to Simple Injector, because this type of problem is not related to Simple Injector itself, and it would easily cause conflicting situations when Simple Injector would be used in combination with other tools that also add similar extension methods or when such feature gets added to the BCL.

These scenarios however are so common that you see Simple Injector users reinvent the weel over and over again, while the quality of such implementation might vary. Because of this I now think it just too convenient for the user not to have these types of extension methods.

Here are three examples:

  • bool IsClosedTypeOf(this Type, Type)
  • Type[] GetClosedTypesOf(this Type, Type)
  • string ToFriendlyName(this Type) // returns a more readable type name (in C# syntax)

These extension methods should be placed in the SimpleInjector namespace.

@dotnetjunkie dotnetjunkie added this to the v4 milestone Dec 21, 2016
@dotnetjunkie dotnetjunkie added a commit that referenced this issue Dec 23, 2016
@dotnetjunkie dotnetjunkie Spllit Helpers class into two.
ALl Type related methods are moved to new internal Types class. Related
to #358
2593fad
@dotnetjunkie dotnetjunkie added a commit that referenced this issue Dec 23, 2016
@dotnetjunkie dotnetjunkie Renamed class.
Related to #358
d316ff3
@dotnetjunkie dotnetjunkie added a commit that referenced this issue Dec 23, 2016
@dotnetjunkie dotnetjunkie Made ToFriendlyName public
Related to #358
de7b2c6
@dotnetjunkie dotnetjunkie added a commit that referenced this issue Dec 25, 2016
@dotnetjunkie dotnetjunkie GetClosedTypeOf method added.
Related to #358
1f95cc6
@dotnetjunkie dotnetjunkie self-assigned this Dec 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment