示例#1
0
        public IConfigureRoutingConventions Build(Func <RouteBuilderInfo, IEnumerable <Route> > builder)
#endif
        {
            builder.MustNotBeNull();
            _lambda.Builder = builder;
            _parent.Add((IBuildRoutes)_lambda);
            return(_parent);
        }
 public IConfigureConventions DefaultBuilder(Func<ModelInfo, HtmlTag> action)
 {
     action.MustNotBeNull();
     var lambda = new LambdaConventions(LambdaConventions.AppliesAlways);
     lambda.Builder = action;
     _defaultBuilder = lambda;
     return this;
 }
		public IConfigureRoutingConventions Build(Func<RouteBuilderInfo, IEnumerable<Route>> builder)
#endif
        {
            builder.MustNotBeNull();
            _lambda.Builder = builder;
            _parent.Add((IBuildRoutes)_lambda);
            return _parent;
        }
示例#4
0
        /// <summary>
        ///     Ensures that the specified <paramref name="assertionResult" /> is false, or otherwise throws the specified exception.
        /// </summary>
        /// <param name="assertionResult">The result of an assertion to be checked.</param>
        /// <param name="exception">The delegate that creates the exception to be thrown when the <paramref name="assertionResult" /> is true.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="exception" /> is null.</exception>
        public static void Against(bool assertionResult, Func <Exception> exception)
        {
            exception.MustNotBeNull(nameof(exception));

            if (assertionResult)
            {
                throw exception();
            }
        }
示例#5
0
 /// <summary>
 /// Creates a <see cref="MenuItem"/> from an expression - is meant to be used with a <see cref="MethodCallExpression"/>.
 /// </summary>
 /// <typeparam name="T1">The parameter type of the first method parameter.</typeparam>
 /// <param name="displayString">The explicit "label" to be used for the menu entry.</param>
 /// <param name="action">The expression to create a menu item for.</param>
 /// <param name="suffixForMenu">A suffix for the description of the method (the description will be extracted from the documentation XML file).</param>
 /// <returns>A new menu item.</returns>
 public static MenuItem Print <T1>(string displayString, Func <T1, Task> action, string suffixForMenu = "")
 {
     _ = action.MustNotBeNull(nameof(action));
     return(new MenuItem(displayString + suffixForMenu, async(parameters) =>
     {
         var callParams = CallParams(action.GetMethodInfo(), parameters);
         await action((T1)callParams[0]).ConfigureAwait(false);
     }));
 }
 /// <summary>
 /// Syntax sugar for checking that the argument passes a validation function.
 /// </summary>
 public static void Validate <T>(this T subject, Func <T, bool> validation, string argName)
 {
     validation.MustNotBeNull("validation");
     if (!validation(subject))
     {
         throw new ArgumentException(String.Format("{0} ({1}) fails to validate",
                                                   argName, subject));
     }
 }
        public IConfigureConventions DefaultBuilder(Func <ModelInfo, HtmlTag> action)
        {
            action.MustNotBeNull();
            var lambda = new LambdaConventions(LambdaConventions.AppliesAlways);

            lambda.Builder  = action;
            _defaultBuilder = lambda;
            return(this);
        }
示例#8
0
 public static void WriteColumnsNames(ICollection<string> columns, StringBuilder builder, Func<string, string> formatter)
 {
     columns.MustNotBeNull();
     formatter.MustNotBeNull();
     foreach (var column in columns)
     {
         builder.Append(formatter(column.Trim())).Append(",");
     }
     builder.RemoveLast();
 }
示例#9
0
 public static void WriteColumnsNames(ICollection <string> columns, StringBuilder builder,
                                      Func <string, string> formatter)
 {
     columns.MustNotBeNull();
     formatter.MustNotBeNull();
     foreach (var column in columns)
     {
         builder.Append(formatter(column.Trim())).Append(",");
     }
     builder.RemoveLast();
 }
示例#10
0
 public SmartContextFacade(Controller ctrl, Func <dynamic> modelIdentifier, Type validationFailedPolicy, IValidationFailedPolicyFactory factory)
 {
     ctrl.MustNotBeNull();
     modelIdentifier.MustNotBeNull();
     validationFailedPolicy.MustNotBeNull();
     factory.MustNotBeNull();
     _ctrl                   = ctrl;
     _modelIdentifier        = modelIdentifier;
     _validationFailedPolicy = validationFailedPolicy;
     IsPost                  = ctrl.HttpContext.Request.IsPost();
     _factory                = factory;
 }
