예제 #1
0
 /// <summary>
 /// Adds constructor parameter to the definition
 /// </summary>
 /// <param name="constructorParamInfo"></param>
 public void WithCtorParam(ConstructorParamInfo constructorParamInfo)
 {
     delegateInfo.AddConstructorParamInfo(constructorParamInfo);
 }
        private void ProcessConstructors()
        {
            if (_exportType.GetTypeInfo().DeclaredConstructors.Count() > 1)
            {
                ConstructorInfo exportConstructor = null;

                foreach (ConstructorInfo declaredConstructor in _exportType.GetTypeInfo().DeclaredConstructors)
                {
                    if (declaredConstructor.GetCustomAttributes().FirstOrDefault(x => x is IImportAttribute) != null)
                    {
                        exportConstructor = declaredConstructor;
                    }
                }

                if (exportConstructor != null)
                {
                    ImportConstructor(exportConstructor);

                    foreach (ParameterInfo parameterInfo in exportConstructor.GetParameters())
                    {
                        IImportAttribute importAttribute = null;
                        ExportStrategyFilter filter = null;
                        object comparer = null;

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

                            if (customAttribute is IImportFilterAttribute)
                            {
                                filter = ((IImportFilterAttribute)customAttribute).
                                    ProvideFilter(parameterInfo.ParameterType, parameterInfo.Name);
                            }

                            if (customAttribute is IImportSortCollectionAttribute)
                            {
                                comparer = ((IImportSortCollectionAttribute)customAttribute).
                                    ProvideComparer(parameterInfo.ParameterType, parameterInfo.Name);
                            }
                        }

                        if (importAttribute != null || filter != null || comparer != null)
                        {
                            IExportValueProvider valueProvider = null;
                            string importName = null;
                            bool isRequired = true;

                            if (importAttribute != null)
                            {
                                ImportAttributeInfo attributeInfo =
                                    importAttribute.ProvideImportInfo(parameterInfo.ParameterType, parameterInfo.Name);

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

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

                                importName = attributeInfo.ImportName;
                                isRequired = attributeInfo.IsRequired;
                                valueProvider = attributeInfo.ValueProvider;
                            }

                            ConstructorParamInfo constructorParamInfo = new ConstructorParamInfo
                                                                                      {
                                                                                          ComparerObject = comparer,
                                                                                          ExportStrategyFilter = filter,
                                                                                          ImportName = importName,
                                                                                          IsRequired = isRequired,
                                                                                          ParameterName = parameterInfo.Name,
                                                                                          ParameterType = parameterInfo.ParameterType,
                                                                                          ValueProvider = valueProvider
                                                                                      };

                            WithCtorParam(constructorParamInfo);
                        }
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Adds a constructor parameter info
        /// </summary>
        /// <param name="paramInfo"></param>
        public void AddConstructorParamInfo(ConstructorParamInfo paramInfo)
        {
            if (_constructorParamInfos == null)
            {
                _constructorParamInfos = new List<ConstructorParamInfo>(1);
            }

            _constructorParamInfos.Add(paramInfo);
        }