Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ComputedValue{T}"/> class.
        /// </summary>
        /// <param name="sharedState">The shared state this computedValue is connected to.</param>
        /// <param name="options">An <see cref="ComputedValueOptions{T}"/> instance that define the options for this computed value.</param>
        public ComputedValue(ISharedState sharedState, ComputedValueOptions <T> options)
        {
            if (sharedState is null)
            {
                throw new ArgumentNullException(nameof(sharedState));
            }

            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this.Name        = options.Name;
            this.derivation  = options.Getter;
            this.SharedState = sharedState;

            if (options.Setter != null)
            {
                this.setter = sharedState.CreateAction($"{options.Name}-setter", options.Context, options.Setter);
            }

            this.scope            = options.Context;
            this.equalityComparer = options.EqualityComparer;
            this.keepAlive        = options.KeepAlive;
            this.requiresReaction = options.RequiresReaction;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ComputedValue{T}"/> class.
        /// </summary>
        /// <param name="sharedState">The shared state this computedValue is connected to.</param>
        /// <param name="options">An <see cref="ComputedValueOptions{T}"/> instance that define the options for this computed value.</param>
        internal ComputedValue(ISharedState sharedState, ComputedValueOptions <T> options)
        {
            // resolve state state from context if necessary.
            this.SharedState = Net.SharedState.ResolveState(sharedState);

            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this.Name       = options.Name;
            this.derivation = options.Getter;

            if (options.Setter != null)
            {
                this.setter = sharedState.CreateAction($"{options.Name}-setter", options.Context, options.Setter);
            }

            this.scope            = options.Context;
            this.equalityComparer = options.EqualityComparer;
            this.keepAlive        = options.KeepAlive;
            this.requiresReaction = options.RequiresReaction;
        }