public void Get() { var id = Guid.NewGuid(); var modl = ModlReflect.New(typeof(EmptyClass), id) as EmptyClass; modl.Save(); modl = ModlReflect.Get(typeof(EmptyClass), id) as EmptyClass; Assert.Equal(typeof(EmptyClass), modl.GetType()); Assert.False(modl.IsNew()); Assert.Equal(id, modl.Id().Get <Guid>()); }
// 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); //} }