// Set up a proeprty that will hold the current item being enumerated. //public SampleDataSourceItem Current { get; private set; } public IEnumerable <T> ExecuteCollection <T>(QueryModel queryModel) { foreach (var id in ModlReflect.List(typeof(T))) { yield return((T)ModlReflect.Get(typeof(T), id)); } //return new List<M>(); //for (var i = 0; i < 10; i++) //{ // yield return (T)Modl.New(typeof(T)); //} //// Create an expression that returns the current item when invoked. //Expression currentItemExpression = Expression.Property(Expression.Constant(this), "Current"); //// Now replace references like the "i" in "select i" that refers to the "i" in "from i in items" //var mapping = new QuerySourceMapping(); //mapping.AddMapping(queryModel.MainFromClause, currentItemExpression); ////queryModel.TransformExpressions(e => ReferenceReplacingExpressionTreeVisitor.ReplaceClauseReferences(e, mapping, true)); //// Create a lambda that takes our SampleDataSourceItem and passes it through the select clause //// to produce a type of T. (T may be SampleDataSourceItem, in which case this is an identity function.) //var currentItemProperty = Expression.Parameter(typeof(SampleDataSourceItem)); //var projection = Expression.Lambda<Func<SampleDataSourceItem, T>>(queryModel.SelectClause.Selector, currentItemProperty); //var projector = projection.Compile(); //// Pretend we're getting SampleDataSourceItems from somewhere... //for (var i = 0; i < 10; i++) //{ // // Set the current item so currentItemExpression can access it. // Current = new SampleDataSourceItem // { // Name = "Name " + i, // Description = "This describes the item in position " + i // }; // // Use the projector to convert (if necessary) the current item to what is being selected and return it. // yield return projector(Current); //} }
public void List() { var modl = ModlReflect.New(typeof(EmptyClass)) as EmptyClass; modl.Save(); var modl2 = ModlReflect.New(typeof(EmptyClass)) as EmptyClass; modl2.Save(); var modlList = ModlReflect.List(typeof(EmptyClass)).ToList(); Assert.NotEqual(0, modlList.Count); Assert.True(modlList.Any(x => (Guid)x == modl.Id().Get <Guid>())); Assert.True(modlList.Any(x => (Guid)x == modl2.Id().Get <Guid>())); var modlList2 = ModlReflect.List <Guid>(typeof(EmptyClass)).ToList(); Assert.NotEqual(0, modlList2.Count); Assert.True(modlList2.Any(x => x == modl.Id().Get <Guid>())); Assert.True(modlList2.Any(x => x == modl2.Id().Get <Guid>())); }