Exemplo n.º 1
0
        private void AutoSyncMembers(object[] syncResults, TrackedObject item, UpdateType updateType, AutoSyncBehavior autoSyncBehavior)
        {
            System.Diagnostics.Debug.Assert(item != null);
            System.Diagnostics.Debug.Assert(item.IsNew || item.IsPossiblyModified, "AutoSyncMembers should only be called for new and modified objects.");
            object[] syncRollbackValues = null;
            if (syncResults != null)
            {
                int idx           = 0;
                var membersToSync = GetAutoSyncMembers(item.Type, updateType);
                System.Diagnostics.Debug.Assert(syncResults.Length == membersToSync.Count);
                if (autoSyncBehavior == AutoSyncBehavior.ApplyNewAutoSync)
                {
                    syncRollbackValues = new object[syncResults.Length];
                }
                foreach (MetaDataMember mm in membersToSync)
                {
                    object       value    = syncResults[idx];
                    object       current  = item.Current;
                    MetaAccessor accessor =
                        (mm.Member is PropertyInfo && ((PropertyInfo)mm.Member).CanWrite)
                                                        ? mm.MemberAccessor
                                                        : mm.StorageAccessor;

                    if (syncRollbackValues != null)
                    {
                        syncRollbackValues[idx] = accessor.GetBoxedValue(current);
                    }
                    accessor.SetBoxedValue(ref current, DBConvert.ChangeType(value, mm.Type));
                    idx++;
                }
            }
            if (syncRollbackValues != null)
            {
                this.SyncRollbackItems.Add(new KeyValuePair <TrackedObject, object[]>(item, syncRollbackValues));
            }
        }
            private void AutoSyncMembers(object[] syncResults, TrackedObject item, UpdateType updateType, AutoSyncBehavior autoSyncBehavior) {
                System.Diagnostics.Debug.Assert(item != null);
                System.Diagnostics.Debug.Assert(item.IsNew || item.IsPossiblyModified, "AutoSyncMembers should only be called for new and modified objects.");
                object[] syncRollbackValues = null;
                if (syncResults != null) {
                    int idx = 0;
                    List<MetaDataMember> membersToSync = GetAutoSyncMembers(item.Type, updateType);
                    System.Diagnostics.Debug.Assert(syncResults.Length == membersToSync.Count);                    
                    if (autoSyncBehavior == AutoSyncBehavior.ApplyNewAutoSync) {
                        syncRollbackValues = new object[syncResults.Length];
                    }
                    foreach (MetaDataMember mm in membersToSync) {
                        object value = syncResults[idx];
                        object current = item.Current;
                        MetaAccessor accessor =
                            (mm.Member is PropertyInfo && ((PropertyInfo)mm.Member).CanWrite)
                                ? mm.MemberAccessor
                                : mm.StorageAccessor;

                        if (syncRollbackValues != null) {
                            syncRollbackValues[idx] = accessor.GetBoxedValue(current);
                        }
                        accessor.SetBoxedValue(ref current, DBConvert.ChangeType(value, mm.Type));
                        idx++;
                    }                    
                }
                if (syncRollbackValues != null) {
                    this.SyncRollbackItems.Add(new KeyValuePair<TrackedObject, object[]>(item, syncRollbackValues));
                }
            }
Exemplo n.º 3
0
 private void AutoSyncMembers(object[] syncResults, TrackedObject item, UpdateType updateType, AutoSyncBehavior autoSyncBehavior)
 {
     object[] array = null;
     if (syncResults != null)
     {
         var num             = 0;
         var autoSyncMembers = GetAutoSyncMembers(item.Type, updateType);
         if (autoSyncBehavior == AutoSyncBehavior.ApplyNewAutoSync)
         {
             array = new object[syncResults.Length];
         }
         foreach (var item2 in autoSyncMembers)
         {
             var value        = syncResults[num];
             var instance     = item.Current;
             var metaAccessor = (item2.Member is PropertyInfo && ((PropertyInfo)item2.Member).CanWrite) ? item2.MemberAccessor : item2.StorageAccessor;
             if (array != null)
             {
                 array[num] = metaAccessor.GetBoxedValue(instance);
             }
             metaAccessor.SetBoxedValue(ref instance, DBConvert.ChangeType(value, item2.Type));
             num++;
         }
     }
     if (array != null)
     {
         SyncRollbackItems.Add(new KeyValuePair <TrackedObject, object[]>(item, array));
     }
 }