Skip to content

Commit

Permalink
Rewrote PageDefinitionSpecificPropertySettingsUpdater.GetPropertySett…
Browse files Browse the repository at this point in the history
…ingsUpdaters as a LINQ expression (it felt easier to read).
  • Loading branch information
cjberg committed Dec 18, 2011
1 parent ffd48e9 commit 0f95cc9
Showing 1 changed file with 13 additions and 21 deletions.
Expand Up @@ -72,7 +72,7 @@ void UpdatePageDefinitionsLocalPropertySettings(PageTypePropertyDefinition prope

void UpdatePageDefinitionsGlobalPropertySettings(PageTypePropertyDefinition propertyDefinition, PageTypeDefinition pageTypeDefinition, PageDefinition pageDefinition)
{
object[] attributes = GetPropertyAttributes(propertyDefinition, pageTypeDefinition);
IEnumerable<object> attributes = GetPropertyAttributes(propertyDefinition, pageTypeDefinition);
var useGlobalSettingsAttribute = attributes.OfType<UseGlobalSettingsAttribute>().FirstOrDefault();
if (useGlobalSettingsAttribute != null)
{
Expand Down Expand Up @@ -114,28 +114,20 @@ private PropertySettingsContainer GetPropertySettingsContainer(PageDefinition pa
return container;
}

private List<PropertySettingsUpdater> GetPropertySettingsUpdaters(PageTypeDefinition pageTypeDefinition, PageTypePropertyDefinition propertyDefinition)
private static List<PropertySettingsUpdater> GetPropertySettingsUpdaters(PageTypeDefinition pageTypeDefinition, PageTypePropertyDefinition propertyDefinition)
{
object[] attributes = GetPropertyAttributes(propertyDefinition, pageTypeDefinition);
var settingsUpdaters = new List<PropertySettingsUpdater>();
foreach (var attribute in attributes)
{
foreach (var interfaceType in attribute.GetType().GetInterfaces())
{
if (!interfaceType.IsGenericType)
continue;

if (!typeof(IUpdatePropertySettings<>).IsAssignableFrom(interfaceType.GetGenericTypeDefinition()))
continue;
var settingsType = interfaceType.GetGenericArguments().First();
var updater = new PropertySettingsUpdater(settingsType, attribute);
settingsUpdaters.Add(updater);
}
}
return settingsUpdaters;
var settingsUpdaters =
from attribute in GetPropertyAttributes(propertyDefinition, pageTypeDefinition)
from interfaceType in attribute.GetType().GetInterfaces()
where interfaceType.IsGenericType
&& typeof(IUpdatePropertySettings<>).IsAssignableFrom(interfaceType.GetGenericTypeDefinition())
let settingsType = interfaceType.GetGenericArguments().First()
select new PropertySettingsUpdater(settingsType, attribute);

return settingsUpdaters.ToList();
}

private object[] GetPropertyAttributes(PageTypePropertyDefinition propertyDefinition, PageTypeDefinition pageTypeDefinition)
private static IEnumerable<object> GetPropertyAttributes(PageTypePropertyDefinition propertyDefinition, PageTypeDefinition pageTypeDefinition)
{
// Binding flags supporting both public and non-public instance properties
const BindingFlags propertyBindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
Expand Down Expand Up @@ -174,7 +166,7 @@ private object[] GetPropertyAttributes(PageTypePropertyDefinition propertyDefini
//var message = String.Format("Unable to locate the property \"{0}\" in PageType \"{1}\".",
// propertyDefinition.Name, pageTypeDefinition.GetPageTypeName());
//throw new PageTypeBuilderException(message);
return new object[0];
return Enumerable.Empty<object>();
}

return prop.GetCustomAttributes(true);
Expand Down

0 comments on commit 0f95cc9

Please sign in to comment.