private ICollection <TNav> GetNavCollection()
        {
            TParent            parentItem;
            IEnumerable <TNav> navEnumerable;

            try
            {
                parentItem    = _parentItem.LoadedItem;
                navEnumerable = _navExpression.Compile().Invoke(parentItem);
            }
            catch (Exception ex)
            {
                throw new NotSupportedException("Error getting navigation collection from parent item.", ex);
            }

            if (navEnumerable == null)
            {
                var newList    = new List <TNav>();
                var castedList = newList as TCollection;
                Debug.Assert(castedList != null, "This should always cast. Is it not covariant?");

                _setter.SetNavItem(parentItem, castedList);
                return(newList);
            }

            var navCollection = navEnumerable as ICollection <TNav>;

            if (navCollection == null)
            {
                throw new NotSupportedException("Cannot add items to this navigation property because it does not implement ICollection.");
            }

            return(navCollection);
        }
示例#2
0
        public async Task SetValueAsync(IDeferredItem <TItem> item, object deserializedValue, IDataTransaction dataTransaction)
        {
            TNav navValue = ConversionUtility.ConvertValue <TNav>(deserializedValue);

            await item.LoadAsync();

            _setter.SetNavItem(item.LoadedItem, navValue);
        }
        private void SetParentNavItem(TNav item)
        {
            var parent = _parentItem.Query.First();

            _setter.SetNavItem(parent, item);
        }