Skip to content

Commit

Permalink
Fix AddPart method on non existent variables.
Browse files Browse the repository at this point in the history
Use the appropriate variable name when creating AddPart methods for parts that have already been visited.
Finalizing 0.3.2-alpha release.
  • Loading branch information
rmboggs committed Jul 30, 2020
1 parent dbe1a19 commit f966551
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.3.2-alpha] - TBD
## [0.3.2-alpha] - 2020-07-30

### Changed

Expand All @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
for more details.
- When encountering OpenXmlUnknownElement objects, make sure to initialize them with the appropriate `ctor` method.
- Correct the initialization parameters for the generated `AddExternalRelationship` method.
- Issue where AddPart methods for OpenXmlPart paths that have already been visited are generated on variables
that do not exist.

## [0.3.1-alpha] - 2020-07-25

Expand Down
38 changes: 20 additions & 18 deletions src/Serialize.OpenXml.CodeGen/OpenXmlPartExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,39 +291,41 @@ internal static CodeStatementCollection BuildEntryMethodCodeStatements(
// Make sure that the namespace for the current part is captured
namespaces.Add(partType.Namespace);

// Assign the appropriate variable name
if (typeCounts.ContainsKey(partTypeFullName))
{
varName = String.Concat(varName, typeCounts[partTypeFullName]++);
}
else
{
typeCounts.Add(partTypeFullName, 1);
}

// Setup the blueprint
// If the URI of the current part has already been included into
// the blue prints collection, build the AddPart invocation
// code statement and exit current method iteration.
if (blueprints.TryGetValue(part.OpenXmlPart.Uri, out bpTemp))
{
// If the URI of the current part has already been included into
// the blue prints collection, build the AddPart invocation
// code statement and exit current method iteration.
// Surround this snippet with blank lines to make it
// stand out in the current section of code.
addBlankLine();
referenceExpression = new CodeMethodReferenceExpression(
new CodeVariableReferenceExpression(varName), "AddPart",
new CodeVariableReferenceExpression(rootVar.Key), "AddPart",
new CodeTypeReference(part.OpenXmlPart.GetType().Name));
invokeExpression = new CodeMethodInvokeExpression(referenceExpression,
new CodeVariableReferenceExpression(bpTemp.VariableName),
new CodePrimitiveExpression(part.RelationshipId));
result.Add(invokeExpression);
addBlankLine();
return result;
}

// Assign the appropriate variable name
if (typeCounts.ContainsKey(partTypeFullName))
{
varName = String.Concat(varName, typeCounts[partTypeFullName]++);
}
else
{
bpTemp = new OpenXmlPartBluePrint(part.OpenXmlPart, varName);
typeCounts.Add(partTypeFullName, 1);
}

// Need to evaluate the current OpenXmlPart type first to make sure the
// Setup the blueprint
bpTemp = new OpenXmlPartBluePrint(part.OpenXmlPart, varName);

// Need to evaluate the current OpenXmlPart type first to make sure the
// correct "Add" statement is used as not all Parts can be initialized
// using the "AddNewPart"method
// using the "AddNewPart" method

// Check for image part methods
if (customAddNewPartRequired)
Expand Down

0 comments on commit f966551

Please sign in to comment.