Exemplo n.º 1
0
        private static TInstance ConstructInstance <TInstance, TLeft, TRight>(
            ConstructorInfo constructorInfo,
            ValueResolver <TLeft, TRight> valueResolver) where TInstance : class
        {
            // Resolve parameter values
            var constructorParameters = constructorInfo
                                        .GetParameters()
                                        .Select(info => info)
                                        .Select(valueResolver.Resolve)
                                        .ToArray();

            // Create instance
            var constructedInstance = constructorInfo.Invoke(constructorParameters) as TInstance
                                      ?? throw new InvalidOperationException(
                                                $"Cannot construct instance of type {typeof(TInstance)}");

            return(constructedInstance);
        }