1234567891011121314151617181920212223242526272829303132333435363738 |
- using System;
- using Luticate2.Auth.Utils.Interfaces;
-
- namespace Luticate2.Auth.Utils.Business.ObjectConverter
- {
- public static class LuObjectConverterUtils
- {
- public static ILuObjectConverter GetObjectConverter(IServiceProvider serviceProvider, Type typeFrom, Type typeTo)
- {
- var type = typeof(ILuObjectConverter<,>);
- var gtype = type.MakeGenericType(typeFrom, typeTo);
- var converter = (ILuObjectConverter) serviceProvider.GetService(gtype);
-
- if (converter == null)
- {
- var baseTypeFrom = typeFrom;
- if (typeFrom.IsGenericType)
- {
- baseTypeFrom = typeFrom.GetGenericTypeDefinition();
- }
- var baseTypeTo = typeTo;
- if (typeTo.IsGenericType)
- {
- baseTypeTo = typeTo.GetGenericTypeDefinition();
- }
- gtype = type.MakeGenericType(baseTypeFrom, baseTypeTo);
- converter = (ILuObjectConverter) serviceProvider.GetService(gtype);
- }
-
- if (converter == null && typeFrom == typeTo)
- {
- converter = (ILuObjectConverter) serviceProvider.GetService(typeof(ILuObjectConverterIdentity));
- }
-
- return converter;
- }
- }
- }
|