/// <summary> /// This is helper method to get event field value from the <see cref="CompositeEvent{T}"/>. /// </summary> /// <typeparam name="TEvent">The type of the event handler.</typeparam> /// <param name="evt">The <see cref="CompositeEvent{T}"/>.</param> /// <returns>The value of the field holding event handlers.</returns> ///// <exception cref="InvalidOperationException">If the event represented by given <see cref="CompositeEvent{T}"/> is not stored using strong references.</exception> ///// <seealso cref="Qi4CS.Core.API.Model.EventStorage"/> ///// <seealso cref="Qi4CS.Core.API.Model.EventStorageStyleAttribute"/> public static TEvent GetEventFieldValue <TEvent>(this CompositeEvent <TEvent> evt) where TEvent : class { //// TODO this should actually be a method of CompositeEvent interfaces. Since it is not possible to write this same method cleanly as extension method for CompositeEvent (without the generic parameter) //if ( ( (CompositeEventSPI) evt ).Model.GetEventStorageKind() != Qi4CS.Core.API.Model.EventStorage.STRONG_REFS ) //{ // throw new InvalidOperationException( "Getting field value of event is only possible for events stored as strong reference." ); //} return(evt.InvokeFunctionWithRef <EventInfo, TEvent>(ReturnParam)); }
/// <summary> /// Invokes the <see cref="CompositeStateParticipant{T}.TryInvokeFunctionWithRef"/> method with given delegate, assuming that field type is same as event type. /// </summary> /// <typeparam name="TEvent">The type of the property.</typeparam> /// <param name="evt">The <see cref="CompositeEvent{T}"/>.</param> /// <param name="function">The delegate to invoke.</param> /// <returns>The result of <paramref name="function"/>.</returns> /// <exception cref="InvalidOperationException">If <see cref="CompositeStateParticipant{T}.TryInvokeFunctionWithRef"/> returns <c>false</c>, that is, when the field type does not match <typeparamref name="TEvent"/>.</exception> /// <remarks> /// TODO link to documentation about how field type is deduced (it is not always the same as type of property or event). /// </remarks> /// <seealso cref="CompositeStateParticipant{T}.TryInvokeFunctionWithRef"/> public static TEvent InvokeFunctionWithRefSameType <TEvent>(this CompositeEvent <TEvent> evt, FunctionWithRef <TEvent> function) where TEvent : class { return(evt.InvokeFunctionWithRef(function)); }