示例#11
0
 /// <summary>
 /// Creates a <see cref="MenuItem"/> from a non-async void expression - is meant to be used with a <see cref="MethodCallExpression"/>.
 /// </summary>
 /// <typeparam name="T1">The parameter type of the first method parameter.</typeparam>
 /// <param name="displayString">The explicit "label" to be used for the menu entry.</param>
 /// <param name="action">The expression to create a menu item for.</param>
 /// <param name="suffixForMenu">A suffix for the description of the method (the description will be extracted from the documentation XML file).</param>
 /// <returns>A new menu item.</returns>
 public static MenuItem Print <T1>(string displayString, Func <T1, string> action, string suffixForMenu = "")
 {
     _ = action.MustNotBeNull(nameof(action));
     return(new MenuItem(
                displayString + suffixForMenu,
                parameters =>
     {
         var callParams = CallParams(action.GetMethodInfo(), parameters);
         var returnValue = action.Invoke((T1)callParams[0]);
         return Task.FromResult(returnValue);
     }));
 }
 public SmartContextFacade(Controller ctrl,Func<dynamic> modelIdentifier,Type validationFailedPolicy,IValidationFailedPolicyFactory factory)
 {
     ctrl.MustNotBeNull();
     modelIdentifier.MustNotBeNull();
     validationFailedPolicy.MustNotBeNull();
     factory.MustNotBeNull();
     _ctrl = ctrl;
     _modelIdentifier = modelIdentifier;
     _validationFailedPolicy = validationFailedPolicy;
     IsPost = ctrl.HttpContext.Request.IsPost();
     _factory = factory;
 }
示例#13
0
        /// <summary>
        /// Removes all items matched by predicate
        ///  Returns number of items removed
        /// </summary>
        /// <param name="dic"></param>
        /// <param name="predicate"></param>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="V"></typeparam>
        /// <returns></returns>
        public static int RemoveAll <K, V>(this IDictionary <K, V> dic, Func <KeyValuePair <K, V>, bool> predicate)
        {
            predicate.MustNotBeNull();
            dic.MustNotBeNull();
            var keys = dic.TakeWhile(predicate).ToArray();

            foreach (var kv in keys)
            {
                dic.Remove(kv);
            }
            return(keys.Length);
        }
示例#14
0
 public MainWindowViewModel(ObservableCollection <NamedList> namedLists,
                            Func <INewItemDialog> createNewItemDialog,
                            Func <IDialog> createConfirmRemovalDialog)
 {
     NamedLists                  = namedLists.MustNotBeNull(nameof(namedLists));
     _createNewItemDialog        = createNewItemDialog.MustNotBeNull(nameof(createNewItemDialog));
     _createConfirmRemovalDialog = createConfirmRemovalDialog.MustNotBeNull(nameof(createConfirmRemovalDialog));
     _addListCommand             = new DelegateCommand(AddList, () => !_isDialogOpen);
     _removeListCommand          = new DelegateCommand(RemoveList, CanRemoveList);
     _addListEntryCommand        = new DelegateCommand(AddListEntry, CanAddListEntry);
     _removeListEntryCommand     = new DelegateCommand(RemoveListEntry, CanRemoveListEntry);
 }
示例#15
0
 /// <summary>
 /// Creates a <see cref="MenuItem"/> from an expression - is meant to be used with a <see cref="MethodCallExpression"/>.
 /// </summary>
 /// <param name="displayString">The explicit "label" to be used for the menu entry.</param>
 /// <param name="action">The expression to create a menu item for.</param>
 /// <param name="suffixForMenu">A suffix for the description of the method (the description will be extracted from the documentation XML file).</param>
 /// <returns>A new menu item.</returns>
 public static MenuItem Print(string displayString, Func <Task <IEnumerable <string> > > action, string suffixForMenu = "")
 {
     _ = action.MustNotBeNull(nameof(action));
     return(new MenuItem(
                displayString + suffixForMenu,
                async p =>
     {
         foreach (var result in await action().ConfigureAwait(false))
         {
             Console.WriteLine($"\n{result}");
         }
     }));
 }
