Skip to content

Inherit parts to child parts #722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added `FileFormatVersions.2019` enum (#695)
- Added `ChartSpace` and chart elements for the new 2016 namespaces. This allows the connecting pieces for building a chart part with chart styles like "Sunburst" (#687).
- Added `OpenXmlElementFunctionalExtensions.With(...)` extension methods, which offer flexible means for constructing `OpenXmlElement` instances in the context of pure functional transformations (#679)
- Added minimum Office versions for enum types and values (#707).
- Added additional `CompatSettingNameValues` values: `UseWord2013TrackBottomHyphenation`, `AllowHyphenationAtTrackBottom`, and `AllowTextAfterFloatingTableBreak` (#706).
- Added minimum Office versions for enum types and values (#707)
- Added additional `CompatSettingNameValues` values: `UseWord2013TrackBottomHyphenation`, `AllowHyphenationAtTrackBottom`, and `AllowTextAfterFloatingTableBreak` (#706)
- Added gfxdata attribue to Arc, Curve, Line, PolyLine, Group, Image, Oval, Rect, and RoundRect shape complex types per MS-OI29500 2.1.1783-1799 (#709)
- Added `TryGetPartById` in `OpenXmlPartContainer`. This allows try to get the child part by the relationship ID (#714)
- Added `StrictRelationshipFound` property on `OpenXmlPackage` indicating whether this package contains Transitional relationships converted from Strict. (#716)
- Added `OpenXmlPartContainer.TryGetPartById` to enable child part retrieval without exception if it does not exist (#714)
- Added `OpenXmlPackage.StrictRelationshipFound` property that indicates whether this package contains Transitional relationships converted from Strict (#716)

### Fixed
- Custom derived parts did not inherit known parts from its parent, causing failure when adding parts (#722)

### Changes
- Marked the property setters in `OpenXmlAttribute` as obsolete as structs should not have mutable state (#698)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static PartConstraintCollection Create<T>(Func<Type, OpenXmlElementData>
{
var collection = new PartConstraintCollection();

foreach (var constraint in type.GetTypeInfo().GetCustomAttributes(inherit: false).OfType<T>())
foreach (var constraint in type.GetTypeInfo().GetCustomAttributes(inherit: true).OfType<T>())
{
collection.Add(new PartConstraintRule(dataFactory(constraint.ConstraintType).Info, constraint.MinOccursIsNonZero, constraint.MaxOccursGreatThanOne));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using DocumentFormat.OpenXml.Framework;
using System;
using System.IO;
using Xunit;

#pragma warning disable IDE0028 // Simplify collection initialization
Expand Down Expand Up @@ -78,6 +79,27 @@ public void ContainsRelationshipTest()
Assert.False(collection.ContainsRelationship("b"));
}

[Fact]
public void PartsAreInherited()
{
using (var m = new MemoryStream())
using (var doc = SpreadsheetDocument.Create(m, SpreadsheetDocumentType.Workbook, true))
{
var wb = doc.AddWorkbookPart();

// Adding new worksheet part using custom worksheetpart derived class
var ws = wb.AddNewPart<PsWorksheetPart>();

Assert.NotNull(ws.AddNewPart<SpreadsheetPrinterSettingsPart>());
}
}

#pragma warning disable CA1812
private sealed class PsWorksheetPart : WorksheetPart
{
}
#pragma warning restore CA1812

[RelationshipType(Relationship)]
private class ConstraintTest1
{
Expand Down