// can not use generic, at it will emit error // Compiler Error CS0310 // The type 'typename' must have a public parameterless constructor in order to use it as parameter 'parameter' in the generic type or method 'generic' internal sealed override OpenXmlPart NewPart(string relationshipType, string contentType) { ThrowIfObjectDisposed(); if (contentType == null) { throw new ArgumentNullException(nameof(contentType)); } if (PartConstraints.TryGetValue(relationshipType, out var partConstraintRule)) { if (!partConstraintRule.MaxOccursGreatThanOne) { if (GetSubPart(relationshipType) != null) { // already have one, can not add new one. throw new InvalidOperationException(ExceptionMessages.OnlyOnePartAllowed); } } OpenXmlPart child = CreateOpenXmlPart(relationshipType); child.CreateInternal(OpenXmlPackage, this, contentType, null); // add it and get the id string relationshipId = AttachChild(child); ChildrenRelationshipParts.Add(relationshipId, child); return(child); } throw new ArgumentOutOfRangeException(nameof(relationshipType)); }
// destroy itself (aka. dispose) internal void Destroy() { OpenXmlPackage.Package.DeletePart(Uri); ChildrenRelationshipParts.Clear(); ReferenceRelationshipList.Clear(); _openXmlPackage = null; _packagePart = null; _uri = null; //this._ownerPart = null; if (InternalRootElement != null) { InternalRootElement.OpenXmlPart = null; InternalRootElement = null; } }
/// <summary> /// Init a new created part /// </summary> /// <typeparam name="T">The type of the part, must be derived from OpenXmlPart.</typeparam> /// <param name="newPart">The part to be initialized.</param> /// <param name="contentType">The content type of the part.</param> /// <param name="id">The relationship id.</param> internal override void InitPart <T>(T newPart, string contentType, string id) { ThrowIfObjectDisposed(); if (contentType == null) { throw new ArgumentNullException(nameof(contentType)); } if (contentType.Length == 0) { throw new ArgumentException(ExceptionMessages.StringArgumentEmptyException, nameof(contentType)); } newPart.CreateInternal(InternalOpenXmlPackage, ThisOpenXmlPart, contentType, null); var relationshipId = AttachChild(newPart, id); ChildrenRelationshipParts.Add(relationshipId, newPart); }