private void ProcessPropertyAttributes()
        {
            foreach (PropertyInfo runtimeProperty in _exportType.GetRuntimeProperties())
            {
                List<IExportCondition> exportConditions = new List<IExportCondition>();
                List<IExportAttribute> exportAttributes = new List<IExportAttribute>();
                IImportAttribute importAttribute = null;
                bool importAfterConstruction = false;
                object comparer = null;
                ExportStrategyFilter filter = null;

                foreach (Attribute customAttribute in runtimeProperty.GetCustomAttributes())
                {
                    if (customAttribute is IImportAttribute)
                    {
                        importAttribute = customAttribute as IImportAttribute;
                    }

                    IImportFilterAttribute filterAttribute = customAttribute as IImportFilterAttribute;

                    if (filterAttribute != null)
                    {
                        filter = filterAttribute.ProvideFilter(_exportType, runtimeProperty.Name);
                    }

                    IImportSortCollectionAttribute sortAttribute = customAttribute as IImportSortCollectionAttribute;

                    if (sortAttribute != null)
                    {
                        comparer = sortAttribute.ProvideComparer(_exportType, runtimeProperty.Name);
                    }

                    IExportAttribute exportAttribute = customAttribute as IExportAttribute;

                    if (exportAttribute != null)
                    {
                        exportAttributes.Add(exportAttribute);
                    }

                    IExportConditionAttribute conditionAttribute = customAttribute as IExportConditionAttribute;

                    if (conditionAttribute != null)
                    {
                        IExportCondition condition = conditionAttribute.ProvideCondition(runtimeProperty.PropertyType);

                        if (condition != null)
                        {
                            exportConditions.Add(condition);
                        }
                    }

                    IImportAfterConstructionAttribute afterConstruction = customAttribute as IImportAfterConstructionAttribute;

                    if (afterConstruction != null)
                    {
                        importAfterConstruction = afterConstruction.ImportAfterConstruction(_exportType, runtimeProperty.PropertyType);
                    }
                }

                foreach (IExportAttribute exportAttribute in exportAttributes)
                {
                    IEnumerable<string> propertyExportNames = exportAttribute.ProvideExportNames(_exportType);
                    IEnumerable<Type> propertyExportTypes = exportAttribute.ProvideExportTypes(_exportType);

                    IExportCondition condition = null;

                    if (exportConditions.Count > 0)
                    {
                        condition = new MultipleConditions(exportConditions.ToArray());
                    }

                    ExportPropertyInfo exportPropertyInfo = new ExportPropertyInfo
                                                                         {
                                                                             ExportCondition = condition,
                                                                             ExportNames = propertyExportNames,
                                                                             ExportTypes = propertyExportTypes,
                                                                             PropertyInfo = runtimeProperty
                                                                         };

                    ExportProperty(exportPropertyInfo);
                }

                if (importAttribute != null && runtimeProperty.CanWrite)
                {
                    ImportAttributeInfo attributeInfo =
                        importAttribute.ProvideImportInfo(_exportType, runtimeProperty.Name);

                    if (filter == null)
                    {
                        filter = attributeInfo.ExportStrategyFilter;
                    }

                    if (comparer == null)
                    {
                        comparer = attributeInfo.Comparer;
                    }

                    if (attributeInfo.ImportKey != null)
                    {
                        ExportStrategyFilter keyFilter =
                            (context, strategy) => IExportLocatorExtensions.CompareKeyFunction(attributeInfo.ImportKey, context, strategy);

                        filter = filter != null ?
                                    new ExportStrategyFilterGroup(keyFilter, filter) : keyFilter;
                    }

                    ImportPropertyInfo importPropertyInfo = new ImportPropertyInfo
                                                                         {
                                                                             ComparerObject = comparer,
                                                                             ExportStrategyFilter = filter,
                                                                             ImportName = attributeInfo.ImportName,
                                                                             IsRequired = attributeInfo.IsRequired,
                                                                             Property = runtimeProperty,
                                                                             ValueProvider = attributeInfo.ValueProvider,
                                                                             AfterConstruction = importAfterConstruction
                                                                         };

                    ImportProperty(importPropertyInfo);
                }
            }
        }
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="exportPropertyInfo">property info to export</param>
        /// <param name="strategy">export strategy</param>
        public FluentExportPropertyConfiguration(ExportPropertyInfo exportPropertyInfo,
			IFluentExportStrategyConfiguration strategy)
            : base(strategy)
        {
            this.exportPropertyInfo = exportPropertyInfo;
        }
Esempio n. 3
0
        public void ExportProperty(ExportPropertyInfo exportPropertyInfo)
        {
            PropertyExportStrategy propertyExportStrategy = new PropertyExportStrategy(exportPropertyInfo.PropertyInfo,
                this,
                exportPropertyInfo.ExportCondition);

            if (exportPropertyInfo.ExportNames != null)
            {
                foreach (string exportName in exportPropertyInfo.ExportNames)
                {
                    propertyExportStrategy.AddExportName(exportName);
                }
            }

            if (exportPropertyInfo.ExportTypes != null)
            {
                foreach (Type type in exportPropertyInfo.ExportTypes)
                {
                    propertyExportStrategy.AddExportType(type);
                }
            }

            AddSecondaryExport(propertyExportStrategy);
        }
        /// <summary>
        /// Export a property by name
        /// </summary>
        /// <param name="propertyName"></param>
        /// <returns></returns>
        public IFluentExportPropertyConfiguration ExportProperty(string propertyName)
        {
            PropertyInfo propertyInfo =
                exportType.GetTypeInfo().GetDeclaredProperty(propertyName);

            ExportPropertyInfo exportPropertyInfo = new ExportPropertyInfo
            {
                PropertyInfo = propertyInfo
            };

            exportStrategy.ExportProperty(exportPropertyInfo);

            return new FluentExportPropertyConfiguration(exportPropertyInfo, this);
        }