本文整理汇总了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);
}
}
示例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();
}