public void CanResolveRuntimeTypes() { IEnumerable <Type> types = PluginManagerInvocations.ResolveTypes(typeof(PublishedItem)); Assert.NotNull(types); Assert.True(types.Contains(typeof(PublishedItem))); }
/// <inheritdoc/> public override object Map(IPublishedContent content, object value) { Type propType = this.PropertyType; bool propTypeIsEnumerable = propType.IsEnumerableType(); Type baseType = propTypeIsEnumerable ? propType.GetEnumerableType() : propType; var types = (IEnumerable <Type>)ApplicationContext.Current.ApplicationCache.StaticCache.GetCacheItem("UmbMapperFactoryAttribute_ResolveTypes_" + baseType.AssemblyQualifiedName, () => { // Workaround for http://issues.umbraco.org/issue/U4-9011 if (baseType.Assembly.IsAppCodeAssembly()) { // This logic is taken from the core type finder so it should be performing the same checks return(baseType.Assembly .GetTypes() .Where(t => baseType.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract && !t.IsSealed && !t.IsNestedPrivate && t.GetCustomAttribute <HideFromTypeFinderAttribute>(true) == null) .ToArray()); } return(PluginManagerInvocations.ResolveTypes(baseType)); }); // Check for IEnumerable<IPublishedContent> value if (value is IEnumerable <IPublishedContent> enumerableValue) { IEnumerable <object> items = enumerableValue.Select(x => { string typeName = this.ResolveTypeName(x); Type type = types.FirstOrDefault(y => y.Name.InvariantEquals(typeName)); return(type != null ? x.MapTo(type) : null); }); return(EnumerableInvocations.Cast(baseType, items)); } // Check for IPublishedContent value if (value is IPublishedContent ipublishedContentValue) { string typeName = this.ResolveTypeName(ipublishedContentValue); Type type = types.FirstOrDefault(y => y.Name.InvariantEquals(typeName)); return(type != null?ipublishedContentValue.MapTo(type) : null); } // No other possible options return(this.DefaultValue); }
public IEnumerable <Type> PluginManagerInvoke() { return(PluginManagerInvocations.ResolveTypes(typeof(EnumPropertyMapper))); }