Add IPropertyHandlerProvider
concept to allow for custom property handling
#45
Labels
IPropertyHandlerProvider
concept to allow for custom property handling
#45
Background
Right now, all of the ways that
IPropertyHandler
implementations can be defined is hard-coded into the static constructor ofImmutableBase<TImmutable>
. This sucks for two big reasons:IPropertyHandler
implementation, the have to do it with hackery and reflection. It is essentially non-extensible.IPropertyHandler
is to be constructed (like, for example, as defined in Add [StringComparison]-like annotation for String properties #12 and Add [EnumerableComparison]-like annotation for IEnumerable properties #14), that logic gets stuck inside ofImmutableBase<TImmutable>
when it could have its complexity compartmentalized.Both of these could be solved with a few interfaces with default implementations.
Task
Create two new interfaces, as follows:
Create three implementations,
StringPropertyHandlerProvider
,EnumerablePropertyHandlerProvider
(for Set & List) andDefaultPropertyHandlerProvider
, that inspect the relevantPropertyInfo
as we do inImmutableBase<TImmutable>
static constructor today to determine support and desired approach to hydration.Create an
AggregatePropertyHandlerProvider
that takes in a list ofIPropertyHandlerProvider
implementations and processes them in order. The first match is used to create anIPropertyHandler
.Use a
IPropertyHandlerFactory
in theImmutableBase<TImmutable>
static constructor to hydrateIPropertyHandler
implementations instead of doing it all in a hard-coded fashion as it does today. It should have a public getter and setter such that others can change how properties are cached. Additionally, when it changes its value, that should cause all of the cachedIPropertyHandler
implementations to be rebuilt using the newIPropertyHandlerFactory
.Assuming all of these changes went through, I would expect the static constructor for
ImmutableBase<TImmutable>
to start to look something like this:Then, when we implement #12 and #14, we can keep that logic in the
IPropertyHandlerProvider
implementations instead of keeping it centrally located in theImmutableBase<TImmutable>
static constructor.The text was updated successfully, but these errors were encountered: