using System; 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 listTypes = new Dictionary { {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); } } }