public static IReadOnlyList <Type> GetAssetTypes(Type contentType) { lock (RegistryLock) { var currentType = contentType; if (UrlReferenceHelper.IsGenericUrlReferenceType(currentType)) { currentType = UrlReferenceHelper.GetTargetContentType(currentType); } else if (UrlReferenceHelper.IsUrlReferenceType(contentType)) { return(GetPublicTypes().Where(t => IsAssetType(t)).ToList()); } List <Type> assetTypes; return(ContentToAssetTypes.TryGetValue(currentType, out assetTypes) ? new List <Type>(assetTypes) : new List <Type>()); } }
/// <summary> /// Creates a reference to the given asset that matches the given reference type. /// </summary> /// <param name="asset">The target asset of the reference to create.</param> /// <param name="referenceType">The type of reference to create.</param> /// <returns>A reference to the given asset if it's not null and <paramref name="referenceType"/> is a valid reference type, null otherwise.</returns> /// <remarks>A reference type is either an <see cref="AssetReference"/> or a content type registered in the <see cref="AssetRegistry"/>.</remarks> public static object CreateReference(AssetViewModel asset, Type referenceType) { if (asset != null) { if (UrlReferenceHelper.IsUrlReferenceType(referenceType)) { return(AttachedReferenceManager.CreateProxyObject(referenceType, asset.Id, asset.Url)); } if (AssetRegistry.IsContentType(referenceType)) { var assetType = asset.AssetItem.Asset.GetType(); var contentType = AssetRegistry.GetContentType(assetType); return(referenceType.IsAssignableFrom(contentType) ? AttachedReferenceManager.CreateProxyObject(contentType, asset.Id, asset.Url) : null); } if (typeof(AssetReference).IsAssignableFrom(referenceType)) { return(new AssetReference(asset.AssetItem.Id, asset.AssetItem.Location)); } } return(null); }
/// <inheritdoc/> public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return(UrlReferenceHelper.IsUrlReferenceType(TypeConverterHelper.GetDestinationType(context))); }
public override bool CanVisit(Type type) { return(UrlReferenceHelper.IsUrlReferenceType(type)); }