Пример #1
0
        private void FillArray(Type propType, ImportingProperty importingProperty, IServerModule module, IDictionary <object, IServerModule> facadeProviders)
        {
            var elemType    = propType.GetElementType();
            var facades     = facadeProviders.Keys.Where(elemType.IsInstanceOfType).ToArray();
            var facadeArray = Array.CreateInstance(elemType, facades.Length);

            for (int i = 0; i < facades.Length; i++)
            {
                facadeArray.SetValue(facades[i], i);
            }
            importingProperty.Property.SetValue(module, facadeArray);
        }
Пример #2
0
        private void FillFacade(Type propType, ImportingProperty importingProperty, IServerModule service, IDictionary <object, IServerModule> facadeProviders)
        {
            var match = facadeProviders.Keys.FirstOrDefault(propType.IsInstanceOfType);

            if (match != null)
            {
                importingProperty.Property.SetValue(service, match);
            }
            else if (importingProperty.Attribute.IsOptional)
            {
                _logger.Log(LogLevel.Warning, "Found no module hosting a facade of type {0} which is referenced by {1}.{2}",
                            propType.Name, service.Name, importingProperty.Property);
            }
            else
            {
                _logger.Log(LogLevel.Error, "Found no module hosting a facade of type {0} which is required by {1}.{2}",
                            propType.Name, service.Name, importingProperty.Property);
                importingProperty.Missing = true;
            }
        }