当前位置: 首页>>代码示例>>C#>>正文


C# Action.?.Invoke方法代码示例

本文整理汇总了C#中Action.?.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# Action.?.Invoke方法的具体用法?C# Action.?.Invoke怎么用?C# Action.?.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Action的用法示例。


在下文中一共展示了Action.?.Invoke方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CombineBothWays

		protected void CombineBothWays(
			QueryContainer ois1,
			QueryContainer ois2,
			Func<QueryContainerDescriptor<Project>, QueryContainer> lambda1,
			Func<QueryContainerDescriptor<Project>, QueryContainer> lambda2,
			Action<IQueryContainer> assertLeft,
			Action<IQueryContainer> assertRight,
			Action<IBoolQuery> assertContainer = null
			)
		{
			var oisLeft = ois1 || ois2;
			Func<QueryContainerDescriptor<Project>, QueryContainer> lambdaLeft = (s) => lambda1(s) || lambda2(s);

			ReturnsBool(oisLeft, lambdaLeft, b =>
			{
				var left = (IQueryContainer)b.Should.First();
				var right = (IQueryContainer)b.Should.Last();
				assertLeft(left);
				assertRight(right);
				assertContainer?.Invoke(b);
			});

			var oisRight = ois2 || ois1;
			Func<QueryContainerDescriptor<Project>, QueryContainer> lambdaRight = (s) => lambda2(s) || lambda1(s);

			ReturnsBool(oisRight, lambdaRight, b =>
			{
				var left = (IQueryContainer)b.Should.First();
				var right = (IQueryContainer)b.Should.Last();
				assertRight(left);
				assertLeft(right);
				assertContainer?.Invoke(b);
			});
		}
开发者ID:niemyjski,项目名称:elasticsearch-net,代码行数:34,代码来源:OrOperatorOnManualBoolsTests.cs

示例2: AssertRegularResponse

		private async Task AssertRegularResponse(bool disableDirectStreaming, Action<ResponseBuilder<RootNodeInfoResponse>> mutate = null)
		{
			var settings = disableDirectStreaming ? _settingsDisableDirectStream : _settings;
			var memoryStreamFactory = new TrackMemoryStreamFactory();
			var requestData = new RequestData(HttpMethod.GET, "/", null, settings, null, memoryStreamFactory)
			{
				Node = new Node(new Uri("http://localhost:9200"))
			};

			var responseBuilder = new ResponseBuilder<RootNodeInfoResponse>(requestData)
			{
			};
			mutate?.Invoke(responseBuilder);

			var stream = new TrackDisposeStream();
			responseBuilder.Stream = stream;

			var response = responseBuilder.ToResponse();
			memoryStreamFactory.Created.Count().Should().Be(disableDirectStreaming ? 1 : 0);
			if (disableDirectStreaming)
			{
				var memoryStream = memoryStreamFactory.Created[0];
				memoryStream.IsDisposed.Should().BeTrue();
			}
			stream.IsDisposed.Should().BeTrue();


			stream = new TrackDisposeStream();
			responseBuilder.Stream = stream;
			response = await responseBuilder.ToResponseAsync();
			memoryStreamFactory.Created.Count().Should().Be(disableDirectStreaming ? 2 : 0);
			if (disableDirectStreaming)
			{
				var memoryStream = memoryStreamFactory.Created[1];
				memoryStream.IsDisposed.Should().BeTrue();
			}
			stream.IsDisposed.Should().BeTrue();
		}
开发者ID:niemyjski,项目名称:elasticsearch-net,代码行数:38,代码来源:ResponseBuilderDisposeTests.cs

示例3: DoWithCurrentRepo

 void DoWithCurrentRepo(Action<Repository> doWithRepo)
 {
     using (var repo = new Repository(Repository.Discover(Environment.CurrentDirectory)))
     {
         doWithRepo?.Invoke(repo);
     }
 }
开发者ID:tenninebt,项目名称:Stamp,代码行数:7,代码来源:TokenResolverTests.cs

