public bool AddDataServiceCollection(object source, string sourceProperty, object collection, string collectionEntitySet) { if (this.graph.ExistsVertex(collection)) { return(false); } Vertex vertex = this.graph.AddVertex(collection); vertex.IsDataServiceCollection = true; vertex.EntitySet = collectionEntitySet; ICollection is2 = collection as ICollection; if (source != null) { vertex.Parent = this.graph.LookupVertex(source); vertex.ParentProperty = sourceProperty; this.graph.AddEdge(source, collection, sourceProperty); Type collectionEntityType = BindingUtils.GetCollectionEntityType(collection.GetType()); if (!typeof(INotifyPropertyChanged).IsAssignableFrom(collectionEntityType)) { throw new InvalidOperationException(System.Data.Services.Client.Strings.DataBinding_NotifyPropertyChangedNotImpl(collectionEntityType)); } typeof(BindingGraph).GetMethod("SetObserver", false, false).MakeGenericMethod(new Type[] { collectionEntityType }).Invoke(this, new object[] { is2 }); } else { this.graph.Root = vertex; } this.AttachDataServiceCollectionNotification(collection); foreach (object obj2 in is2) { this.AddEntity(source, sourceProperty, obj2, collectionEntitySet, collection); } return(true); }
public bool AddCollection( object source, string sourceProperty, object collection, string collectionEntitySet) { Debug.Assert(collection != null, "'collection' can not be null"); Debug.Assert( BindingEntityInfo.IsDataServiceCollection(collection.GetType()), "Argument 'collection' must be an DataServiceCollection<T> of entity type T"); if (this.graph.ExistsVertex(collection)) { return(false); } Vertex collectionVertex = this.graph.AddVertex(collection); collectionVertex.IsCollection = true; collectionVertex.EntitySet = collectionEntitySet; ICollection collectionItf = collection as ICollection; if (source != null) { collectionVertex.Parent = this.graph.LookupVertex(source); collectionVertex.ParentProperty = sourceProperty; this.graph.AddEdge(source, collection, sourceProperty); Type entityType = BindingUtils.GetCollectionEntityType(collection.GetType()); Debug.Assert(entityType != null, "Collection must at least be inherited from DataServiceCollection<T>"); if (!typeof(INotifyPropertyChanged).IsAssignableFrom(entityType)) { throw new InvalidOperationException(Strings.DataBinding_NotifyPropertyChangedNotImpl(entityType)); } typeof(BindingGraph) .GetMethod("SetObserver", BindingFlags.Instance | BindingFlags.NonPublic) .MakeGenericMethod(entityType) .Invoke(this, new object[] { collectionItf }); } else { this.graph.Root = collectionVertex; } Debug.Assert( collectionVertex.Parent != null || collectionVertex.IsRootCollection, "If parent is null, then collectionVertex should be a root collection"); this.AttachCollectionNotification(collection); foreach (var item in collectionItf) { this.AddEntity( source, sourceProperty, item, collectionEntitySet, collection); } return(true); }