Skip to content

Instantly share code, notes, and snippets.

@danielmoore
Created July 9, 2011 23:36
Show Gist options
  • Save danielmoore/1074060 to your computer and use it in GitHub Desktop.
Save danielmoore/1074060 to your computer and use it in GitHub Desktop.
bad code style?
private bool IsIncluded(LazyMemberInfo memberInfo)
{
var accessors = memberInfo.GetAccessors().Where(a => a != null);
var types = accessors.Select(m => m as Type ?? m.DeclaringType);
var assemblies = types.Select(t => t.Assembly).Distinct().Where(a => a != null);
var scopeSets = new[]
{
// Local Scopes
accessors
.Concat(accessors.GroupJoin(
types.SelectMany(t => t.GetProperties()),
a => a,
a => a.GetGetMethod(),
(l, r) => r.SingleOrDefault()))
.Where(a => a != null)
.SelectMany(Attribute.GetCustomAttributes)
.OfType<ILocalCompositionContainerScope>()
.Select(s => s.ShouldIncludeInContainer(_containerName)),
// Type Scopes
accessors
.Select(a => a.DeclaringType)
.Where(t => t != null)
.SelectMany(Attribute.GetCustomAttributes)
.OfType<ILocalCompositionContainerScope>()
.Select(s => s.ShouldIncludeInContainer(_containerName)),
// Assembly Global Scopes
assemblies
.SelectMany(Attribute.GetCustomAttributes)
.OfType<IGlobalCompositionContainerScope>()
.OrderBy(s => s.Importance)
.SelectMany(s => types.Select(t => s.ShouldIncludeInContainer(_containerName, t))),
// Assembly Local Scopes
assemblies
.SelectMany(Attribute.GetCustomAttributes)
.OfType<ILocalCompositionContainerScope>()
.Select(s => s.ShouldIncludeInContainer(_containerName))
};
var result = scopeSets.Select(s => s.Aggregate(Conjoin)).First(v => v.HasValue);
return result ?? false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment