Пример #1
0
        /// <summary>
        /// Return an IFormatter by invoking the factory function associated
        /// with the given FormatterUsage or FormatterUsage.Default if not registered.
        /// </summary>
        /// <param name="formatterUsage">The specific formatter</param>
        /// <returns>An IFormatter instance provided by the </returns>
        public virtual IFormatter CreateFormatter(FormatterUsage formatterUsage)
        {
            var formatter = _registry.CanResolve <IFormatter>(formatterUsage.ToString())
                ? _registry.Resolve <IFormatter>(formatterUsage.ToString())
                : _registry.Resolve <IFormatter>(FormatterUsage.Default.ToString());

            if (formatterUsage == FormatterUsage.Journal && PacketOptions != null)
            {
                formatter = new PacketingFormatter(formatter, PacketOptions.Value);
            }

            return(formatter);
        }
Пример #2
0
        /// <summary>
        /// Return an IFormatter by invoking the factory function associated
        /// with the given FormatterUsage or FormatterUsage.Default if not registered.
        /// </summary>
        /// <param name="formatterUsage">The specific formatter</param>
        /// <returns>An IFormatter instance provided by the </returns>
        public virtual IFormatter CreateFormatter(FormatterUsage formatterUsage)
        {
            var formatter = Registry.CanResolve <IFormatter>(formatterUsage.ToString())
                ? Registry.Resolve <IFormatter>(formatterUsage.ToString())
                : Registry.Resolve <IFormatter>(FormatterUsage.Default.ToString());

            if (_binder != null && formatter is BinaryFormatter)
            {
                ((BinaryFormatter)formatter).Binder = _binder;
            }

            if (formatterUsage == FormatterUsage.Journal && PacketOptions != null)
            {
                formatter = new PacketingFormatter(formatter, PacketOptions.Value);
            }
            return(formatter);
        }
Пример #3
0
 /// <summary>
 /// Inject a custom IFormatter factory.
 /// </summary>
 /// <param name="factory">Function that provides an IFormatter</param>
 /// <param name="formatterUsage">What type of objects to format</param>
 public void SetFormatterFactory(Func <EngineConfiguration, FormatterUsage, IFormatter> factory, FormatterUsage formatterUsage = FormatterUsage.Default)
 {
     Register(args => factory.Invoke(this, formatterUsage), formatterUsage.ToString());
 }
Пример #4
0
 public void UseFormatter <T>() where T : IFormatter
 {
     _formatterUsage = FormatterUsage.selected;
     _selectedFormatterTypes.Fill(typeof(T));
 }
Пример #5
0
 public void UseNoFormatters()
 {
     _formatterUsage = FormatterUsage.none;
     _selectedFormatterTypes.Clear();
 }
Пример #6
0
 public void UseAllFormatters()
 {
     _formatterUsage = FormatterUsage.all;
     _selectedFormatterTypes.Clear();
 }