Ejemplo n.º 1
0
        public Type GetPropertyValueType(PublishedPropertyType propertyType)
        {
            var settings = GetSettings(propertyType);

            var modelType = typeof(IPublishedContent);

            if (settings.AllowedDoctypes.Any() == true)
            {
                if (ModelsBuilderHelper.IsEnabled() == true)
                {
                    var foundType = GetTypeForAllowedDoctypes(settings.AllowedDoctypes);

                    if (foundType != null)
                    {
                        modelType = foundType;
                    }
                }
            }

            if (settings.AllowsMultiple() == true)
            {
                return(typeof(IEnumerable <>).MakeGenericType(modelType));
            }

            return(modelType);
        }
Ejemplo n.º 2
0
        private static Type GetTypeForAllowedDoctypes(string[] allowedDoctypes)
        {
            var modelsNamespace = ModelsBuilderHelper.GetNamespace();

            var types = TypeHelper.GetTypes(allowedDoctypes, modelsNamespace);

            if (types.Any() == true)
            {
                if (allowedDoctypes.Length > 1)
                {
                    var interfaces = types.Select(x => x
                                                  .GetInterfaces()
                                                  .Where(i => i.IsPublic));

                    var sharedInterfaces = interfaces.IntersectMany();

                    return(sharedInterfaces.LastOrDefault());
                }
            }

            return(types.FirstOrDefault());
        }
Ejemplo n.º 3
0
        public static Type GetPropertyValueType(PublishedPropertyType propertyType, IPickerSettings pickerSettings)
        {
            var modelType = typeof(IPublishedContent);

            if (pickerSettings.AllowedDoctypes.Count() == 1 &&
                ModelsBuilderHelper.IsEnabled() == true)
            {
                var modelsNamespace = ModelsBuilderHelper.GetNamespace();

                var foundType = TypeHelper.GetType(pickerSettings.AllowedDoctypes.FirstOrDefault(), modelsNamespace);

                if (foundType != null)
                {
                    modelType = foundType;
                }
            }

            if (pickerSettings.AllowsMultiple() == true)
            {
                return(typeof(IEnumerable <>).MakeGenericType(modelType));
            }

            return(modelType);
        }