示例4: Step

        private static void Step(IEnumerable<IPortalCommon> moving, IEnumerable<IPortal> portals, double stepSize, Action<EnterCallbackData> portalEnter, List<PortalableSweep> previous)
        {
            List<PortalableMovement> pointMovement = new List<PortalableMovement>();
            List<PortalMovement> lineMovement = new List<PortalMovement>();

            //Get the start positions and initial end positions for all portals and portalables.
            {
                foreach (IPortal p in portals)
                {
                    if (!Portal.IsValid(p))
                    {
                        continue;
                    }
                    Line lineStart = new Line(Vector2Ext.ToDouble(Portal.GetWorldVerts(p)));

                    Transform2d t = (Transform2d)p.WorldTransform.Add(p.WorldVelocity.Multiply((float)stepSize));
                    Line lineEnd = new Line(Vector2Ext.ToDouble(Portal.GetWorldVerts(p, (Transform2)t)));

                    lineMovement.Add(new PortalMovement(p, lineStart, lineEnd));
                }

                foreach (IPortalCommon p in moving)
                {
                    if (p.WorldTransform == null || p.WorldVelocity == null)
                    {
                        continue;
                    }
                    Transform2d shift = (Transform2d)p.WorldVelocity.Multiply((float)stepSize);
                    Transform2d t = (Transform2d)p.WorldTransform.Add(p.WorldVelocity.Multiply((float)stepSize));

                    Line movement = new Line((Vector2d)p.WorldTransform.Position, t.Position);

                    pointMovement.Add(new PortalableMovement(p, movement, (Transform2d)p.WorldTransform));
                }
            }

            List<PortalableSweep> earliest = GetEarliestCollision(pointMovement, lineMovement, previous, stepSize);

            if (earliest.Count == 0)
            {
                foreach (PortalableMovement p in pointMovement)
                {
                    IPortalable portalable = p.Instance as IPortalable;
                    if (portalable != null)
                    {
                        Transform2d shift = (Transform2d)portalable.GetVelocity().Multiply((float)stepSize);
                        portalable.SetTransform(portalable.Transform.Add((Transform2)shift));
                    }

                    Transform2d worldVelocity = (Transform2d)p.Instance.WorldVelocity.Multiply((float)stepSize);
                    p.Instance.WorldTransform = p.Instance.WorldTransform.Add((Transform2)worldVelocity);
                }
                return;
            }

            double tDelta = earliest[0].Sweep.TimeProportion;
            foreach (PortalableMovement move in pointMovement)
            {
                IPortalable portalable = move.Instance as IPortalable;
                if (portalable != null)
                {
                    Transform2d velocity = (Transform2d)portalable.GetVelocity().Multiply((float)(stepSize * tDelta));
                    portalable.SetTransform(portalable.GetTransform().Add((Transform2)velocity));
                }

                Transform2d worldVelocity = (Transform2d)move.Instance.WorldVelocity.Multiply((float)(stepSize * tDelta));
                move.Instance.WorldTransform = move.Instance.WorldTransform.Add((Transform2)worldVelocity);
            }

            foreach (PortalableSweep sweep in earliest)
            {
                float intersectT = (float)sweep.Sweep.AcrossProportion;
                IPortalCommon instance = sweep.Portalable.Instance;

                /*Before this instance enters the portal we place it exactly on the portal to reduce
                 * precision errors.*/
                PlaceOnPortal(instance, sweep.Portal.Portal, intersectT);

                bool worldOnly = !PortalCommon.IsRoot(instance);
                Portal.Enter(sweep.Portal.Portal, instance, intersectT, false, worldOnly);
                portalEnter?.Invoke(new EnterCallbackData(sweep.Portal.Portal, sweep.Portalable.Instance, intersectT));

                /*After this instance has entered the portal we again go ahead and place it exactly on the
                 * portal (this time on the exit) to reduce precision errors.*/
                PlaceOnPortal(instance, sweep.Portal.Portal.Linked, intersectT);
            }

            Step(moving, portals, stepSize * (1 - tDelta), portalEnter, earliest);
        }
开发者ID:AyyTee,项目名称:Aventyr,代码行数:89,代码来源:SimulationStep.cs

