/// <summary>
        /// Processes the value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="context">The context.</param>
        /// <param name="chainContext">The chain context.</param>
        /// <returns>
        /// The <see cref="object" /> representing the processed value.
        /// </returns>
        internal virtual object ProcessValue(
            object value,
            DittoProcessorContext context,
            DittoChainContext chainContext)
        {
            if (value != null && this.ValueType.IsInstanceOfType(value) == false)
            {
                throw new ArgumentException($"Expected a value argument of type {this.ValueType} but got {value.GetType()}", "value");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (this.ContextType.IsInstanceOfType(context) == false)
            {
                throw new ArgumentException($"Expected a context argument of type {this.ContextType} but got {context.GetType()}", "context");
            }

            if (chainContext == null)
            {
                throw new ArgumentNullException("chainContext");
            }

            this.Value        = value;
            this.Context      = context;
            this.ChainContext = chainContext;

            var ctx = new DittoCacheContext(this, context.Content, context.TargetType, context.PropertyInfo, context.Culture);

            return(this.GetCacheItem(ctx, this.ProcessValue));
        }
Esempio n. 2
0
 /// <summary>
 /// Adds the context.
 /// </summary>
 /// <param name="context">The context.</param>
 public void AddContext(DittoProcessorContext context)
 {
     this.lookup.AddOrUpdate(context.GetType(), context.Populate(content, targetType, propertyDescriptor, culture), (type, ctx) => ctx); // Don't override if already exists
 }
Esempio n. 3
0
 /// <summary>
 /// Adds a processor context to the collection chain.
 /// </summary>
 /// <param name="ctx">The processor context.</param>
 public void Add(DittoProcessorContext ctx)
 {
     _processorContexts.AddOrUpdate(ctx.GetType(), ctx, (type, ctx2) => ctx2); // Don't override if already exists
 }
        /// <summary>
        /// Processes the value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="context">The context.</param>
        /// <returns>
        /// The <see cref="object" /> representing the processed value.
        /// </returns>
        internal virtual object ProcessValue(
            object value,
            DittoProcessorContext context)
        {
            if (value != null && !ValueType.IsInstanceOfType(value))
            {
                throw new ArgumentException("Expected a value argument of type " + ValueType + " but got " + value.GetType(), "value");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (!ContextType.IsInstanceOfType(context))
            {
                throw new ArgumentException("Expected a context argument of type " + ContextType + " but got " + context.GetType(), "context");
            }

            Value   = value;
            Context = context;

            var ctx = new DittoCacheContext(this, context.Content, context.TargetType, context.PropertyDescriptor, context.Culture);

            return(this.GetCacheItem(ctx, this.ProcessValue));
        }