/// <summary>
        /// Initialises a new instance of <see cref="WidgetContext"/>.
        /// </summary>
        /// <param name="widgetDescriptor">The widget descriptor.</param>
        /// <param name="values">The set of provided invocation values.</param>
        /// <param name="viewContext">The view context.</param>
        /// <param name="writer">The text writer.</param>
        public WidgetContext(WidgetDescriptor widgetDescriptor, RouteValueDictionary values, ViewContext viewContext, TextWriter writer)
        {
            if (widgetDescriptor == null)
            {
                throw new ArgumentNullException(nameof(widgetDescriptor));
            }

            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            if (viewContext == null)
            {
                throw new ArgumentNullException(nameof(viewContext));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            WidgetDescriptor = widgetDescriptor;
            Values = values;

            ViewContext = new ViewContext(
                viewContext,
                viewContext.View,
                new ViewDataDictionary(viewContext.ViewData),
                writer);
        }
        /// <summary>
        /// Invokes a widget synchronously.
        /// </summary>
        /// <param name="writer">The target text writer.</param>
        /// <param name="descriptor">The widget descriptor.</param>
        /// <param name="values">The set of values to provide to the widget.</param>
        private void InvokeCore(TextWriter writer, WidgetDescriptor descriptor, object values = null)
        {
            var context = new WidgetContext(descriptor, new RouteValueDictionary(values), _viewContext, writer);
            var invoker = _invokerFactory.CreateInstance(context);

            invoker.Invoke(context);
        }
Пример #3
0
        /// <summary>
        /// Initialises a new instance of <see cref="WidgetContext"/>.
        /// </summary>
        /// <param name="widgetDescriptor">The widget descriptor.</param>
        /// <param name="values">The set of provided invocation values.</param>
        /// <param name="viewContext">The view context.</param>
        /// <param name="writer">The text writer.</param>
        public WidgetContext(WidgetDescriptor widgetDescriptor, RouteValueDictionary values, ViewContext viewContext, TextWriter writer)
        {
            if (widgetDescriptor == null)
            {
                throw new ArgumentNullException(nameof(widgetDescriptor));
            }

            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            if (viewContext == null)
            {
                throw new ArgumentNullException(nameof(viewContext));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            WidgetDescriptor = widgetDescriptor;
            Values           = values;

            ViewContext = new ViewContext(
                viewContext,
                viewContext.View,
                new ViewDataDictionary(viewContext.ViewData),
                writer);
        }
        /// <summary>
        /// Creates a descriptor for the given widget type.
        /// </summary>
        /// <param name="typeInfo">The widget type.</param>
        /// <returns>The widget descriptor.</returns>
        private static WidgetDescriptor CreateDescriptor(TypeInfo typeInfo)
        {
            var descriptor = new WidgetDescriptor
            {
                FullName = WidgetConventions.GetWidgetFullName(typeInfo),
                ShortName = WidgetConventions.GetWidgetName(typeInfo),
                Type = typeInfo.AsType()
            };

            return descriptor;
        }
Пример #5
0
        /// <summary>
        /// Creates a descriptor for the given widget type.
        /// </summary>
        /// <param name="typeInfo">The widget type.</param>
        /// <returns>The widget descriptor.</returns>
        private static WidgetDescriptor CreateDescriptor(TypeInfo typeInfo)
        {
            var descriptor = new WidgetDescriptor
            {
                FullName  = WidgetConventions.GetWidgetFullName(typeInfo),
                ShortName = WidgetConventions.GetWidgetName(typeInfo),
                Type      = typeInfo.AsType()
            };

            return(descriptor);
        }
 /// <summary>
 /// Initialises a new instance of <see cref="WidgetContext"/>.
 /// </summary>
 public WidgetContext()
 {
     WidgetDescriptor = new WidgetDescriptor();
     Values = new RouteValueDictionary();
     ViewContext = new ViewContext();
 }
        /// <summary>
        /// Invokes a widget synchronously.
        /// </summary>
        /// <param name="writer">The target text writer.</param>
        /// <param name="descriptor">The widget descriptor.</param>
        /// <param name="values">The set of values to provide to the widget.</param>
        private void InvokeCore(TextWriter writer, WidgetDescriptor descriptor, object values = null)
        {
            var context = new WidgetContext(descriptor, new RouteValueDictionary(values), _viewContext, writer);
            var invoker = _invokerFactory.CreateInstance(context);

            invoker.Invoke(context);
        }
Пример #8
0
 /// <summary>
 /// Initialises a new instance of <see cref="WidgetContext"/>.
 /// </summary>
 public WidgetContext()
 {
     WidgetDescriptor = new WidgetDescriptor();
     Values           = new RouteValueDictionary();
     ViewContext      = new ViewContext();
 }