From dbe1a1938eeb5ab7a8fc59c56b12b8d318008cb3 Mon Sep 17 00:00:00 2001 From: Ryan Boggs Date: Thu, 30 Jul 2020 06:33:51 -0700 Subject: [PATCH] Version Bump to 0.3.2-alpha Bumping the version up to 0.3.2-alpha in the project file in preparation of the next (hopefully the last) alpha release. Clean up/refactor some of the code generation in OpenXmlPackageExtensions to get rid of VS.NET warnings. Should not impact code behavior. --- .../OpenXmlPackageExtensions.cs | 50 +++++++++---------- .../Serialize.OpenXml.CodeGen.csproj | 2 +- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/Serialize.OpenXml.CodeGen/OpenXmlPackageExtensions.cs b/src/Serialize.OpenXml.CodeGen/OpenXmlPackageExtensions.cs index 35f3274..738f210 100644 --- a/src/Serialize.OpenXml.CodeGen/OpenXmlPackageExtensions.cs +++ b/src/Serialize.OpenXml.CodeGen/OpenXmlPackageExtensions.cs @@ -21,7 +21,6 @@ DEALINGS IN THE SOFTWARE. */ using DocumentFormat.OpenXml.Packaging; -using DocumentFormat.OpenXml.Vml.Office; using Serialize.OpenXml.CodeGen.Extentions; using System; using System.CodeDom; @@ -87,8 +86,8 @@ public static CodeCompileUnit GenerateSourceCode(this OpenXmlPackage pkg, Namesp CodeTypeDeclaration mainClass; CodeTryCatchFinallyStatement tryAndCatch; CodeFieldReferenceExpression docTypeVarRef = null; - Type docTypeEnum = null; - string docTypeEnumVal = null; + Type docTypeEnum; + string docTypeEnumVal; KeyValuePair rootVarType; // Add all initial namespace names first @@ -96,24 +95,23 @@ public static CodeCompileUnit GenerateSourceCode(this OpenXmlPackage pkg, Namesp // The OpenXmlDocument derived parts all contain a property called "DocumentType" // but the property types differ depending on the derived part. Need to get both - // the enum name of selected value to use as a parameter for the Create statement - if (pkg is PresentationDocument) + // the enum name of selected value to use as a parameter for the Create statement. + switch (pkg) { - var docType = ((PresentationDocument)pkg).DocumentType; - docTypeEnumVal = docType.ToString(); - docTypeEnum = docType.GetType(); - } - else if (pkg is SpreadsheetDocument) - { - var docType = ((SpreadsheetDocument)pkg).DocumentType; - docTypeEnumVal = docType.ToString(); - docTypeEnum = docType.GetType(); - } - else if (pkg is WordprocessingDocument) - { - var docType = ((WordprocessingDocument)pkg).DocumentType; - docTypeEnumVal = docType.ToString(); - docTypeEnum = docType.GetType(); + case PresentationDocument p: + docTypeEnum = p.DocumentType.GetType(); + docTypeEnumVal = p.DocumentType.ToString(); + break; + case SpreadsheetDocument s: + docTypeEnum = s.DocumentType.GetType(); + docTypeEnumVal = s.DocumentType.ToString(); + break; + case WordprocessingDocument w: + docTypeEnum = w.DocumentType.GetType(); + docTypeEnumVal = w.DocumentType.ToString(); + break; + default: + throw new ArgumentException("object is not a recognized OpenXmlPackage type.", nameof(pkg)); } // Create the entry method @@ -201,14 +199,14 @@ public static CodeCompileUnit GenerateSourceCode(this OpenXmlPackage pkg, Namesp if (pkg.Parts != null) { var customNewPartTypes = new Type[] { typeof(PresentationPart), typeof(WorkbookPart), typeof(MainDocumentPart) }; - OpenXmlPartBluePrint bpTemp = null; - CodeMethodReferenceExpression referenceExpression = null; - CodeMethodInvokeExpression invokeExpression = null; - CodeMethodReferenceExpression methodReference = null; - Type currentPartType = null; + OpenXmlPartBluePrint bpTemp; + CodeMethodReferenceExpression referenceExpression; + CodeMethodInvokeExpression invokeExpression; + CodeMethodReferenceExpression methodReference; + Type currentPartType; string varName = null; string initMethodName = null; - string mainPartTypeName = null; + string mainPartTypeName; foreach (var pair in pkg.Parts) { diff --git a/src/Serialize.OpenXml.CodeGen/Serialize.OpenXml.CodeGen.csproj b/src/Serialize.OpenXml.CodeGen/Serialize.OpenXml.CodeGen.csproj index c75ad28..e59ac9d 100644 --- a/src/Serialize.OpenXml.CodeGen/Serialize.OpenXml.CodeGen.csproj +++ b/src/Serialize.OpenXml.CodeGen/Serialize.OpenXml.CodeGen.csproj @@ -5,7 +5,7 @@ netstandard2.0 - 0.3.1-alpha + 0.3.2-alpha Ryan Boggs MIT https://github.com/rmboggs/Serialize.OpenXml.CodeGen