public Boolean TryInvokeFunctionWithRef <TField>(FunctionWithRef <TField> function, out TField result) { Object resultObj; var retVal = this._refInvoker(function, out resultObj); result = retVal ? (TField)resultObj : default(TField); return(retVal); }
/// <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)); }
/// <summary> /// Invokes the <see cref="CompositeStateParticipant{T}.TryInvokeFunctionWithRef"/> method with given delegate, assuming that field type is same as property type. /// </summary> /// <typeparam name="TProperty">The type of the property.</typeparam> /// <param name="property">The <see cref="CompositeProperty{T}"/>.</param> /// <param name="function">The delegate to invoke.</param> /// <returns>The return value 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="TProperty"/>.</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 TProperty InvokeFunctionWithRefSameType <TProperty>(this CompositeProperty <TProperty> property, FunctionWithRef <TProperty> function) { return(property.InvokeFunctionWithRef(function)); }
/// <summary> /// Helper method to invoke <see cref="CompositeStateParticipant{T}.TryInvokeFunctionWithRef"/> and throw an exception if it returns <c>false</c>. /// </summary> /// <typeparam name="TReflectionInfo">The kind of composite state participant, <see cref="PropertyInfo"/> or <see cref="EventInfo"/>.</typeparam> /// <typeparam name="TField">The presumed type of the field containing composite property or event.</typeparam> /// <param name="stateParticipant">The <see cref="CompositeStateParticipant{T}"/>.</param> /// <param name="function">The delegate to invoke.</param> /// <returns>The return value of 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="TField"/>.</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 TField InvokeFunctionWithRef <TReflectionInfo, TField>(this CompositeStateParticipant <TReflectionInfo> stateParticipant, FunctionWithRef <TField> function) where TReflectionInfo : MemberInfo { TField result; if (!stateParticipant.TryInvokeFunctionWithRef(function, out result)) { ThrowUnmatchedStateParticipantFieldType <TReflectionInfo, TField>(stateParticipant); } return(result); }