public virtual void Enqueue(int priority, IChoQueuedMsgServiceObject <T> msgQObject) { if (_stoppingService) { return; } ChoGuard.NotDisposed(this); CheckState(); _queue.Enqueue(priority, msgQObject); }
private static object[] GetTypeConvertersInternal(MemberInfo memberInfo) { if (memberInfo != null) { Type type; if (ChoType.TryGetMemberType(memberInfo, out type) && (type == null)) { return(EmptyTypeConverters); } if (_typeMemberTypeConverterCache.ContainsKey(memberInfo)) { if ((_typeMemberTypeConverterCache[memberInfo] == EmptyTypeConverters) && _typeTypeConverterCache.ContainsKey(type)) { return(_typeTypeConverterCache[type]); } return(_typeMemberTypeConverterCache[memberInfo]); } lock (_typeMemberTypeConverterCacheLockObject) { if (!_typeMemberTypeConverterCache.ContainsKey(memberInfo)) { _typeMemberTypeConverterCache[memberInfo] = EmptyTypeConverters; _typeMemberTypeConverterParamsCache[memberInfo] = EmptyParams; ChoPriorityQueue queue = new ChoPriorityQueue(); ChoPriorityQueue queue2 = new ChoPriorityQueue(); foreach (Attribute attribute in ChoType.GetMemberAttributesByBaseType(memberInfo, typeof(ChoTypeConverterAttribute))) { ChoTypeConverterAttribute attribute2 = (ChoTypeConverterAttribute)attribute; if (attribute2 != null) { queue.Enqueue(attribute2.Priority, attribute2.CreateInstance()); queue2.Enqueue(attribute2.Priority, attribute2.Parameters); } if (queue.Count > 0) { _typeMemberTypeConverterCache[memberInfo] = queue.ToArray(); _typeMemberTypeConverterParamsCache[memberInfo] = queue2.ToArray(); return(_typeMemberTypeConverterCache[memberInfo]); } } if ((queue.Count == 0) && !type.IsSimple()) { if (!_typeTypeConverterCache.ContainsKey(type)) { Register(type); } return(_typeTypeConverterCache[type]); } } return(_typeMemberTypeConverterCache.ContainsKey(memberInfo) ? _typeMemberTypeConverterCache[memberInfo] : ((object[])EmptyTypeConverters)); } } return(EmptyTypeConverters); }
private static void Register(Type type) { ChoTypeConverterAttribute customAttribute = type.GetCustomAttribute <ChoTypeConverterAttribute>(); if (customAttribute != null) { _typeTypeConverterCache.Add(type, new object[] { customAttribute.CreateInstance() }); _typeTypeConverterParamsCache.Add(type, new object[] { customAttribute.Parameters }); } ChoPriorityQueue queue = new ChoPriorityQueue(); ChoPriorityQueue queue2 = new ChoPriorityQueue(); foreach (Attribute attribute in ChoType.GetAttributes(type, typeof(ChoTypeConverterAttribute))) { ChoTypeConverterAttribute attribute2 = (ChoTypeConverterAttribute)attribute; if (attribute2 != null) { queue.Enqueue(attribute2.Priority, attribute2.CreateInstance()); queue2.Enqueue(attribute2.Priority, attribute2.Parameters); } } if (queue.Count > 0) { _typeTypeConverterCache[type] = queue.ToArray(); _typeTypeConverterParamsCache[type] = queue2.ToArray(); return; } TypeConverter converter = TypeDescriptor.GetConverter(type); if (converter != null && converter.GetType() != typeof(TypeConverter)) { _typeTypeConverterCache.Add(type, new object[] { converter }); _typeTypeConverterParamsCache.Add(type, EmptyParams); } else { _typeTypeConverterCache.Add(type, EmptyTypeConverters); _typeTypeConverterParamsCache.Add(type, EmptyParams); } }
public static object[] GetTypeConverters(MemberInfo memberInfo) { if (memberInfo == null) { return(null); } Type memberType; if (ChoType.TryGetMemberType(memberInfo, out memberType) && (memberType == null /*|| memberType.IsSimple() */)) { return(null); } if (_typeMemberTypeConverterCache.ContainsKey(memberInfo)) { if (_typeMemberTypeConverterCache[memberInfo] == EmptyTypeConverters) { if (_typeTypeConverterCache.ContainsKey(memberType)) { return(_typeTypeConverterCache[memberType]); } } return(_typeMemberTypeConverterCache[memberInfo]); } else { lock (_typeMemberTypeConverterCacheLockObject) { if (!_typeMemberTypeConverterCache.ContainsKey(memberInfo)) { Type typeConverterAttribute = typeof(ChoTypeConverterAttribute); _typeMemberTypeConverterCache[memberInfo] = EmptyTypeConverters; _typeMemberTypeConverterParamsCache[memberInfo] = EmptyParams; ChoPriorityQueue queue = new ChoPriorityQueue(); ChoPriorityQueue paramsQueue = new ChoPriorityQueue(); foreach (Attribute attribute in ChoType.GetAttributes(memberInfo, typeof(ChoTypeConverterAttribute), false)) { ChoTypeConverterAttribute converterAttribute = (ChoTypeConverterAttribute)attribute; if (converterAttribute != null) { queue.Enqueue(converterAttribute.Priority, converterAttribute.CreateInstance()); paramsQueue.Enqueue(converterAttribute.Priority, converterAttribute.Parameters); } if (queue.Count > 0) { _typeMemberTypeConverterCache[memberInfo] = queue.ToArray(); _typeMemberTypeConverterParamsCache[memberInfo] = paramsQueue.ToArray(); return(_typeMemberTypeConverterCache[memberInfo]); } } if (queue.Count == 0 && !memberType.IsSimple()) { if (!_typeTypeConverterCache.ContainsKey(memberType)) { foreach (Type type in ChoType.GetTypes <ChoTypeConverterAttribute>()) { ChoTypeConverterAttribute converterAttribute = type.GetCustomAttribute <ChoTypeConverterAttribute>(); if (converterAttribute != null && converterAttribute.ConverterType == memberType) { _typeTypeConverterCache.Add(memberType, new object[] { ChoType.CreateInstance(type) }); _typeTypeConverterParamsCache.Add(memberType, new object[] { converterAttribute.Parameters }); return(_typeTypeConverterCache[memberType]); } } TypeConverter converter = TypeDescriptor.GetConverter(memberType); if (converter != null) { _typeTypeConverterCache.Add(memberType, new object[] { converter }); } else { _typeTypeConverterCache.Add(memberType, EmptyTypeConverters); } _typeTypeConverterParamsCache.Add(memberType, EmptyParams); } return(_typeTypeConverterCache[memberType]); } } return(_typeMemberTypeConverterCache.ContainsKey(memberInfo) ? _typeMemberTypeConverterCache[memberInfo] : EmptyTypeConverters); } } }