Known source and destination types

Nov 24, 2011 at 11:00 PM
Edited Nov 24, 2011 at 11:03 PM


Looking through the documentation and trying some code i noticed there are bases for known source/target but not one for both.

If I'm doing a mapping between 2 known types and want type safety is there any injection base class suitable or some other method for this?

If I know what both types are why do I have to use object rather than type during the injection? e.g. have a new base type available such as "KnownTypesValueInjection<SomeKnownType1, SomeKnownType2>" should give an Inject method with signature "Inject(SomeKnownType1 source, SomeKnownType2 destination)" or something similar

Unless of course I'm missing the point of those classes (KnownSourceValueInjection and KnownTargetValueInjection)



Nov 25, 2011 at 3:45 AM

it is meant to be injecting from any to any object, that's why the InjectFrom methods have object types as parameters, even though you may use an injection that will just a certain type

Nov 27, 2011 at 9:52 AM
Edited Nov 27, 2011 at 9:55 AM

But you get type safety by using generics, don't really lose anything over using objects and dont need to box/unbox. Actually with generics there isn't much reason to use objects unless you need to store multiple types. Speed + compile time errors is much more useful than run-time errors and the ability to store multiple types in the majority of cases.

Nov 27, 2011 at 11:08 AM

well, nobody needed this before

Nov 27, 2011 at 11:18 AM

Someone probably has, I doubt I'm the first person who thought it would be better to have a generic option for source/target.

I still love the application, all I'm doing is making a suggestion.

Nov 27, 2011 at 11:54 AM
Edited Nov 27, 2011 at 11:54 AM

I understand, but the main purpose of it is to build very reusable injections, 

it wasn't intended to build a separate injection for each pair of types

Mar 19, 2013 at 9:01 PM
    abstract class KnownSourceAndDestInjector<TSource, TDest> : KnownSourceValueInjection<TSource>
        protected override void Inject(TSource source, object target)
            Inject(source, (TDest)target);

        protected abstract void Inject(TSource source, TDest target);

    internal class AddressInjector : KnownSourceAndDestInjector<Address, Composite>
        protected override void Inject(Address source, Composite target)
            target.Streetname = source.NameOfStreet;