/// <summary> /// Returns a collection of filtered Relationships that are /// owned by this PackagePart /// The relationshipType string is compared with the type of the relationships /// in a case sensitive and culture ignorant manner. /// </summary> /// <returns></returns> /// <exception cref="InvalidOperationException">If this part has been deleted</exception> /// <exception cref="InvalidOperationException">If the parent package has been closed or disposed</exception> /// <exception cref="IOException">If the package is write only, no information can be retrieved from it</exception> /// <exception cref="ArgumentNullException">If parameter "relationshipType" is null</exception> /// <exception cref="ArgumentException">If parameter "relationshipType" is an empty string</exception> public PackageRelationshipCollection GetRelationshipsByType(string relationshipType) { //These checks are made in the GetRelationshipsHelper as well, but we make them //here as we need to perform parameter validation CheckInvalidState(); _container.ThrowIfWriteOnly(); if (relationshipType == null) { throw new ArgumentNullException("relationshipType"); } InternalRelationshipCollection.ThrowIfInvalidRelationshipType(relationshipType); return(GetRelationshipsHelper(relationshipType)); }
//------------------------------------------------------ // // Public Constructors // //------------------------------------------------------ #region Public Constructor /// <summary> /// Constructor /// </summary> /// <param name="sourceUri">Source Uri of the PackagePart or PackageRoot ("/") that owns the relationship</param> /// <param name="selectorType">PackageRelationshipSelectorType enum representing the type of the selectionCriteria</param> /// <param name="selectionCriteria">The actual string that is used to select the relationships</param> /// <exception cref="ArgumentNullException">If sourceUri is null</exception> /// <exception cref="ArgumentNullException">If selectionCriteria is null</exception> /// <exception cref="ArgumentOutOfRangeException">If selectorType Enumeration does not have a valid value</exception> /// <exception cref="System.Xml.XmlException">If PackageRelationshipSelectorType.Id and selection criteria is not valid Xsd Id</exception> /// <exception cref="ArgumentException">If PackageRelationshipSelectorType.Type and selection criteria is not valid relationship type</exception> /// <exception cref="ArgumentException">If sourceUri is not "/" to indicate the PackageRoot, then it must conform to the /// valid PartUri syntax</exception> public PackageRelationshipSelector(Uri sourceUri, PackageRelationshipSelectorType selectorType, string selectionCriteria) { if (sourceUri == null) { throw new ArgumentNullException("sourceUri"); } if (selectionCriteria == null) { throw new ArgumentNullException("selectionCriteria"); } //If the sourceUri is not equal to "/", it must be a valid part name. if (Uri.Compare(sourceUri, PackUriHelper.PackageRootUri, UriComponents.SerializationInfoString, UriFormat.UriEscaped, StringComparison.Ordinal) != 0) { sourceUri = PackUriHelper.ValidatePartUri(sourceUri); } //selectionCriteria is tested here as per the value of the selectorType. //If selectionCriteria is empty string we will throw the appropriate error message. if (selectorType == PackageRelationshipSelectorType.Type) { InternalRelationshipCollection.ThrowIfInvalidRelationshipType(selectionCriteria); } else if (selectorType == PackageRelationshipSelectorType.Id) { InternalRelationshipCollection.ThrowIfInvalidXsdId(selectionCriteria); } else { throw new ArgumentOutOfRangeException("selectorType"); } _sourceUri = sourceUri; _selectionCriteria = selectionCriteria; _selectorType = selectorType; }