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


C# Expression.Skip方法代码示例

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


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

示例1: ThenTheLoadedTasksShouldHaveTheSameAttributesAsTheOriginalSetOfTasks

        public void ThenTheLoadedTasksShouldHaveTheSameAttributesAsTheOriginalSetOfTasks()
        {
            var newTasks = _context.Get<IRepository<Task>>().FindAll().ToArray();
            foreach (var newTask in newTasks)
            {
                Task task = newTask;
                var oldTask = _loadedTasks.Where(t => t.Id == task.Id).FirstOrDefault();
                oldTask.Should().NotBeNull();

                var dateFuncs = new Expression<Func<Task, object>>[]
                    {
                        t => t.CreatedDate,
                        t => t.AbandonedDate,
                        t => t.CompletedDate,
                        t => t.ModifiedDate,
                        t => t.StartedDate,
                        t => t.StateChangedDate
                    };

                var links = new Expression<Func<Task, object>>[]
                    {
                        t => t.LessImportantTasks,
                        t => t.MoreImportantTasks,
                        t => t.Parent,
                        t => t.SubTasks
                    };

                CheckDates(oldTask, newTask, dateFuncs);

                newTask.ShouldHave().AllProperties().But(
                    t => t.CreatedDate,
                    dateFuncs.Skip(1).Concat(links).ToArray()
                    ).EqualTo(oldTask);

            }
        }
开发者ID:ArildF,项目名称:PTB,代码行数:36,代码来源:TaskBoardSteps.cs

示例2: GetFunc

        public object GetFunc([NotNull] params Type[] funcTypes)
        {
            // If the method is not closed or doesn't have return type, were' done.
            if ((Info.ContainsGenericParameters) ||
                (Info.ReturnType == typeof(void)))
                return null;

            bool isStatic = Info.IsStatic;

            int tCount = funcTypes.Count();
            // Create array for required func types - statics take an instance as the first parameter
            Type[] signatureTypes = new Type[tCount - 1];
            int a = 0;
            if (!isStatic)
            {
                if (tCount < 1)
                    return null;
                signatureTypes[a++] = ExtendedType.Type;
            }

            // Now add parameter types.
            int p = 0;
            ParameterInfo[] parameters = _parameters.Value;
            Debug.Assert(parameters != null);

            int pCount = parameters.Length;
            for (; a < tCount - 1; a++)
            {
                // Check if we run out of parameters.
                if (p >= pCount)
                    return null;

                Debug.Assert(parameters[p] != null);

                // Func's don't support output, pointer, or by reference parameters
                if (parameters[p].IsOut ||
                    parameters[p].ParameterType.IsByRef ||
                    parameters[p].ParameterType.IsPointer)
                    return null;

                // ReSharper disable once PossibleNullReferenceException
                signatureTypes[a] = parameters[p++].ParameterType;
            }

            // Any remaining parameters must be optional.
            // ReSharper disable once PossibleNullReferenceException
            if ((p < pCount) &&
                (!parameters[p].IsOptional))
                return null;

            // Create expressions
            ParameterExpression[] parameterExpressions = new ParameterExpression[tCount - 1];
            Expression[] pExpressions = new Expression[tCount - 1];
            for (int i = 0; i < tCount - 1; i++)
            {
                Type funcType = funcTypes[i];
                Type signatureType = signatureTypes[i];

                Debug.Assert(funcType != null);
                Debug.Assert(signatureType != null);

                // Create parameter
                parameterExpressions[i] = Expression.Parameter(funcType);
                if (funcType != signatureType)
                {
                    // Try to convert from the input funcType to the underlying parameter type.
                    if (!parameterExpressions[i].TryConvert(signatureType, out pExpressions[i]))
                        return null;
                }
                else
                // No conversion necessary.
                    pExpressions[i] = parameterExpressions[i];
            }

            // Create call expression, instance methods use the first parameter of the Func<> as the instance, static
            // methods do not supply an instance.
            Expression expression = isStatic
                ? Expression.Call(Info, pExpressions)
                : Expression.Call(pExpressions[0], Info, pExpressions.Skip(1));

            // Check if we need to do a cast to the func result type
            if (funcTypes[tCount - 1] != Info.ReturnType &&
                // ReSharper disable once AssignNullToNotNullAttribute
                !expression.TryConvert(funcTypes[tCount - 1], out expression))
                return null;

            return Expression.Lambda(expression, parameterExpressions).Compile();
        }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:88,代码来源:Method.cs


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