Esempio n. 1
0
            /// <summary>
            ///   Raises either the Changing or Changed event. </summary>
            /// <param name="changing">
            ///   If true, the Changing event is raised otherwise it's Changed. </param>
            /// <param name="changeType">
            ///   The type of change being made. </param>
            /// <param name="section">
            ///   The name of the section that was involved in the change or null if not applicable. </param>
            /// <param name="entry">
            ///   The name of the entry that was involved in the change or null if not applicable. 
            ///   If changeType is equal to Other, entry is the name of the property involved in the change.</param>
            /// <param name="value">
            ///   The value that was changed or null if not applicable. </param>
            /// <returns>
            ///   The return value is based on the event raised.  If the Changing event was raised, 
            ///   the return value is the opposite of ProfileChangingArgs.Cancel; otherwise it's true.</returns>
            /// <remarks>
            ///   This method may be used by derived classes as a convenient alternative to calling 
            ///   OnChanging and OnChanged.  For example, a typical call to OnChanging would require
            ///   four lines of code, which this method reduces to two. </remarks>
            /// <seealso cref="Changing" />
            /// <seealso cref="Changed" />
            /// <seealso cref="OnChanging" />
            /// <seealso cref="OnChanged" />
            protected bool RaiseChangeEvent(bool changing, ProfileChangeType changeType, string section, string entry, object value)
            {
                if (changing)
                {
                    // Don't even bother if there are no handlers.
                    if (Changing == null)
                        return true;

                    ProfileChangingArgs e = new ProfileChangingArgs(changeType, section, entry, value);
                    OnChanging(e);
                    return !e.Cancel;
                }

                // Don't even bother if there are no handlers.
                if (Changed != null)
                    OnChanged(new ProfileChangedArgs(changeType, section, entry, value));
                return true;
            }
Esempio n. 2
0
            /// <summary>
            ///   Raises the Changing event. </summary>
            /// <param name="e">
            ///   The arguments object associated with the Changing event. </param>
            /// <remarks>
            ///   This method should be invoked prior to making a change to the profile so that the
            ///   Changing event is raised, giving a chance to the handlers to prevent the change from
            ///   happening (by setting e.Cancel to true). This method calls each individual handler 
            ///   associated with the Changing event and checks the resulting e.Cancel flag.  
            ///   If it's true, it stops and does not call of any remaining handlers since the change 
            ///   needs to be prevented anyway. </remarks>
            /// <seealso cref="Changing" />
            /// <seealso cref="OnChanged" />
            protected virtual void OnChanging(ProfileChangingArgs e)
            {
                if (Changing == null)
                    return;

                foreach (ProfileChangingHandler handler in Changing.GetInvocationList())
                {
                    handler(this, e);

                    // If a particular handler cancels the event, stop
                    if (e.Cancel)
                        break;
                }
            }