Exemplo n.º 1
0
 public static string Display <T>(this System.Collections.Generic.IEnumerable <T> o)
 {
     if (o.Count() <= 0)
     {
         return("");
     }
     return(o.Aggregate(" ", (a, b) => a + ", " + b).Substring(2));
 }
Exemplo n.º 2
0
        public static IHtmlString ParseShortcodes(this HtmlHelper htmlHelper, string content)
        {
            System.Collections.Generic.IEnumerable <IShortcodeParser> shortcodeParsers = MrCMSApplication.GetAll <IShortcodeParser>();

            content = shortcodeParsers.Aggregate(content, (current, shortcodeParser) => shortcodeParser.Parse(htmlHelper, current));

            return(new HtmlString(content));
        }
        public Task BindModelAsync(ModelBindingContext bindingContext)
        {
            if (bindingContext is null)
            {
                throw new ArgumentNullException(nameof(bindingContext));
            }

            // Only accept enum values
            if (!bindingContext.ModelMetadata.IsFlagsEnum)
            {
                return(CompletedTask);
            }

            ValueProviderResult provideValue = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);

            // Do nothing if there is no actual values
            if (provideValue == ValueProviderResult.None)
            {
                return(CompletedTask);
            }

            // Get the real enum type
            Type enumType = bindingContext.ModelType;

            enumType = Nullable.GetUnderlyingType(enumType) ?? enumType;

            // Each value self may contains a series of actual values, split it with comma
            System.Collections.Generic.IEnumerable <string> strs = provideValue.Values.SelectMany(s => s.Split(','));

            // Convert all items into enum items.
            System.Collections.Generic.IEnumerable <object> actualValues = strs.Select(valueString => Enum.Parse(enumType, valueString));

            // Merge to final result
            int result = actualValues.Aggregate(0, (current, value) => current | (int)value);

            // Convert to Enum object
            object realResult = Enum.ToObject(enumType, result);

            // Result
            bindingContext.Result = ModelBindingResult.Success(realResult);

            return(CompletedTask);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Sum of the double collection
 /// </summary>
 /// <param name="source">Current collection</param>
 /// <returns>The sum of the elements</returns>
 public static double Sum1(this System.Collections.Generic.IEnumerable <double> source)
 {
     return(source.Aggregate((x, y) => x + y));
 }