示例5: ValidateCopyToThrows

        private static void ValidateCopyToThrows(
            Action<SqlErrorCollection, SqlError[], int> copyTo,
            Action<SqlErrorCollection> additionalValidation = null)
        {
            SqlErrorCollection c = CreateCollection();

            Assert.Throws<ArgumentNullException>(() => copyTo(c, null, 0));
            Assert.Throws<ArgumentNullException>(() => copyTo(c, null, -1));
            Assert.Throws<ArgumentOutOfRangeException>(() => copyTo(c, new SqlError[10], -1));
            Assert.Throws<ArgumentException>(() => copyTo(c, new SqlError[10], 1000));

            additionalValidation?.Invoke(c);
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:13,代码来源:SqlErrorCollectionTest.cs

示例6: _rayCast

        private static void _rayCast(IPortalable placeable, IEnumerable<IPortal> portals, double movementLeft, IPortal portalPrevious, Action<EnterCallbackData, double> portalEnter, Settings settings, int count)
        {
            Transform2 begin = placeable.GetTransform();
            Transform2 velocity = placeable.GetVelocity().Multiply(settings.TimeScale);
            if (settings.MaxIterations <= count)
            {
                //If we run out of iterations before running out of movement, call _rayEnd with 0 movementLeft just to make sure the AdjustEnpoint setting is handled.
                _rayEnd(placeable, portals, 0, portalPrevious, settings, begin, velocity);
                return;
            }
            if (!placeable.IsPortalable)
            {
                _rayEnd(placeable, portals, movementLeft, portalPrevious, settings, begin, velocity);
                return;
            }
            double distanceMin = movementLeft;
            IPortal portalNearest = null;
            IntersectCoord intersectNearest = new IntersectCoord();
            LineF ray = new LineF(begin.Position, begin.Position + velocity.Position);
            foreach (IPortal p in portals)
            {
                if (!Portal.IsValid(p) || portalPrevious == p)
                {
                    continue;
                }

                LineF portalLine = new LineF(Portal.GetWorldVerts(p));
                IntersectCoord intersect = MathExt.LineLineIntersect(portalLine, ray, true);
                double distance = ((Vector2d)begin.Position - intersect.Position).Length;
                if (intersect.Exists && distance < distanceMin)
                {
                    distanceMin = distance;
                    portalNearest = p;
                    intersectNearest = intersect;
                }
            }
            if (portalNearest != null)
            {
                movementLeft -= distanceMin;

                double t = (velocity.Position.Length - movementLeft) / velocity.Position.Length;

                begin.Position = (Vector2)intersectNearest.Position;
                placeable.SetTransform(begin);
                Portal.Enter(portalNearest, placeable, (float)intersectNearest.TFirst, true);

                portalEnter?.Invoke(new EnterCallbackData(portalNearest, placeable, intersectNearest.TFirst), t);

                movementLeft *= Math.Abs(placeable.GetTransform().Size / begin.Size);
                _rayCast(placeable, portals, movementLeft, portalNearest.Linked, portalEnter, settings, count + 1);
            }
            else
            {
                _rayEnd(placeable, portals, movementLeft, portalPrevious, settings, begin, velocity);
            }
        }
开发者ID:AyyTee,项目名称:Aventyr,代码行数:56,代码来源:Ray.cs

示例7: DoWithCurrentRepo

 void DoWithCurrentRepo(Action<Repository> doWithRepo)
 {
     using (var repo = new Repository(Repository.Discover(TestContext.CurrentContext.TestDirectory)))
     {
         doWithRepo?.Invoke(repo);
     }
 }
开发者ID:Fody,项目名称:Stamp,代码行数:7,代码来源:TokenResolverTests.cs

示例8: IndexPageTree

        /// <summary>
        /// (Re)Indexes the complete page tree for pagedata that inherits from <see cref="IIndexablePageData"/>
        /// </summary>
        /// <param name="swapWithErrors">if set to <c>true</c> and if an error occured during the index process the new index is swapped to live</param>
        /// <param name="onStatusChanges">the action that is executed on status changed during the index process</param>
        /// <returns></returns>
        public IEnumerable<IBulkResponse> IndexPageTree(bool swapWithErrors = false, Action<string> onStatusChanges = null)
        {
            foreach (var languageBranch in LanguageBranchRepository.ListEnabled())
            {
                var language = languageBranch.Culture;
                InitializeIndex(language);

                var aliasName = GetAliasName(language);
                var indexName1 = GetIndexName(language, 1);
                var indexName2 = GetIndexName(language, 2);

                var aliasIndices = ElasticClient.GetAlias(x => x.Name(aliasName)).Indices;
                var liveIndexName = aliasIndices.First().Key;
                var reIndexName = liveIndexName.Equals(indexName1) ? indexName2 : indexName1;

                // clear the reIndex indice since we are re-building it
                Clear(reIndexName, language);

                var indexablePages = GetIndexablePages(language).ToArray();
                var bulkOperations = new List<IBulkOperation>();
                bool hasErrors = false;

                for (var i = 0; i < indexablePages.Length; i++)
                {
                    var indexablePageData = indexablePages[i];
                    if (!indexablePageData.ShouldIndex())
                        continue;

                    var indexModel = CreateIndexModel(indexablePageData);

                    bulkOperations.Add(CreateBulkOperation(indexModel));

                    if (bulkOperations.Count == Options.BulkSize || i == indexablePages.Length - 1)
                    {
                        var bulkRequest = new BulkRequest(reIndexName) {Operations = new List<IBulkOperation>(bulkOperations)};

                        var bulkResponse = ElasticClient.Bulk(bulkRequest);
                        if (!bulkResponse.IsValid || bulkResponse.Errors)
                            hasErrors = true;

                        bulkOperations.Clear();

                        yield return bulkResponse;
                    }

                    onStatusChanges?.Invoke($"Insterted bulk into {reIndexName} currentIndex: {i}");
                }

                if (!hasErrors || swapWithErrors)
                    SwapIndex(liveIndexName, aliasName, reIndexName);
            }
        }
开发者ID:jeroenslor,项目名称:epi-cms-search-elasticsearch,代码行数:58,代码来源:PageDataIndexer.cs


注:本文中的Action.?.Invoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。