Beispiel #1
0
        /// <inheritdoc />
        public CssClassList Create(CssBuilderOptions options = null)
        {
            var cache = options != null
                ? _caches.GetOrAdd(options, CreateCacheForOptions)
                : _defaultCache;

            return(new CssClassList(options ?? _options, cache));
        }
Beispiel #2
0
 /// <summary>
 /// Adds the css builder services to the specified <see cref="IServiceCollection"/>.
 /// </summary>
 /// <param name="serviceCollection">
 /// The <see cref="IServiceCollection"/> to add services to.
 /// </param>
 /// <param name="action">
 /// An <see cref="Action{CssBuilderOptions}"/>  to configure the provided <see cref="CssBuilderOptions"/>.
 /// </param>
 public static void AddCssBuilder(
     this IServiceCollection serviceCollection,
     Action <CssBuilderOptions> action = null)
 {
     serviceCollection.TryAddSingleton <ICssBuilder, CssBuilder>();
     serviceCollection.AddSingleton(p =>
     {
         var options = new CssBuilderOptions();
         action?.Invoke(options);
         return(options);
     });
 }
        internal CssClassList(CssBuilderOptions options, ThreadsafeCssBuilderCache cache)
        {
            _cssClasses = new List <string>();
            _options    = options ?? throw new ArgumentNullException(nameof(options));
            _cache      = cache ?? throw new ArgumentNullException(nameof(cache));

            if (_options.EnumToClassNameConverter == null)
            {
                throw new ArgumentException("Options.EnumToClassNameConverter can't be null.");
            }

            if (_options.PropertyToClassNameConverter == null)
            {
                throw new ArgumentException("Options.PropertyToClassNameConverter can't be null.");
            }
        }
 private CssClassList CreateCssDefinition(CssBuilderOptions options = null)
 {
     return(cssBuilder.Create(options));
 }
Beispiel #5
0
 private static ThreadsafeCssBuilderCache CreateCacheForOptions(CssBuilderOptions arg)
 {
     return(new ThreadsafeCssBuilderCache());
 }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CssBuilder"/> class.
 /// </summary>
 /// <param name="options">An options object which modifies class name generation and other things.</param>
 /// <exception cref="ArgumentNullException">options is null.</exception>
 public CssBuilder(CssBuilderOptions options)
 {
     _options      = options ?? throw new ArgumentNullException(nameof(options));
     _defaultCache = _caches.GetOrAdd(_options, CreateCacheForOptions);
 }