/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/MassTransit/Metadata/TypeMetadataCache.cs
92 строки
3 KB
Chris Patterson
Massive file cleanup
27 мар 2024, 02:43
27 мар 2024, 02:43
2ac69e8
Код
Авторство
О чём код?
namespace MassTransit.Metadata { using System; using System.Collections.Generic; using System.Reflection; using Internals; public static class TypeMetadataCache { static readonly object _builderLock = new object(); public static IImplementationBuilder ImplementationBuilder => Cached.Builder; public static Type GetImplementationType(Type type) { lock (_builderLock) return Cached.Builder.GetImplementationType(type); } public static string GetShortName(Type type) { return TypeCache.GetShortName(type); } public static IEnumerable<PropertyInfo> GetProperties(Type type) { return MessageTypeCache.GetProperties(type); } public static bool IsValidMessageType(Type type) { return MessageTypeCache.IsValidMessageType(type); } public static bool IsTemporaryMessageType(Type type) { return MessageTypeCache.IsTemporaryMessageType(type); } public static Type[] GetMessageTypes(Type type) { return MessageTypeCache.GetMessageTypes(type); } public static string[] GetMessageTypeNames(Type type) { return MessageTypeCache.GetMessageTypeNames(type); } public static bool IsValidMessageDataType(Type type) { return type.IsInterfaceOrConcreteClass() && MessageTypeCache.IsValidMessageType(type) && !type.IsValueTypeOrObject(); } static class Cached { internal static readonly IImplementationBuilder Builder = new DynamicImplementationBuilder(); } } public class TypeMetadataCache<T> : ITypeMetadataCache<T> { readonly Lazy<Type> _implementationType; TypeMetadataCache() { _implementationType = new Lazy<Type>(() => TypeMetadataCache.GetImplementationType(typeof(T))); } public static Type ImplementationType => Cached.Metadata.Value.ImplementationType; public static string ShortName => TypeCache<T>.ShortName; public static string DiagnosticAddress => MessageTypeCache<T>.DiagnosticAddress; public static IEnumerable<PropertyInfo> Properties => MessageTypeCache<T>.Properties; public static bool IsValidMessageType => MessageTypeCache<T>.IsValidMessageType; public static string InvalidMessageTypeReason => MessageTypeCache<T>.InvalidMessageTypeReason; public static bool IsTemporaryMessageType => MessageTypeCache<T>.IsTemporaryMessageType; public static Type[] MessageTypes => MessageTypeCache<T>.MessageTypes; public static string[] MessageTypeNames => MessageTypeCache<T>.MessageTypeNames; Type ITypeMetadataCache<T>.ImplementationType => _implementationType.Value; static class Cached { internal static readonly Lazy<ITypeMetadataCache<T>> Metadata = new Lazy<ITypeMetadataCache<T>>(() => new TypeMetadataCache<T>()); } } }