Beispiel #1
0
        private void TryUpdateId(List <T> data, T item)
        {
            var insertId = GetNextIdValue(data);

            if (insertId == null)
            {
                return;
            }

            ObjectExtensions.AddDataToField(item, _idField, insertId);
        }
Beispiel #2
0
        private T HandleIdUpdate(List <T> data, T item)
        {
            var insertId = GetNextIdValue(data);

            if (insertId == null)
            {
                return(item);
            }

            ObjectExtensions.AddDataToField(item, _idField, insertId);

            // If item doesn't have _idField...

            return(item);
        }
        private T GetItemToInsert(dynamic insertId, T item, Func <T, T> insertConvert)
        {
            if (insertId == null)
            {
                return(insertConvert(item));
            }

            // If item to be inserted is an anonymous type and it is missing the id-field, then add new id-field
            // If it has an id-field, then we trust that user know what value he wants to insert
            if (ObjectExtensions.IsAnonymousType(item) && ObjectExtensions.HasField(item, _idField) == false)
            {
                var toReturn = insertConvert(item);
                ObjectExtensions.AddDataToField(toReturn, _idField, insertId);
                return(toReturn);
            }
            else
            {
                ObjectExtensions.AddDataToField(item, _idField, insertId);
                return(insertConvert(item));
            }
        }