protected override void ImplWrite (
            TextWriter tw, IValueUnit source, IRepositorySerializationContext context )
        {
            if ( context.SerializeMetadata && context.Metadata != null )
                if ( source == null )
                    source = context.Metadata as IValueUnit;
                else
                {
                    IValueUnit wrapperVu = new ValueUnit ();

                    wrapperVu.Add ( "$Metadata", context.Metadata );
                    wrapperVu.Add ( "$Data", source );

                    source = wrapperVu;
                }

            base.ImplWrite ( tw, source, context );
        } // End of ImplWrite (...)
コード例 #2
0
        public async Task CreateOrMergeItemAsync(ShoppingListItem item)
        {
            ShoppingListItem itemOnList = await GetItemByNameAsync(item.OwnerId, item.Name);

            // check if items could be merged
            if (itemOnList != null && (ValueUnit.TryParse(itemOnList.Quantity, out ValueUnit onlistValue) && ValueUnit.TryParse(item.Quantity, out ValueUnit coreDataValue)))
            {
                // merge items
                ValueUnit newValueUnit = ValueUnit.Add(onlistValue, coreDataValue);

                itemOnList.Quantity = newValueUnit.ToString();
            }
            else
            {
                // create new item
                _context.ShoppingListItems.Add(item);
            }
            await _context.SaveChangesAsync();
        }