1234567891011121314151617181920212223242526272829303132333435 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using Luticate2.Auth.Utils.Interfaces;
-
- namespace Luticate2.Auth.Utils.Business.Converters
- {
- public class LuConvertersAllocator : ILuConvertersAllocator
- {
- protected static IDictionary<Type, Type> listTypes = new Dictionary<Type, Type>
- {
- {typeof(IEnumerable<>), typeof(List<>)},
- {typeof(ICollection<>), typeof(Collection<>)},
- {typeof(Collection<>), typeof(Collection<>)},
- {typeof(IList<>), typeof(List<>)},
- {typeof(List<>), typeof(List<>)}
- };
-
- public object GetInstance(Type type)
- {
- if (type.IsGenericType)
- {
- var gtype = type.GetGenericTypeDefinition();
-
- if (listTypes.ContainsKey(gtype))
- {
- var glistType = listTypes[gtype].MakeGenericType(type.GenericTypeArguments[0]);
- return Activator.CreateInstance(glistType);
- }
- }
- return Activator.CreateInstance(type);
- }
- }
- }
|