Exemplo n.º 1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="participant">Required.</param>
 public VariantParticipant(IComposerParticipant <TSuper> participant)
 {
     Participant = participant ?? throw new ArgumentNullException(nameof(participant));
     if (Participant is IRequestComposition <TTarget> requestComposition)
     {
         requestComposition.CompositionRequested += handleCompositionRequested;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// This protected virtual method raises the
 /// <see cref="IRequestComposition{TTarget}.CompositionRequested"/>
 /// event.
 /// </summary>
 /// <param name="participant">Optional parameter for a new
 /// <see cref="RequestCompositionEventArgs{TTarget}"/>: notice that if this is not null,
 /// the <paramref name="request"/> must be set..</param>
 /// <param name="request">Optional parameter for a new
 /// <see cref="RequestCompositionEventArgs{TTarget}"/>.</param>
 protected virtual void RaiseCompositionRequested(
     IComposerParticipant <ContainerConfiguration> participant = null,
     RequestCompositionEventArgs <ContainerConfiguration> .ParticipantRequest request
     = RequestCompositionEventArgs <ContainerConfiguration> .ParticipantRequest.None)
 => CompositionRequested?.Invoke(
     this,
     participant != null
                                                 ? new RequestCompositionEventArgs <ContainerConfiguration>(participant, request)
                                                 : new RequestCompositionEventArgs <ContainerConfiguration>());
Exemplo n.º 3
0
 /// <summary>
 /// Constructor sets the <see cref="Participant"/>; and the
 /// <see cref="Request"/>.
 /// </summary>
 /// <param name="participant">Required in this constructor.</param>
 /// <param name="request">Required in this constructor; and must not be
 /// <see cref="ParticipantRequest.None"/>.</param>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="InvalidEnumArgumentException"></exception>
 public RequestCompositionEventArgs(IComposerParticipant <TTarget> participant, ParticipantRequest request)
 {
     if (!Enum.IsDefined(typeof(ParticipantRequest), request) ||
         (request == ParticipantRequest.None))
     {
         throw new InvalidEnumArgumentException(nameof(request), (int)request, typeof(ParticipantRequest));
     }
     Participant = participant ?? throw new ArgumentNullException(nameof(participant));
     Request     = request;
 }
Exemplo n.º 4
0
        /// <summary>
        /// This helper method will check and construct a new variant participant, that
        /// implements the composer's covariant type, and contributes all supported interfaces to
        /// the composer. Since this will construct a new participant, the actual
        /// added instance is returned here.
        /// </summary>
        /// <typeparam name="TSuper">The delegate's actual type.</typeparam>
        /// <typeparam name="TTarget">This composer's implemented type.</typeparam>
        /// <param name="composer">Required.</param>
        /// <param name="participant">Required.</param>
        /// <param name="oneTimeOnly">Optional.</param>
        /// <returns>The actual added instance.</returns>
        /// <exception cref="ArgumentNullException"/>
        public static VariantParticipant <TSuper, TTarget> ParticipateAs <TSuper, TTarget>(
            this IComposer <TTarget> composer,
            IComposerParticipant <TSuper> participant,
            bool oneTimeOnly = false)
            where TTarget : TSuper
        {
            if (composer == null)
            {
                throw new ArgumentNullException(nameof(composer));
            }
            VariantParticipant <TSuper, TTarget> variantParticipant
                = new VariantParticipant <TSuper, TTarget>(participant);

            composer.Participate(variantParticipant, oneTimeOnly);
            return(variantParticipant);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Removes the participant.
 /// </summary>
 /// <param name="participant">Not null.</param>
 /// <returns>False if the argument is not found.</returns>
 /// <exception cref="ArgumentNullException"/>
 public bool Remove(IComposerParticipant <TTarget> participant)
 {
     if (participant == null)
     {
         throw new ArgumentNullException(nameof(participant));
     }
     lock (Participants) {
         if (participant is IRequestComposition <TTarget> requestComposition)
         {
             requestComposition.CompositionRequested -= HandleParticipantCompositionRequested;
         }
         if (!Participants.Remove(participant))
         {
             return(false);
         }
         HandleParticipantRemoved(participant);
         return(true);
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Adds the participant.
 /// </summary>
 /// <param name="participant">Not null.</param>
 /// <returns>False if the argument is already added.</returns>
 /// <exception cref="ArgumentNullException"/>
 public bool Add(IComposerParticipant <TTarget> participant)
 {
     if (participant == null)
     {
         throw new ArgumentNullException(nameof(participant));
     }
     lock (Participants) {
         checkDisposed();
         if (Participants.Contains(participant))
         {
             return(false);
         }
         Participants.Add(participant);
         if (participant is IRequestComposition <TTarget> requestComposition)
         {
             requestComposition.CompositionRequested -= HandleParticipantCompositionRequested;
             requestComposition.CompositionRequested += HandleParticipantCompositionRequested;
         }
         HandleParticipantAdded(participant);
         return(true);
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Will be invoked with each removed participant, while holding the sync lock.
 /// </summary>
 /// <param name="removedParticipant">Not null.</param>
 protected virtual void HandleParticipantRemoved(IComposerParticipant <TTarget> removedParticipant)
 {
 }
Exemplo n.º 8
0
 /// <summary>
 /// Will be invoked with each added participant, while holding the sync lock.
 /// </summary>
 /// <param name="addedParticipant">Not null.</param>
 protected virtual void HandleParticipantAdded(IComposerParticipant <TTarget> addedParticipant)
 {
 }
Exemplo n.º 9
0
 public bool Equals(IComposerParticipant <TSuper> other)
 => (other != null) &&
 object.ReferenceEquals(Participant, other);
Exemplo n.º 10
0
 public bool Equals(IComposerParticipant <TTarget> other)
 => Equals(other as VariantParticipant <TSuper, TTarget>);