Skip to content

Commit 8c7c199

Browse files
authored
Access schema resources in BinarySdbSchemaDatas (#347)
1 parent de35c61 commit 8c7c199

File tree

4 files changed

+52
-64
lines changed

4 files changed

+52
-64
lines changed

DocumentFormat.OpenXml/Validation/Schema/BinarySdbSchemaDatas.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Collections.Generic;
88
using System.Diagnostics;
99
using System.IO;
10+
using System.Reflection;
1011

1112
using SdbIndex = System.UInt16;
1213

@@ -23,12 +24,33 @@ public BinarySdbSchemaDatas(FileFormatVersions fileFormat)
2324
this.SdbDataHead = new SdbDataHead();
2425
this._fileFormat = fileFormat;
2526

26-
using (var schema = ValidationResources.GetSchemaStream(this._fileFormat))
27+
using (var schema = GetSchemaStream(fileFormat))
2728
{
2829
this.Load(schema);
2930
}
3031
}
3132

33+
private static Stream GetSchemaStream(FileFormatVersions fileFormat)
34+
{
35+
Stream GetEmbeddedResource(string name)
36+
{
37+
return typeof(ValidationResources).GetTypeInfo().Assembly.GetManifestResourceStream($"DocumentFormat.OpenXml.src.GeneratedCode.{name}.bin");
38+
}
39+
40+
switch (fileFormat)
41+
{
42+
case FileFormatVersions.Office2007:
43+
return GetEmbeddedResource("O12SchemaConstraintDatas");
44+
case FileFormatVersions.Office2010:
45+
return GetEmbeddedResource("O14SchemaConstraintDatas");
46+
case FileFormatVersions.Office2013:
47+
return GetEmbeddedResource("O15SchemaConstraintDatas");
48+
default:
49+
Debug.Assert(fileFormat.Any());
50+
return GetEmbeddedResource("O12SchemaConstraintDatas");
51+
}
52+
}
53+
3254
/// <summary>
3355
/// Load the schema constraint data from the stream.
3456
/// </summary>

DocumentFormat.OpenXml/Validation/ValidationResources.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DocumentFormat.OpenXml/Validation/ValidationResources.Objects.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

DocumentFormat.OpenXml/Validation/ValidationResources.resx

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!-- Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
32
<root>
4-
<!--
5-
Microsoft ResX Schema
6-
3+
<!--
4+
Microsoft ResX Schema
5+
76
Version 2.0
8-
9-
The primary goals of this format is to allow a simple XML format
10-
that is mostly human readable. The generation and parsing of the
11-
various data types are done through the TypeConverter classes
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
1211
associated with the data types.
13-
12+
1413
Example:
15-
14+
1615
... ado.net/XML headers & schema ...
1716
<resheader name="resmimetype">text/microsoft-resx</resheader>
1817
<resheader name="version">2.0</resheader>
@@ -27,36 +26,36 @@
2726
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
2827
<comment>This is a comment</comment>
2928
</data>
30-
31-
There are any number of "resheader" rows that contain simple
29+
30+
There are any number of "resheader" rows that contain simple
3231
name/value pairs.
33-
34-
Each data row contains a name, and value. The row also contains a
35-
type or mimetype. Type corresponds to a .NET class that support
36-
text/value conversion through the TypeConverter architecture.
37-
Classes that don't support this are serialized and stored with the
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
3837
mimetype set.
39-
40-
The mimetype is used for serialized objects, and tells the
41-
ResXResourceReader how to depersist the object. This is currently not
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
4241
extensible. For a given mimetype the value must be set accordingly:
43-
44-
Note - application/x-microsoft.net.object.binary.base64 is the format
45-
that the ResXResourceWriter will generate, however the reader can
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
4645
read any of the formats listed below.
47-
46+
4847
mimetype: application/x-microsoft.net.object.binary.base64
49-
value : The object must be serialized with
48+
value : The object must be serialized with
5049
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
5150
: and then encoded with base64 encoding.
52-
51+
5352
mimetype: application/x-microsoft.net.object.soap.base64
54-
value : The object must be serialized with
53+
value : The object must be serialized with
5554
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
5655
: and then encoded with base64 encoding.
5756
5857
mimetype: application/x-microsoft.net.object.bytearray.base64
59-
value : The object must be serialized into a byte array
58+
value : The object must be serialized into a byte array
6059
: using a System.ComponentModel.TypeConverter
6160
: and then encoded with base64 encoding.
6261
-->
@@ -337,4 +336,4 @@
337336
<data name="Pkg_DataPartReferenceIsNotAllowed" xml:space="preserve">
338337
<value>The package/part '{0}' cannot have a relationship that targets '{1}'.</value>
339338
</data>
340-
</root>
339+
</root>

0 commit comments

Comments
 (0)