本文整理汇总了C#中ResultOperatorBase类的典型用法代码示例。如果您正苦于以下问题:C# ResultOperatorBase类的具体用法?C# ResultOperatorBase怎么用?C# ResultOperatorBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResultOperatorBase类属于命名空间,在下文中一共展示了ResultOperatorBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessResultOperator
/// <summary>
/// Actually try and process this! The count consisits of a count integer and something to increment it
/// at its current spot.
/// </summary>
/// <param name="resultOperator"></param>
/// <param name="queryModel"></param>
/// <param name="codeEnv"></param>
/// <returns></returns>
public Expression ProcessResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, IGeneratedQueryCode gc, ICodeContext cc, CompositionContainer container)
{
if (gc == null)
throw new ArgumentNullException("CodeEnv must not be null!");
var c = resultOperator as CountResultOperator;
if (c == null)
throw new ArgumentNullException("resultOperator can only be a CountResultOperator and must not be null");
//
// The accumulator where we will store the result.
//
var accumulator = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
accumulator.SetInitialValue("0");
//
// Use the Aggregate infrasturcutre to do the adding. This
// has the advantage that it will correctly combine with
// similar statements during query optimization.
//
var add = Expression.Add(accumulator, Expression.Constant((int)1));
var addResolved = ExpressionToCPP.GetExpression(add, gc, cc, container);
gc.Add(new StatementAggregate(accumulator, addResolved));
return accumulator;
}
示例2: ProcessResultOperator
/// <summary>
/// Implement the skipping. We have a main limitation: we currently know only how to implement integer skipping.
/// We implement with "if" statements to support composability, even if it means running longer in the end...
/// We actually return nothing when goes - we aren't really a final result the way "Count" is.
/// </summary>
/// <param name="resultOperator"></param>
/// <param name="queryModel"></param>
/// <param name="_codeEnv"></param>
/// <returns></returns>
public void ProcessResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, IGeneratedQueryCode codeEnv, ICodeContext codeContext, CompositionContainer container)
{
///
/// Quick checks to make sure
///
if (codeEnv == null)
throw new ArgumentNullException("codeEnv cannot be null");
var take = resultOperator as TakeResultOperator;
var skip = resultOperator as SkipResultOperator;
if (take == null && skip == null)
{
throw new ArgumentNullException("resultOperator must not be null and must represent either a take or a skip operation!");
}
if (take != null && take.Count.Type != typeof(int))
throw new ArgumentException("Take operator count must be an integer!");
if (skip != null && skip.Count.Type != typeof(int))
throw new ArgumentException("Skip operator count must be an integer!");
// If this is a "global" take, then we need to declare the variable a bit specially.
// Global: we have a limit on the number of objects that goes across events. We test this by seeing if this
// is a sub-query that is registered (or not).
var isGlobalTake = codeContext.IsInTopLevelQueryModel(queryModel);
// Now, we create a count variable and that is how we will tell if we are still skipping or
// taking. It must be declared in the current block, before our current code! :-)
var counter = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int), otherDependencies: codeContext.LoopIndexVariable.Return<IDeclaredParameter>());
if (isGlobalTake)
{
counter.DeclareAsStatic = true;
codeEnv.Add(counter);
} else
{
codeEnv.AddOutsideLoop(counter);
}
var comparison = StatementIfOnCount.ComparisonOperator.LessThanEqual;
IValue limit = null;
if (skip != null)
{
comparison = StatementIfOnCount.ComparisonOperator.GreaterThan;
limit = ExpressionToCPP.GetExpression(skip.Count, codeEnv, codeContext, container);
}
else
{
limit = ExpressionToCPP.GetExpression(take.Count, codeEnv, codeContext, container);
}
codeEnv.Add(new StatementIfOnCount(counter, limit, comparison));
///
/// We are particularly fortunate here. We don't have to update the Loop variable - whatever it is, is
/// still the right one! Normally we'd have to futz with the LoopVariable in code context because we
/// were iterating over something new. :-) Easy!
///
}
示例3: VisitResultOperator
#pragma warning restore 649
/// <summary>
/// Process a result operator. If this result is amenable to be made into a function, then
/// do so.
/// </summary>
/// <param name="resultOperator"></param>
/// <param name="queryModel"></param>
/// <param name="index"></param>
public override void VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, int index)
{
// Look for a single-result processor
var processor = _operators.FindScalarROProcessor(resultOperator.GetType());
if (processor != null)
{
var result = processor.ProcessResultOperator(resultOperator, queryModel, _codeEnv, _codeContext, MEFContainer);
if (result != null)
{
_codeEnv.SetResult(result);
_scoping.Add(_codeContext.Add(queryModel, result));
}
return;
}
// Look for a sequence processor
var collectionProcessor = _operators.FindCollectionROProcessor(resultOperator.GetType());
if (collectionProcessor != null)
{
collectionProcessor.ProcessResultOperator(resultOperator, queryModel, _codeEnv, _codeContext, MEFContainer);
_codeEnv.ResetResult();
return;
}
///
/// Uh oh - no idea how to do this!
///
throw new InvalidOperationException("LINQToTTree can't translate the operator '" + resultOperator.ToString() + "'");
}
示例4: VisitResultOperator
/// <summary>
/// Visits the result operator.
/// </summary>
/// <param name="resultOperator">The result operator.</param>
/// <param name="queryModel">The query model.</param>
/// <param name="index">The index.</param>
public override void VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, int index)
{
if (resultOperator is CountResultOperator)
{
this.IsCount = true;
}
else
throw new NotSupportedException(string.Format("Operator {0} is not supported.", resultOperator.GetType()));
}
示例5: ProcessResultOperator
internal void ProcessResultOperator(
[PexAssumeUnderTest]ROUniqueCombinations target,
ResultOperatorBase resultOperator,
QueryModel queryModel,
CodeContext cc,
[PexAssumeNotNull]GeneratedCode codeEnv
)
{
target.ProcessResultOperator(resultOperator, queryModel, codeEnv, cc, null);
}
示例6: ProcessIdentityQuery
/// <summary>
/// Try to do a fast count. Basically, what we are dealing with here is the fact that we have
/// a simple array, we need only take its length, and return that.
/// </summary>
/// <param name="resultOperator"></param>
/// <param name="queryModel"></param>
/// <param name="_codeEnv"></param>
/// <param name="_codeContext"></param>
/// <param name="container"></param>
/// <returns></returns>
public Tuple<bool, Expression> ProcessIdentityQuery(ResultOperatorBase resultOperator, QueryModel queryModel, IGeneratedQueryCode _codeEnv, ICodeContext _codeContext, CompositionContainer container)
{
//
// We just need to return a length expression. We are low enough level we need to do some basic resolution.
//
if (!queryModel.MainFromClause.FromExpression.Type.IsArray)
return Tuple.Create(false, null as Expression);
var lengthExpr = Expression.ArrayLength(queryModel.MainFromClause.FromExpression).Resolve(_codeEnv, _codeContext, container);
return Tuple.Create(true, lengthExpr as Expression);
}
示例7: VisitResultOperator
public override void VisitResultOperator (ResultOperatorBase resultOperator, QueryModel queryModel, int index)
{
ArgumentUtility.CheckNotNull ("resultOperator", resultOperator);
ArgumentUtility.CheckNotNull ("queryModel", queryModel);
var fetchRequest = resultOperator as FetchRequestBase;
if (fetchRequest != null)
{
queryModel.ResultOperators.RemoveAt (index);
_fetchQueryModelBuilders.Add (new FetchQueryModelBuilder (fetchRequest, queryModel, index));
}
}
示例8: VisitResultOperator
public override void VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, int index)
{
if (resultOperator is CountResultOperator)
{
// For count operators, we can remove any order-by result operators
foreach (var orderby in queryModel.BodyClauses.Where(bc => bc is OrderByClause).ToList())
{
queryModel.BodyClauses.Remove(orderby);
}
}
base.VisitResultOperator(resultOperator, queryModel, index);
}
示例9: ProcessResultOperator
internal Expression ProcessResultOperator(
[PexAssumeUnderTest]ROMinMax target,
ResultOperatorBase resultOperator,
QueryModel queryModel,
IGeneratedQueryCode gc,
ICodeContext cc,
CompositionContainer container
)
{
Expression result
= target.ProcessResultOperator(resultOperator, queryModel, gc, cc, container);
return result;
// TODO: add assertions to method ROMinMaxTest.ProcessResultOperator(ROMinMax, ResultOperatorBase, QueryModel, IGeneratedQueryCode, ICodeContext, CompositionContainer)
}
示例10: VisitResultOperator
public override void VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, int index)
{
var handler = resultOperators.GetItem(resultOperator.GetType());
if (handler != null)
{
handler.Accept(resultOperator, model);
}
else
{
model.ApplyUnsupported(resultOperator);
}
base.VisitResultOperator(resultOperator, queryModel, index);
}
示例11: VisitResultOperator
public override void VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, int index)
{
if (resultOperator is FirstResultOperator)
{
_queryParts.Take = 1;
return;
}
if (resultOperator is CountResultOperator || resultOperator is LongCountResultOperator)
{
_queryParts.ReturnCount = true;
return;
}
if (resultOperator is TakeResultOperator)
{
var exp = ((TakeResultOperator)resultOperator).Count;
if (exp.NodeType == ExpressionType.Constant)
{
_queryParts.Take = (int)((ConstantExpression)exp).Value;
}
else
{
throw new NotSupportedException("Currently not supporting methods or variables in the Skip or Take clause.");
}
return;
}
if (resultOperator is SkipResultOperator)
{
var exp = ((SkipResultOperator) resultOperator).Count;
if (exp.NodeType == ExpressionType.Constant)
{
_queryParts.Skip = (int)((ConstantExpression)exp).Value;
}
else
{
throw new NotSupportedException("Currently not supporting methods or variables in the Skip or Take clause.");
}
return;
}
base.VisitResultOperator(resultOperator, queryModel, index);
}
示例12: ProcessResultOperator
/// <summary>
/// Take the incoming stream of items, and send them along! :-)
/// </summary>
/// <param name="resultOperator"></param>
/// <param name="queryModel"></param>
/// <param name="_codeEnv"></param>
/// <param name="_codeContext"></param>
/// <param name="container"></param>
public void ProcessResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, IGeneratedQueryCode gc, ICodeContext cc, CompositionContainer container)
{
//
// Some basic checks on the input.
//
if (cc == null)
throw new ArgumentNullException("cc");
if (gc == null)
throw new ArgumentNullException("gc");
if (cc.LoopVariable == null)
throw new ArgumentNullException("No defined loop variable!");
//
// Get the indexer that is being used to access things. We will just push that onto a temp vector of int's. That will be
// a list of the items that we want to come back and look at. That said, once done we need to pop-up one level in our
// depth.
//
var arrayRecord = DeclarableParameter.CreateDeclarableParameterArrayExpression(typeof(int));
gc.AddOutsideLoop(arrayRecord);
var recordIndexStatement = new Statements.StatementRecordIndicies(ExpressionToCPP.GetExpression(cc.LoopIndexVariable.AsExpression(), gc, cc, container), arrayRecord);
gc.Add(recordIndexStatement);
gc.Pop();
//
// Now, we go down one loop and run over the pairs with a special loop.
//
var index1 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
var index2 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
var indexIterator = new Statements.StatementPairLoop(arrayRecord, index1, index2);
gc.Add(indexIterator);
//
// Finally, build the resulting loop variable. For now it is just a tuple, which is basically the formed expression we started with,
// but with the other index properties. Other bits will have to do the translation for us. :-)
//
var item1 = cc.LoopVariable.ReplaceSubExpression(cc.LoopIndexVariable.AsExpression(), index1);
var item2 = cc.LoopVariable.ReplaceSubExpression(cc.LoopIndexVariable.AsExpression(), index2);
var tupleType = typeof(Tuple<,>).MakeGenericType(cc.LoopVariable.Type, cc.LoopVariable.Type);
var newTuple = Expression.New(tupleType.GetConstructor(new Type[] { cc.LoopVariable.Type, cc.LoopVariable.Type }), item1, item2);
cc.SetLoopVariable(newTuple, null);
}
示例13: HandleContains
public static List<Expression> HandleContains(ResultOperatorBase resultOperator, IEnumerable values)
{
List<Expression> expressions = new List<Expression>();
if (resultOperator is ContainsResultOperator && values != null)
{
var cro = resultOperator as ContainsResultOperator;
foreach (var v in values)
{
expressions.Add(
Expression.Equal(cro.Item, Expression.Convert(Expression.Constant(v), cro.Item.Type)));
}
}
return expressions;
}
示例14: HandleResultOperator
public virtual Expression HandleResultOperator(
EntityQueryModelVisitor entityQueryModelVisitor,
ResultOperatorBase resultOperator,
QueryModel queryModel)
{
Check.NotNull(entityQueryModelVisitor, nameof(entityQueryModelVisitor));
Check.NotNull(resultOperator, nameof(resultOperator));
Check.NotNull(queryModel, nameof(queryModel));
ResultHandler handler;
if (!_handlers.TryGetValue(resultOperator.GetType(), out handler))
{
throw new NotImplementedException(resultOperator.GetType().ToString());
}
return handler(entityQueryModelVisitor, resultOperator, queryModel);
}
示例15: VisitResultOperator
public override void VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, int index)
{
if (resultOperator is CountResultOperator || resultOperator is LongCountResultOperator)
{
// For count operators, we can remove any order-by result operators
foreach (IBodyClause orderby in queryModel.BodyClauses.Where(bc => bc is OrderByClause).ToList())
{
queryModel.BodyClauses.Remove(orderby);
}
}
if (resultOperator is CastResultOperator)
{
Array.ForEach(queryModel.ResultOperators.OfType<CastResultOperator>().ToArray(), castOperator=> queryModel.ResultOperators.Remove(castOperator));
}
base.VisitResultOperator(resultOperator, queryModel, index);
}
开发者ID:khaliyo,项目名称:Spring.net-NHibernate.net-Asp.net-MVC-DWZ-,代码行数:17,代码来源:RemoveUnnecessaryBodyOperators.cs