/// <summary> /// Adds specified meta-feature to the store. /// </summary> /// <param name="featureType">Type of feature to add.</param> public void AddMetaFeature(Type featureType) { if (featureType == null) { throw new ArgumentNullException("featureType"); } FeatureAttribute attribute = ReflectionHelper.GetAttribute <FeatureAttribute>(featureType); if (attribute == null) { throw new ArgumentException("featureType must have a FeatureAttribute or derived applied to it."); } Type metaFeatureType = attribute.MetaFeature; Debug.Assert(metaFeatureType != null); ConstructorInfo constructor = metaFeatureType.GetConstructor(new Type[] { typeof(MetaFeatureStore), typeof(Type) }); if (constructor == null) { throw new ArgumentException("MetaFeature type must have a constructor taking MetaFeatureStore and Type arguments."); } MetaFeature metaFeature = constructor.Invoke(new object[] { this, featureType }) as MetaFeature; Debug.Assert(!m_metaFeatures.ContainsKey(metaFeature.FeatureType)); if (!m_metaFeatures.ContainsKey(metaFeature.FeatureType)) { Debug.WriteLine("MetaFeatureStore: Adding meta-feature to the store: " + metaFeature.ToString()); m_metaFeatures[metaFeature.FeatureType] = metaFeature; m_relationshipsDirty = true; } }
public MetaFeature(IMetaFeatureService store, Type featureType) { if (store == null) { throw new ArgumentNullException("store"); } m_store = store; if (featureType == null) { throw new ArgumentNullException("featureType"); } m_featureType = featureType; if (m_featureType.GetInterfaceMap(typeof(IDisposable)).InterfaceType == null) { throw new ArgumentException("featureType runtime type must implement the System.IDisposable interface to be used as a feature type."); } m_featureData = ReflectionHelper.GetAttribute <FeatureAttribute>(m_featureType); if (m_featureData == null) { throw new ArgumentException("featureType must have a FeatureAttribute or derived applied."); } Debug.Assert(m_featureData.MetaFeature == this.GetType()); }
public void AddMetaFeatures(Assembly assembly, Predicate <Type> typeFilter) { foreach (Type featureType in assembly.GetTypes()) { if (!featureType.IsAbstract) { FeatureAttribute attribute = ReflectionHelper.GetAttribute <FeatureAttribute>(featureType); if (attribute != null && (typeFilter == null || typeFilter(featureType))) { AddMetaFeature(featureType); } } } }
private void RebuildRelationships() { m_relationships.Clear(); foreach (MetaFeature metaFeature in m_metaFeatures.Values) { if (metaFeature.FeatureType != typeof(GlobalContext)) { FeatureAttribute attr = ReflectionHelper.GetAttribute <FeatureAttribute>(metaFeature.FeatureType); Debug.Assert(attr != null); AddMetaRelationship( metaFeature, MetaRelationshipKind.Parent, FindMetaFeature(attr.Container)); } } m_relationshipsDirty = false; }