/// <summary>
 /// Создать описатель.
 /// </summary>
 public override ActivePartInfo CreateElement(ExtensionAttachmentContext context, ActivePartAttribute attr)
 {
     //if (!typeof(IActivePart).IsAssignableFrom(context.Type))
     //	throw new ExtensibilityException(
     //		$"Type \'{context.Type}\' must implement interface \'{typeof(IActivePart)}");
     Debug.Assert(context.Type.AssemblyQualifiedName != null, "context.Type.AssemblyQualifiedName != null");
     return(new ActivePartInfo(context.Type.AssemblyQualifiedName));
 }
Example #2
0
 public override TInfo CreateElement(
     ExtensionAttachmentContext context,
     TAttr attr)
 {
     if (_elementType != null && !_elementType.IsAssignableFrom(context.Type))
     {
         throw new ExtensibilityException($"Type \'{context.Type}\' must inherit/implement \'{_elementType}\'");
     }
     return(_creator(context, attr));
 }
 private void Scan(Assembly asm, IEnumerable <Type> types, IExtensionAttachmentStrategy strategy)
 {
     foreach (var type in types)
     {
         var ctx = new ExtensionAttachmentContext(ServiceContainer, this, asm, type);
         foreach (var attr in CustomAttributeData.GetCustomAttributes(type))
         {
             strategy.Attach(ctx, attr);
         }
     }
 }
 /// <summary>
 /// Создать элемент.
 /// </summary>
 public override ExtensionStrategyFactoryInfo CreateElement(
     ExtensionAttachmentContext context,
     ExtensionStrategyFactoryAttribute attr)
 {
     if (!typeof(IExtensionStrategyFactory).IsAssignableFrom(context.Type))
     {
         throw new InvalidExtensionTypeException(
                   $"Strategy factory must implement '{typeof (IExtensionStrategyFactory)}' interface");
     }
     return(new ExtensionStrategyFactoryInfo(context.Type));
 }
Example #5
0
        /// <summary>
        /// Подключает расширение.
        /// </summary>
        protected override void Attach(ExtensionAttachmentContext context, ServiceAttribute attribute)
        {
            // Single instance for all contracts
            var holder = new ServiceHolder(context.Type);

            foreach (var contract in attribute.ContractTypes)
            {
                _publisher.Publish(
                    contract,
                    pub => holder.CreateInstance(_publisher));
            }
        }
        /// <summary>
        /// Сканирует сборку.
        /// </summary>
        public void Scan(IExtensionAttachmentStrategy strategy, [NotNull] params Assembly[] assemblies)
        {
            if (strategy == null)
            {
                throw new ArgumentNullException(nameof(strategy));
            }
            if (assemblies == null)
            {
                throw new ArgumentNullException(nameof(assemblies));
            }

            foreach (var asm in assemblies)
            {
                var ctx = new ExtensionAttachmentContext(ServiceContainer, this, asm);
                foreach (var attr in CustomAttributeData.GetCustomAttributes(asm))
                {
                    strategy.Attach(ctx, attr);
                }
                Scan(asm, asm.GetTypes(), strategy);
            }
        }
 /// <summary>
 /// Создать элемент.
 /// </summary>
 public override TestNamedElementInfo CreateElement(
     ExtensionAttachmentContext context,
     TestNamedElementAttribute attr)
 {
     return(new TestNamedElementInfo(attr.Name, context.Type));
 }
 /// <summary>
 /// Подключает расширение.
 /// </summary>
 protected override void Attach(ExtensionAttachmentContext context, SimpleExtensionAttribute attribute)
 {
     _lastExtensionTypeName = context.Type.AssemblyQualifiedName;
 }