private static void PopulateCategoryAssignmentProperties()
{
// This method populates a "map" of what types and properties contain category assignments.
// This map is consulted to determine when we need to be concerned about indexing assignments.
CategoryAssignmentProperties = new Dictionary<Type, List<string>>();
// Iterate all types which have a backing class...
var contentTypeRepo = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
foreach (var contentType in contentTypeRepo.List().Where(t => t.ModelType != null))
{
// Iterate all properties...
foreach (var property in contentType.ModelType.GetProperties())
{
// Does this property have the CategoryAssignment attribute?
if (!property.GetCustomAttributes<IndexAsCategoriesAttribute>().Any())
{
continue;
}
// Is this property the correct type?
if(property.PropertyType != typeof(IEnumerable<ContentReference>))
{
continue;
}
// We're good, add it to the map...
if(!CategoryAssignmentProperties.ContainsKey(contentType.ModelType))
{
CategoryAssignmentProperties.Add(contentType.ModelType, new List<string>());
}
CategoryAssignmentProperties[contentType.ModelType].Add(property.Name);
}
}
}