Exemple #1
0
        private void MarkToBottom(Base model, bool recursiveCall = false)
        {
            if (!recursiveCall) _cache.Clear();

            if (_cache.Contains(model)) return;

            Mark(model);

            _cache.Add(model);

            var publicProperties = model.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

            var directProperties = publicProperties.Where(x => typeof(Base).IsAssignableFrom(x.PropertyType));

            directProperties.Select(x => x.GetValue(model))
                .Cast<Base>()
                .ToList()
                .ForEach(x => MarkToBottom(x, true));

            var collectionProperties = publicProperties.Where(x => typeof(IEnumerable<Base>).IsAssignableFrom(x.PropertyType));

            collectionProperties.Select(x => x.GetValue(model))
                .Cast<IEnumerable<Base>>()
                .ToList()
                .ForEach(x => x.ToList().ForEach(y => MarkToBottom(y, true)));
        }
Exemple #2
0
 private void Mark(Base model)
 {
     if (model.IsNew())
     {
         model.GenerateId();
         New(model);
     }
     else
     {
         Modified(model);
     }
 }