|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace Technewlogic.ObjectLounge.Framework.MetaModel
{
// TODO: Tests für das automatische Injecten von Entity Collections schreiben
public class ApplicationContextSpec
{
internal ApplicationContextSpec(
ModelConfigurationErrorManager errorManager,
Type contextType)
{
_errorManager = errorManager;
ContextType = contextType;
BuildApplicationContextCollectionSpecs();
}
private readonly ModelConfigurationErrorManager _errorManager;
public Type ContextType { get; private set; }
public IEnumerable<ApplicationContextCollectionSpec> ApplicationContextCollectionSpecs { get; private set; }
public IEnumerable<Type> RegisteredTypes
{
get
{
return ApplicationContextCollectionSpecs
.Select(it => it.EntityType);
}
}
private void BuildApplicationContextCollectionSpecs()
{
var contextCollectionProperties = GetContextCollectionProperties();
ApplicationContextCollectionSpecs = contextCollectionProperties
.Select(it => new ApplicationContextCollectionSpec(_errorManager, it))
.ToArray();
var redundantModelTypes = ApplicationContextCollectionSpecs
.GroupBy(it => it.EntityType)
.Where(it => it.Count() > 1);
foreach (var it in redundantModelTypes)
_errorManager.ModelTypeRegisteredRedundant(it.Key);
}
#region Helper
private IEnumerable<PropertyInfo> GetContextCollectionProperties()
{
var contextCollectionProperties = ContextType
.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Select(it => new
{
PropertyInfo = it,
EntityCollectionAttribute = it
.GetCustomAttributes(typeof(EntityCollectionAttribute), true)
.FirstOrDefault()
})
.Where(it => it.EntityCollectionAttribute != null)
.Select(it => it.PropertyInfo);
return contextCollectionProperties;
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.