示例#16
0
        public virtual bool GetOrAddScopedInstance(TypeKey typeKey, Func <object> createInstance, out object instance, bool searchInParentScope = true)
        {
            createInstance.MustNotBeNull(nameof(createInstance));

            if (TryGetScopedInstance(typeKey, out instance, searchInParentScope))
            {
                return(false);
            }

            instance = createInstance();
            _scopedObjects.Add(typeKey, instance);
            return(true);
        }
示例#17
0
        /// <summary>
        /// Stores the events using the specified action then publish them.
        /// If persisting throws a <see cref="DuplicateOperationException"/> it will use those events for publishing
        /// </summary>
        /// <param name="bus"></param>
        /// <param name="persistAction">Should throw <see cref="DuplicateOperationException"/> if a commit is duplicate</param>
        public static void PublishAfterStoring(this IDispatchMessages bus, Func <IEvent[]> persistAction)
        {
            persistAction.MustNotBeNull();
            IEvent[] events = Array.Empty <IEvent>();
            try
            {
                events = persistAction();
            }
            catch (DuplicateOperationException ex)
            {
                events = ex.Events;
            }

            bus.Publish(events);
        }
示例#18
0
 /// <summary>
 /// Stores the events using the specified action then publish them.
 /// If persisting throws a <see cref="DuplicateOperationException"/> it will use those events for publishing
 /// </summary>
 /// <param name="bus"></param>
 /// <param name="persistAction">Should throw <see cref="DuplicateOperationException"/> if a commit is duplicate</param>
 public static void PublishAfterStoring(this IDispatchMessages bus,Func<IEvent[]> persistAction)
 {
     persistAction.MustNotBeNull();
     IEvent[] events = Array.Empty<IEvent>();
    try
    {
         events=persistAction();
    }
     catch (DuplicateOperationException ex)
     {
         events = ex.Events;
     }
    
     bus.Publish(events);            
 }
示例#19
0
        /// <summary>
        /// Returns number of items removed
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="items"></param>
        /// <param name="predicate"></param>
        /// <returns></returns>
        public static int RemoveAll <T>(this IList <T> items, Func <T, bool> predicate)
        {
            items.MustNotBeEmpty();
            predicate.MustNotBeNull();
            var removed = 0;

            for (int i = items.Count - 1; i >= 0; i--)
            {
                if (predicate(items[i]))
                {
                    items.RemoveAt(i);
                    removed++;
                }
            }
            return(removed);
        }
示例#20
0
 /// <summary>
 /// Gets a single row then maps it to a poco
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="db"></param>
 /// <param name="builder"></param>
 /// <param name="token"></param>
 /// <returns></returns>
 public static Task <T> QueryRowAsync <T>(this DbConnection db, Func <IBuildQueryFrom, IGenerateSql <T> > builder, CancellationToken token)
 {
     builder.MustNotBeNull();
     return(db.WithSql(builder, cancel: token).GetFirstRowAsync());
 }
 public static IReadOnlyList <T> AsReadOnlyList <T>([ValidatedNotNull] this IEnumerable <T> source, Func <IEnumerable <T>, IReadOnlyList <T> > createCollection) =>
 source as IReadOnlyList <T> ?? createCollection.MustNotBeNull(nameof(createCollection))(source.MustNotBeNull(nameof(source)));
示例#22
0
 public static void WriteColumnsNames(string columns, StringBuilder builder, Func <string, string> formatter)
 {
     columns.MustNotBeEmpty();
     formatter.MustNotBeNull();
     WriteColumnsNames(columns.Split(','), builder, formatter);
 }
示例#23
0
 public static Saga <T> SagaCompletesWhen <T>(this Saga <T> saga, Func <T, bool> when) where T : ASagaState
 {
     when.MustNotBeNull();
     saga.Completion = when;
     return(saga);
 }
 public IConfigureMakeSharp MethodToExecute(Func <MethodInfo, bool> matchMethod)
 {
     matchMethod.MustNotBeNull();
     _matchMethod = matchMethod;
     return(this);
 }
 public IConfigureMakeSharp TasksAre(Func <Type, bool> matchType)
 {
     matchType.MustNotBeNull();
     _matchType = matchType;
     return(this);
 }
 public void Register <T>(Func <DbDataReader, T> mapper)
 {
     mapper.MustNotBeNull();
     _mappers[typeof(T)] = mapper;
 }
