Exemplo n.º 1
0
        public virtual IApiItemBuilder <TItem> Item <TItem>()
            where TItem : class, new()
        {
            var itemModel = Model.Roots.FirstOrDefault(i => i.ItemType == typeof(TItem)) as ApiItemModel <TItem>
                            ?? CreateNewItemModel <TItem>();

            var itemBuilder = new EngineItemBuilder <TItem>(itemModel);

            return(itemBuilder);
        }
Exemplo n.º 2
0
        public IApiItemBuilder <TNavItem> IsItem <TNavItem>()
            where TNavItem : class, TField, new()
        {
            var itemModel = new ApiItemModel <TNavItem>(null); // can be null because GetRootCollection never called for navigation properties
            IEngineSubContext <TNavItem> subContext = new FluentEngineSubContext <TNavItem>(itemModel);

            var castedExpression = _expression as Expression <Func <TItem, TNavItem> >; // should cast fine due to generic constraint

            var navTools = new SubWriterTools <TItem, TNavItem, TNavItem>(castedExpression, itemModel.Events, _setter);

            _fieldModel.Reader         = new SubItemFieldReader <TItem, TNavItem>(castedExpression, subContext);
            _fieldModel.Collator       = new NotSupportedFieldCollator <TItem>("sub items");
            _fieldModel.ResourceGetter = new SubItemResourceGetter <TItem, TNavItem>(navTools, subContext);
            _fieldModel.Writer         = new SubItemFieldWriter <TItem, TNavItem>(navTools, subContext);

            var itemBuilder = new EngineItemBuilder <TNavItem>(itemModel);

            return(itemBuilder);
        }