/// <summary>
        /// Creates a component-state item, which gives you a hidden-field value that you can access while building the page.
        /// </summary>
        /// <param name="id">The ID of this state item, which must be unique within the page or current ID context. Do not pass null or the empty string.</param>
        /// <param name="durableValue">The current value of this state item in persistent storage. For transient state that is used only to support intermediate
        /// post-backs, pass the default value.</param>
        /// <param name="valueValidator">A predicate that takes a value and returns true if it is valid for this state item. Used primarily to validate post-back
        /// values.</param>
        /// <param name="durableValueUpdateValidationMethod">The validation method, which you should use to update the durable value, if this is necessary. Pass
        /// null for transient state that is used only to support intermediate post-backs.</param>
        public static ComponentStateItem <T> Create <T>(
            string id, T durableValue, Func <T, bool> valueValidator, Action <T, Validator> durableValueUpdateValidationMethod = null)
        {
            creationTimeAsserter();

            id = elementOrIdentifiedComponentIdGetter().AppendDelimiter("_") + id;
            var item = new ComponentStateItem <T>(durableValue, valueGetter(id), valueValidator, durableValueUpdateValidationMethod, dataModificationGetter());

            itemAdder(id, item);
            return(item);
        }
Пример #2
0
        /// <summary>
        /// Creates a component-state item, which gives you a hidden-field value that you can access while building the page.
        /// </summary>
        /// <param name="id">The ID of this state item, which must be unique within the page or current ID context. Do not pass null or the empty string.</param>
        /// <param name="durableValue">The current value of this state item in persistent storage. For transient state that is used only to support intermediate
        /// post-backs, pass the default value.</param>
        /// <param name="valueValidator">A predicate that takes a value and returns true if it is valid for this state item. Used primarily to validate post-back
        /// values.</param>
        /// <param name="includeInChangeDetection">Pass true to include this state item in change detection for the current data modifications. This is necessary
        /// when the value of this state item affects what will be persisted by the data modifications. For transient state that is used only to support
        /// intermediate post-backs, pass false.</param>
        public static ComponentStateItem <T> Create <T>(string id, T durableValue, Func <T, bool> valueValidator, bool includeInChangeDetection)
        {
            creationTimeAsserter();

            id = elementOrIdentifiedComponentIdGetter().AppendDelimiter("_") + id;
            var item = new ComponentStateItem <T>(
                durableValue,
                valueGetter(id),
                valueValidator,
                includeInChangeDetection ? dataModificationGetter() : Enumerable.Empty <DataModification>().Materialize());

            itemAdder(id, item);
            return(item);
        }