示例#27
0
 public MessagingMediator(Func <Type, object> resolve)
 {
     resolve.MustNotBeNull();
     _resolve = resolve;
 }
示例#28
0
 public IQueryAndProcess ProcessEachRow(Func <T, bool> processor)
 {
     CheckDispose();
     processor.MustNotBeNull();
     return(new QueryAndProcess(_cmd, processor, _cancel, _disposeAfterQuery));
 }
示例#29
0
 public static void WriteColumnsNames(string columns, StringBuilder builder, Func<string, string> formatter)
 {
     columns.MustNotBeEmpty();
     formatter.MustNotBeNull();
     WriteColumnsNames(columns.Split(','), builder, formatter);
 }
 public IConfigureMakeSharp TasksAre(Func<Type, bool> matchType)
 {
     matchType.MustNotBeNull();
     _matchType = matchType;
     return this;
 }
示例#31
0
 public static void RegisterConverterFor <T>(Func <object, T> conv)
 {
     conv.MustNotBeNull();
     _converters.TryAdd(typeof(T).GetHashCode(), conv);
 }
 public IConfigureMakeSharp MethodToExecute(Func<MethodInfo, bool> matchMethod)
 {
     matchMethod.MustNotBeNull();
     _matchMethod = matchMethod;
     return this;
 }
示例#33
0
 public static IEnumerable <T> GetInstancesOfTypesDerivedFrom <T>(this Assembly asm, Func <Type, T> factory) where T : class, new()
 {
     factory.MustNotBeNull();
     return(asm.GetTypesDerivedFrom <T>(true).Select(factory));
 }
示例#34
0
 /// <summary>
 /// Creates a <see cref="MenuItem"/> from an expression - is meant to be used with a <see cref="MethodCallExpression"/>.
 /// </summary>
 /// <param name="displayString">The explicit "label" to be used for the menu entry.</param>
 /// <param name="action">The expression to create a menu item for.</param>
 /// <param name="suffixForMenu">A suffix for the description of the method (the description will be extracted from the documentation XML file).</param>
 /// <returns>A new menu item.</returns>
 public static MenuItem Print(string displayString, Func <Task> action, string suffixForMenu = "")
 {
     _ = action.MustNotBeNull(nameof(action));
     return(new MenuItem(displayString + suffixForMenu, async p => await action().ConfigureAwait(false)));
 }
示例#35
0
 /// <summary>
 ///     Tries to cast the specified enumerable as an <see cref="IReadOnlyList{T}" />, or
 ///     creates a new collection containing the enumerable's items by calling the specified delegate.
 /// </summary>
 /// <typeparam name="T">The item type of the collection.</typeparam>
 /// <param name="enumerable">The enumerable that will be converted to <see cref="IReadOnlyList{T}" />.</param>
 /// <param name="createCollection">The delegate that creates the collection containing the specified items.</param>
 /// <returns>The casted enumerable, or a new collection containing the enumerable's items.</returns>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="enumerable" /> or <paramref name="createCollection" /> is null.</exception>
 public static IReadOnlyList <T> AsReadOnlyList <T>(this IEnumerable <T> enumerable, Func <IEnumerable <T>, IReadOnlyList <T> > createCollection)
 {
     return(enumerable as IReadOnlyList <T> ?? createCollection.MustNotBeNull(nameof(createCollection))(enumerable.MustNotBeNull(nameof(enumerable))));
 }
示例#36
0
 public static IList <T> AsList <T>(this IEnumerable <T> source, Func <IEnumerable <T>, IList <T> > createCollection) =>
 source as IList <T> ?? createCollection.MustNotBeNull(nameof(createCollection))(source.MustNotBeNull(nameof(source)));
 public DrinksController(Func <IDrinksContext> createContext)
 {
     _createContext = createContext.MustNotBeNull(nameof(createContext));
 }
示例#38
0
 public IQueryAndProcess ProcessEachRow(Func <T, bool> processor)
 {
     processor.MustNotBeNull();
     return(new QueryAndProcess(_cmd, processor, _cancel));
 }