17 using System.Collections;
18 using System.Collections.Concurrent;
19 using System.Collections.Generic;
22 using System.Linq.Expressions;
23 using System.Reflection;
35 private static readonly MethodInfo SetPropertyMethodInfo = typeof(
DynamicSecurityData).GetMethod(
"SetProperty");
36 private static readonly MethodInfo GetPropertyMethodInfo = typeof(
DynamicSecurityData).GetMethod(
"GetProperty");
39 private readonly ConcurrentDictionary<Type, Type> _genericTypes =
new ConcurrentDictionary<Type, Type>();
49 _registeredTypes = registeredTypes;
66 return _cache.HasData(typeof(T));
78 if (_registeredTypes.TryGetType(name, out type))
80 return _cache.HasData(type);
91 return list.LastOrDefault();
99 return GetAllImpl(typeof(T));
107 public PyObject
Get(Type type)
118 return list[list.Count - 1].ToPython();
129 return GetAllImpl(type);
138 [Obsolete(
"DynamicSecurityData is a view of the SecurityCache. It is readonly, properties can not be set")]
154 if (_registeredTypes.TryGetType(name, out type))
156 IReadOnlyList<BaseData> data;
157 if (_cache.TryGetValue(type, out data))
162 var listType = GetGenericListType(type);
163 return Activator.CreateInstance(listType);
172 private dynamic GetAllImpl(Type type)
176 var dataType = data.GetType();
177 if (dataType.GetElementType() == type
179 || dataType.GenericTypeArguments.Length == 1
180 && dataType.GenericTypeArguments[0] == type)
185 var baseDataList = data as IReadOnlyList<BaseData>;
186 if (baseDataList !=
null)
188 var listType = GetGenericListType(type);
189 var list = (IList)Activator.CreateInstance(listType);
190 foreach (var baseData
in baseDataList)
197 throw new InvalidOperationException(Messages.DynamicSecurityData.UnexpectedTypesForGetAll(type, data));
200 private Type GetGenericListType(Type type)
203 if (!_genericTypes.TryGetValue(type, out containerType))
206 _genericTypes[type] = containerType = typeof(List<>).MakeGenericType(type);
209 return containerType;