/// <summary> /// Gets an interface to the <see cref="ContainerPropertyBag{TContainer}"/> for the given type. /// </summary> /// <remarks> /// The returned <see cref="IPropertyBag"/> can be used to get the strongly typed generic using the <see cref="IPropertyBag.Accept"/> method. /// </remarks> /// <param name="type">The container type to resolve the property bag for.</param> /// <returns>The resolved property bag.</returns> internal static IPropertyBag GetPropertyBag(Type type) { if (s_PropertyBags.TryGetValue(type, out var propertyBag)) { return(propertyBag); } if (!RuntimeTypeInfoCache.IsContainerType(type)) { return(null); } if (type.IsInterface || type.IsAbstract) { return(null); } if (null != s_PropertyBagProvider) { propertyBag = s_PropertyBagProvider.CreatePropertyBag(type); if (null == propertyBag) { s_PropertyBags.TryAdd(type, null); } else { propertyBag.Register(); return(propertyBag); } } return(null); }
/// <summary> /// Gets an interface to the <see cref="ContainerPropertyBag{TContainer}"/> for the given type. /// </summary> /// <remarks> /// The returned <see cref="IPropertyBag"/> can be used to get the strongly typed generic using the <see cref="IPropertyBag.Accept"/> method. /// </remarks> /// <param name="type">The container type to resolve the property bag for.</param> /// <returns>The resolved property bag.</returns> internal static IPropertyBag GetPropertyBag(Type type) { if (s_PropertyBags.TryGetValue(type, out var propertyBag)) { return(propertyBag); } if (!RuntimeTypeInfoCache.IsContainerType(type)) { return(null); } if (type.IsArray && type.GetArrayRank() != 1) { return(null); } if (type.IsInterface || type.IsAbstract) { return(null); } if (type == typeof(object)) { return(null); } if (null != s_PropertyBagProvider) { propertyBag = s_PropertyBagProvider.CreatePropertyBag(type); if (null == propertyBag) { #if !NET_DOTS s_PropertyBags.TryAdd(type, null); #else s_PropertyBags[type] = null; #endif } else { (propertyBag as IPropertyBagRegister)?.Register(); return(propertyBag); } } return(null); }