Share via

Reflection

PharmaSoft 1 Reputation point
2024-06-14T09:19:56.48+00:00

Hello, I try to inject this service in serviceprovider with two parameters. At the end, it will be generic but for this exemple, I put the parameters. Could you help me ?

List<ConstructorInfo> ctors;

Type[] genericArguments = interfaceType.GetGenericArguments();

int expectedArgumentsCount = genericArguments.Length;

if (expectedArgumentsCount > 2)

{

ctors = pipeline.Select(

    x => {

        if (x.IsGenericType)

        {

            Type[] genericArguments;

            if (x == typeof(RemoveEntityGenericHandler<,>))

            {

                Type entityType = typeof(Assurance); // ou déterminez dynamiquement

                Type queryType = typeof(AssuranceRepository);

                genericArguments = new Type[] { entityType, queryType };

            }

            else

            {

                genericArguments = interfaceType.GetGenericArguments();

            }

            Type specificType = x.MakeGenericType(genericArguments);

            return specificType.GetConstructors().Single();

        }

        else

        {

            return x.GetConstructors().Single();

        }

    })

    .ToList();

}

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.