コード例 #1
0
 public static void CleanAll(this IDirtyCheck sender)
 {
     sender.WalkObjectGraph(o => { if (o.IsDirty)
                                   {
                                       o.IsDirty = false;
                                   }
                                   return(false); }, coll => { });
 }
コード例 #2
0
 public static void OnPropertyChanged(this IDirtyCheck sender, PropertyChangedEventHandler handler, [CallerMemberName] string propertyName = "")
 {
     if (handler != null)
     {
         handler(sender, new PropertyChangedEventArgs(propertyName));
     }
     sender.IsDirty = true;
     //sender.OnDirty();
 }
コード例 #3
0
        public static bool IsAnythingDirty(this IDirtyCheck sender)
        {
            bool isDirty = false;

            sender.WalkObjectGraph(o => { if (o.IsDirty)
                                          {
                                              isDirty = true; return(true);
                                          }
                                          return(false); }, coll => { });
            return(isDirty);
        }
コード例 #4
0
        public static void WalkObjectGraph(this IDirtyCheck sender, Func <IDirtyCheck, bool> snippetForObject, Action <IList> snippetForCollection, params string[] exemptProperties)
        {
            var visited = new List <IDirtyCheck>();
            Action <IDirtyCheck> walk = null;

            walk = (o) =>
            {
                if (o != null && !visited.Contains(o))
                {
                    visited.Add(o);
                    bool exitWalk = snippetForObject.Invoke(o);
                    if (!exitWalk)
                    {
                        PropertyInfo[] properties = o.GetBrowsableProperties();
                        foreach (PropertyInfo property in properties)
                        {
                            if (!exemptProperties.Contains(property.Name))
                            {
#if DNXCORE50
                                var issub = property.PropertyType.GetTypeInfo().IsSubclassOf(typeof(IDirtyCheck));
                                //for Assign property.PropertyType.GetTypeInfo().IsAssignableFrom(type.GetTypeInfo());
#else
                                var issub = property.PropertyType.IsSubclassOf(typeof(IDirtyCheck));
#endif

                                if (issub)
                                {
                                    var obj = (IDirtyCheck)(property.GetValue(o, null));
                                    walk(obj);
                                }
                                else
                                {
                                    var coll = property.GetValue(o, null) as IList;
                                    if (coll != null)
                                    {
                                        snippetForCollection.Invoke(coll);
                                        foreach (object item in coll)
                                        {
                                            var check = item as IDirtyCheck;
                                            if (check != null)
                                            {
                                                walk(check);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };
            walk(sender);
        }
コード例 #5
0
ファイル: ExtensionMethods.cs プロジェクト: mmercan/SearchEng
        public static void dispose(this IDirtyCheck dirty)
        {
            // string s = "Hi";
            //  var w = s.GetType().IsPrimitive;

            List <object> objects = new List <object>();

            Walk <object>(dirty, (d) =>
            {
                objects.Add(d);
                return(false);
            }, null, null);
        }
コード例 #6
0
ファイル: ExtensionMethods.cs プロジェクト: mmercan/SearchEng
        public static void ResetAllDirtyObjects(this IDirtyCheck dirty)
        {
            List <IDirtyCheck> dirtyObjects = new List <IDirtyCheck>();

            Walk <IDirtyCheck>(dirty, (d) =>
            {
                if (d.IsDirty)
                {
                    d.IsDirty = false;
                }
                return(false);
            }, null, null);
        }
コード例 #7
0
        public static List <IDirtyCheck> GetDirtyObjects(this IDirtyCheck sender)
        {
            string[] dontCheck   = { "IsDirty" };
            var      dirtyobjecs = new List <IDirtyCheck>();

            sender.WalkObjectGraph(o =>
            {
                if (o.IsDirty)
                {
                    dirtyobjecs.Add(o);
                }
                return(false);
            }, coll => { }, dontCheck);
            return(dirtyobjecs);
        }
コード例 #8
0
ファイル: ExtensionMethods.cs プロジェクト: mmercan/SearchEng
        public static bool CheckDirty(this IDirtyCheck dirt)
        {
            bool isDirty = false;

            Walk <IDirtyCheck>(dirt, (d) => { if (d.IsDirty)
                                              {
                                                  isDirty = true; return(true);
                                              }
                                              else
                                              {
                                                  return(false);
                                              } }, null, null);

            return(isDirty);
        }