/// <summary> /// Determines whether this map is equal to a sequence of key-value pairs. Maps are equal if they contain the same keys, and if the values associated with them are also equal. /// </summary> /// <param name="other">A sequence of key-value pairs. This operation is much faster if it's a map compatible with this one.</param> /// <param name="equality">A function for determining equality between values.</param> /// <returns></returns> public virtual bool MapEquals(IEnumerable <KeyValuePair <TKey, TValue> > other, Func <TValue, TValue, bool> equality) { other.CheckNotNull("other"); equality.CheckNotNull("equality"); var boiler = EqualityHelper.BoilerEquality(this, other); if (boiler.IsSome) { return(boiler.Value); } var map = other as TMap; if (map != null && IsCompatibleWith(map)) { return(MapEquals(map, equality)); } var tryLength = other.TryGuessLength(); if (tryLength.IsSome && tryLength.Value < Length) { return(false); } return(other.ForEachWhile(kvp => { var myValue = this.TryGet(kvp.Key); return myValue.IsSome && equality(myValue.Value, kvp.Value); })); }
/// <summary> /// Executes the navigation action passing current page object. /// </summary> /// <typeparam name="TNavigateTo">The type of the navigate to.</typeparam> /// <param name="navigationAction">The navigation action.</param> /// <returns>The instance of the page object to navigate to.</returns> public TNavigateTo Do <TNavigateTo>(Func <TOwner, TNavigateTo> navigationAction) where TNavigateTo : PageObject <TNavigateTo> { navigationAction.CheckNotNull(nameof(navigationAction)); return(navigationAction((TOwner)this)); }
/// <summary> /// 根据第三方条件是否为真来决定是否执行指定条件的查询 /// </summary> /// <param name="source"> 要查询的源 </param> /// <param name="predicate"> 查询条件 </param> /// <param name="condition"> 第三方条件 </param> /// <typeparam name="T"> 动态类型 </typeparam> /// <returns> 查询的结果 </returns> public static IEnumerable <T> WhereIf <T>(this IEnumerable <T> source, Func <T, bool> predicate, bool condition) { predicate.CheckNotNull("predicate"); source = source as IList <T> ?? source.ToList(); return(condition ? source.Where(predicate) : source); }
/// <summary> /// Specifies the driver options factory method. /// </summary> /// <param name="optionsFactory">The factory method of the driver options.</param> /// <returns>The same builder instance.</returns> public RemoteDriverAtataContextBuilder WithOptions(Func <DriverOptions> optionsFactory) { optionsFactory.CheckNotNull(nameof(optionsFactory)); this.optionsFactory = optionsFactory; return(this); }
public LiftedList(int itemCount, Func <int, T> factory, Func <bool> disposedChecker) { itemCount.CheckGTE(0, "itemCount"); IsDisposed = disposedChecker.CheckNotNull("disposedChecker"); CreateObject = factory.CheckNotNull("factory"); m_array = new T[itemCount]; }
/// <summary> /// Adds the <c>download.default_directory</c> user profile preference to <see cref="ChromeOptions"/> /// with the value specified by <paramref name="directoryPathBuilder"/>. /// </summary> /// <param name="directoryPathBuilder">The directory path builder.</param> /// <returns>The same builder instance.</returns> public ChromeAtataContextBuilder WithDownloadDirectory(Func <string> directoryPathBuilder) { directoryPathBuilder.CheckNotNull(nameof(directoryPathBuilder)); return(WithOptions(x => x .AddUserProfilePreference("download.default_directory", directoryPathBuilder.Invoke()))); }
/// <summary> /// (Implemnetation) The GroupJoin operator. Results are returned as a key-value map, and group elements are stored as an iterator. /// </summary> /// <typeparam name="TOutIter"> The type of the return collection. </typeparam> /// <typeparam name="TOut"> The type of element in the return collection. </typeparam> /// <typeparam name="TInner"> The type of element in the inner sequence. </typeparam> /// <typeparam name="TKey"> The type of the key. </typeparam> /// <param name="bFactory"> A prototype instance of the resulting collection provider, used as a builder factory. </param> /// <param name="inner"> The inner sequence. </param> /// <param name="oKeySelector"> The outer key selector. </param> /// <param name="iKeySelector"> The inner key selector. </param> /// <param name="rSelector"> The return element selector. </param> /// <param name="eq"> The equality comparer. </param> /// <returns> </returns> protected virtual TOutIter _GroupJoin <TOut, TOutIter, TInner, TKey>(TOutIter bFactory, IEnumerable <TInner> inner, Func <TElem, TKey> oKeySelector, Func <TInner, TKey> iKeySelector, Func <TElem, IEnumerable <TInner>, TOut> rSelector, IEqualityComparer <TKey> eq = null) where TOutIter : IBuilderFactory <IIterableBuilder <TOut, TOutIter> > { bFactory.CheckNotNull("bFactory"); inner.CheckNotNull("inner"); oKeySelector.CheckNotNull("oKeySelector"); iKeySelector.CheckNotNull("iKeySelector"); rSelector.CheckNotNull("rSelector"); eq = eq ?? FastEquality <TKey> .Default; using (var builder = bFactory.EmptyBuilder) { var dict = new Dictionary <TKey, List <TInner> >(eq); foreach (var item in inner) { var k = iKeySelector(item); dict[k] = dict[k] ?? new List <TInner>(); dict[k].Add(item); } ForEach(v => { var k = oKeySelector(v); var ins = dict[k]; builder.Add(rSelector(v, ins)); }); return(builder.Produce()); } }
/// <summary> /// (Implementation) The GroupBy operator. Results are returned as a concrete map type, and group elements are stored as an iterator. /// </summary> /// <typeparam name="TOutMap">The type of the output map.</typeparam> /// <typeparam name="TElem2">The type of intermediate value returned by the value selector.</typeparam> /// <typeparam name="TOut">The type of the output element.</typeparam> /// <typeparam name="TKey">The type of the key used to perform the grouping.</typeparam> /// <param name="bFactory">A prototype instance of the resulting collection, used as a builder factory.</param> /// <param name="keySelector">The key selector.</param> /// <param name="valueSelector">The value selector.</param> /// <param name="resultSelector">The result selector.</param> /// <param name="eq">The eq.</param> /// <returns></returns> protected virtual TOutMap _GroupBy <TOutMap, TElem2, TOut, TKey>( TOutMap bFactory, Func <TElem, TKey> keySelector, Func <TElem, TElem2> valueSelector, Func <TKey, IEnumerable <TElem2>, TOut> resultSelector, IEqualityComparer <TKey> eq = null) where TOutMap : IBuilderFactory <IIterableBuilder <TOut, TOutMap> > { keySelector.CheckNotNull("keySelector"); valueSelector.CheckNotNull("valueSelector"); resultSelector.CheckNotNull("resultSelector"); eq = eq ?? FastEquality <TKey> .Default; using (var builder = bFactory.EmptyBuilder) { var groups = new Dictionary <TKey, List <TElem2> >(eq); ForEach(x => { var key = keySelector(x); if (!groups.ContainsKey(key)) { groups[key] = new List <TElem2>(); } groups[key].Add(valueSelector(x)); }); foreach (var kvp in groups) { var myGrouping = resultSelector(kvp.Key, kvp.Value); builder.Add(myGrouping); } return(builder.Produce()); } }
internal RemoteQueryProvider(Func <Expressions.Expression, TSource> dataProvider, ITypeInfoProvider?typeInfoProvider, IQueryResultMapper <TSource> resultMapper, Func <Expression, bool>?canBeEvaluatedLocally) { _dataProvider = dataProvider.CheckNotNull(nameof(dataProvider)); _resultMapper = resultMapper.CheckNotNull(nameof(resultMapper)); _typeInfoProvider = typeInfoProvider; _canBeEvaluatedLocally = canBeEvaluatedLocally; }
/// <summary> /// 循环集合的每一项,调用委托生成字符串,返回合并后的字符串。默认分隔符为逗号 /// </summary> /// <param name="collection">待处理的集合</param> /// <param name="itemFormatFunc">单个集合项的转换委托</param> /// <param name="separetor">分隔符,默认为逗号</param> /// <typeparam name="T">泛型类型</typeparam> /// <returns></returns> public static string ExpandAndToString <T>(this IEnumerable <T> collection, Func <T, string> itemFormatFunc, string separetor = ",") { collection = collection as IList <T> ?? collection.ToList(); itemFormatFunc.CheckNotNull("itemFormatFunc"); if (!collection.Any()) { return(null); } StringBuilder sb = new StringBuilder(); int i = 0; int count = collection.Count(); foreach (T t in collection) { if (i == count - 1) { sb.Append(itemFormatFunc(t)); } else { sb.Append(itemFormatFunc(t) + separetor); } i++; } return(sb.ToString()); }
/// <summary> /// Use custom driver creator function. /// </summary> /// <param name="driverCreator">The builder.</param> /// <returns>The <see cref="FirefoxAtataContextBuilder"/> instance.</returns> public AtataContextBuilder UseDriver(Func <RemoteWebDriver> driverCreator) { driverCreator.CheckNotNull(nameof(driverCreator)); BuildingContext.DriverCreator = driverCreator; return(this); }
/// <summary> /// Specifies the capabilities factory method. /// </summary> /// <param name="capabilitiesFactory">The factory method of the driver capabilities.</param> /// <returns>The same builder instance.</returns> public RemoteDriverAtataContextBuilder WithCapabilities(Func <ICapabilities> capabilitiesFactory) { capabilitiesFactory.CheckNotNull(nameof(capabilitiesFactory)); this.capabilitiesFactory = capabilitiesFactory; return(this); }
public static void Register(string typeAlias, Func <IScreenshotConsumer> logConsumerFactory) { typeAlias.CheckNotNullOrWhitespace(nameof(typeAlias)); logConsumerFactory.CheckNotNull(nameof(logConsumerFactory)); AliasFactoryMap[typeAlias.ToLower()] = logConsumerFactory; }
/// <summary> /// Specifies the driver service factory method. /// </summary> /// <param name="serviceFactory">The factory method of the driver service.</param> /// <returns>The same builder instance.</returns> public TBuilder WithDriverService(Func <TService> serviceFactory) { serviceFactory.CheckNotNull(nameof(serviceFactory)); this.serviceFactory = serviceFactory; return((TBuilder)this); }
/// <summary> /// Specifies the driver options factory method. /// </summary> /// <param name="optionsFactory">The factory method of the driver options.</param> /// <returns>The same builder instance.</returns> public TBuilder WithOptions(Func <TOptions> optionsFactory) { optionsFactory.CheckNotNull(nameof(optionsFactory)); this.optionsFactory = optionsFactory; return((TBuilder)this); }
public AsyncRemoteStreamProvider(Func <Expressions.Expression, CancellationToken, IAsyncEnumerable <TSource> > dataProvider, ITypeInfoProvider?typeInfoProvider, Func <Expression, bool>?canBeEvaluatedLocally, IQueryResultMapper <TSource> resultMapper) { _dataProvider = dataProvider.CheckNotNull(nameof(dataProvider)); _resultMapper = resultMapper.CheckNotNull(nameof(resultMapper)); _typeInfoProvider = typeInfoProvider; _canBeEvaluatedLocally = canBeEvaluatedLocally; }
/// <summary> /// Sets the factory method of the test name. /// </summary> /// <param name="testNameFactory">The factory method of the test name.</param> /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns> public AtataContextBuilder UseTestName(Func <string> testNameFactory) { testNameFactory.CheckNotNull(nameof(testNameFactory)); BuildingContext.TestNameFactory = testNameFactory; return(this); }
/// <summary> /// 根据指定条件返回集合中不重复的元素 /// </summary> /// <typeparam name="T">动态类型</typeparam> /// <typeparam name="TKey">动态筛选条件类型</typeparam> /// <param name="source">要操作的源</param> /// <param name="keySelector">重复数据筛选条件</param> /// <returns>不重复元素的集合</returns> public static IEnumerable <T> DistinctBy <T, TKey>(this IEnumerable <T> source, Func <T, TKey> keySelector) { keySelector.CheckNotNull("keySelector"); source = source as IList <T> ?? source.ToList(); return(source.GroupBy(keySelector).Select(group => group.First())); }
/// <summary> /// Drags and drops the control to the target control returned by <paramref name="targetSelector"/>. /// By default uses <see cref="DragAndDropUsingActionsAttribute"/>. /// Also executes <see cref="TriggerEvents.BeforeClick" /> and <see cref="TriggerEvents.AfterClick" /> triggers. /// </summary> /// <param name="targetSelector">The target control selector.</param> /// <returns>The instance of the owner page object.</returns> public TOwner DragAndDropTo(Func <TOwner, Control <TOwner> > targetSelector) { targetSelector.CheckNotNull(nameof(targetSelector)); var target = targetSelector(Owner); return(DragAndDropTo(target)); }
public TRet Get <TRet>(Func <TomlTable, TRet> getter) { getter.CheckNotNull(nameof(getter)); var cfg = this.persistable.Load(); return(getter(cfg)); }
public IConfigSource GetSource(Func <TomlTable, object> getter) { getter.CheckNotNull(nameof(getter)); var cfg = this.persistable.LoadSourcesTable(); return((IConfigSource)getter(cfg)); }
public AsyncRemoteQueryProvider( Func <RemoteLinq.Expression, CancellationToken, ValueTask <TSource?> > asyncDataProvider, IAsyncQueryResultMapper <TSource> resultMapper, IExpressionToRemoteLinqContext?context) { _asyncDataProvider = asyncDataProvider.CheckNotNull(nameof(asyncDataProvider)); _resultMapper = resultMapper.CheckNotNull(nameof(resultMapper)); _context = context; }
/// <inheritdoc cref="SubjectBase{TObject, TSubject}.ResultOf{TResult}(Func{TObject, TResult}, string)"/> public static Subject <TResult> ResultOf <TResult>(Func <TResult> function, string functionName) { function.CheckNotNull(nameof(function)); functionName.CheckNotNull(nameof(functionName)); return(new Subject <TResult>( new LazyObjectSource <TResult>(function), BuildResultName(functionName))); }
/// <summary> /// Initializes a new instance of the <see cref="DriverSetupConfigurationBuilder"/> class. /// </summary> /// <param name="browserName">Name of the browser.</param> /// <param name="driverSetupStrategyFactory">The driver setup strategy factory.</param> /// <param name="context">The driver setup configuration.</param> public DriverSetupConfigurationBuilder( string browserName, Func <IHttpRequestExecutor, IDriverSetupStrategy> driverSetupStrategyFactory, DriverSetupConfiguration context) : base(context) { BrowserName = browserName.CheckNotNull(nameof(browserName)); _driverSetupStrategyFactory = driverSetupStrategyFactory.CheckNotNull(nameof(driverSetupStrategyFactory)); }
/// <summary> /// Creates a new lazy <see cref="Subject{TResult}"/> from the result of the specified <paramref name="function"/> with the specified <paramref name="functionName"/>. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="function">The function.</param> /// <param name="functionName">Name of the function.</param> /// <returns>A new <see cref="Subject{TResult}"/> instance.</returns> public Subject <TResult> SubjectOf <TResult>(Func <TObject, TResult> function, string functionName) { function.CheckNotNull(nameof(function)); functionName.CheckNotNull(nameof(functionName)); return(new Subject <TResult>( new LazyObjectSource <TResult, TObject>(this, function), functionName)); }
public AsyncRemoteStreamProvider( Func <Expressions.Expression, CancellationToken, IAsyncEnumerable <TSource?> > dataProvider, IAsyncQueryResultMapper <TSource> resultMapper, IExpressionToRemoteLinqContext?context) { _dataProvider = dataProvider.CheckNotNull(nameof(dataProvider)); _resultMapper = resultMapper.CheckNotNull(nameof(resultMapper)); _context = context; }
/// <summary> /// Initializes a new instance of the <see cref="LazyObjectSource{TValue, TSource}"/> class. /// </summary> /// <param name="sourceProvider">The source provider.</param> /// <param name="valueGetFunction">The value get function.</param> public LazyObjectSource(IObjectProvider <TSource> sourceProvider, Func <TSource, TObject> valueGetFunction) { this.sourceProvider = sourceProvider.CheckNotNull(nameof(sourceProvider)); valueGetFunction.CheckNotNull(nameof(valueGetFunction)); lazyValue = new Lazy <TObject>(() => valueGetFunction.Invoke(this.sourceProvider.Value)); this.sourceProvider = sourceProvider; }
public RemoteQueryProvider( Func <Expressions.Expression, TSource?> dataProvider, IQueryResultMapper <TSource> resultMapper, IExpressionToRemoteLinqContext?context) { _dataProvider = dataProvider.CheckNotNull(nameof(dataProvider)); _resultMapper = resultMapper.CheckNotNull(nameof(resultMapper)); _context = context; }
/// <summary> /// Creates a new dynamic <see cref="Subject{TResult}"/> from the result of the specified <paramref name="function"/> with the specified <paramref name="functionName"/>. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="function">The function.</param> /// <param name="functionName">Name of the function.</param> /// <returns>A new <see cref="Subject{TResult}"/> instance.</returns> public Subject <TResult> DynamicResultOf <TResult>(Func <TObject, TResult> function, string functionName) { function.CheckNotNull(nameof(function)); functionName.CheckNotNull(nameof(functionName)); return(new Subject <TResult>( new DynamicObjectSource <TResult, TObject>(this, function), Subject.BuildResultName(functionName))); }
/// <inheritdoc cref="SubjectBase{TObject, TSubject}.DynamicSubjectOf{TResult}(Func{TObject, TResult}, string)"/> public static Subject <TResult> DynamicSubjectOf <TResult>(Func <TResult> function, string functionName) { function.CheckNotNull(nameof(function)); functionName.CheckNotNull(nameof(functionName)); return(new Subject <TResult>( new DynamicObjectSource <TResult>(function), functionName)); }
//# Creates an instruction instance. Note that if [operand] is of type Func<Object> the value of [Operand] will //# be computed lazyily from the return value of the function. However, the value returned from //# `((Func<Object>)operand)()` cannot its self be a Func<Object>. If it is, calling [Operand] will result in //# an exception. internal Instruction( Opcode opcode, int offset, int size, object operand, IReadOnlyList<byte> encoding, Func<String> prettyPrint, Instruction modifiedInstruction ) { m_opcode = opcode.CheckDefined("opcode"); m_offset = offset.CheckGTE(0, "offset"); m_size = size.CheckGTE(1, "size"); m_operand = operand; m_encoding = encoding; m_prettyPrint = prettyPrint.CheckNotNull("prettyPrint"); m_modifiedInstruction = modifiedInstruction; }