當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。